Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Jun 2014 04:18:56 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r267995 - user/marcel/mkimg
Message-ID:  <201406280418.s5S4IuZf009015@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Sat Jun 28 04:18:55 2014
New Revision: 267995
URL: http://svnweb.freebsd.org/changeset/base/267995

Log:
  Add option -y for unit testing. When unit_testing is in effect, fields
  that have different values for each run, such as UUIDs and timestamps,
  will have a synthesized value. This allows us to compare images against
  a known baseline without fails negatives.
  
  Add mkimg_uuid() that wraps uuidgen() and provides synthesized values
  for unit testing.

Modified:
  user/marcel/mkimg/mkimg.c
  user/marcel/mkimg/mkimg.h

Modified: user/marcel/mkimg/mkimg.c
==============================================================================
--- user/marcel/mkimg/mkimg.c	Sat Jun 28 04:10:46 2014	(r267994)
+++ user/marcel/mkimg/mkimg.c	Sat Jun 28 04:18:55 2014	(r267995)
@@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/queue.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/uuid.h>
 #include <errno.h>
 #include <err.h>
 #include <fcntl.h>
@@ -50,6 +51,7 @@ __FBSDID("$FreeBSD$");
 struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist);
 u_int nparts = 0;
 
+u_int unit_testing;
 u_int verbose;
 
 u_int ncyls = 0;
@@ -258,6 +260,22 @@ sparse_write(int fd, const void *ptr, si
 }
 #endif /* SPARSE_WRITE */
 
+void
+mkimg_uuid(struct uuid *uuid)
+{
+	static uint8_t gen[sizeof(struct uuid)];
+	u_int i;
+
+	if (!unit_testing) {
+		uuidgen(uuid, 1);
+		return;
+	}
+
+	for (i = 0; i < sizeof(gen); i++)
+		gen[i]++;
+	memcpy(uuid, gen, sizeof(uuid_t));
+}
+
 static void
 mkimg(void)
 {
@@ -337,7 +355,7 @@ main(int argc, char *argv[])
 
 	bcfd = -1;
 	outfd = 1;	/* Write to stdout by default */
-	while ((c = getopt(argc, argv, "b:f:o:p:s:vH:P:S:T:")) != -1) {
+	while ((c = getopt(argc, argv, "b:f:o:p:s:vyH:P:S:T:")) != -1) {
 		switch (c) {
 		case 'b':	/* BOOT CODE */
 			if (bcfd != -1)
@@ -373,6 +391,9 @@ main(int argc, char *argv[])
 			if (error)
 				errc(EX_DATAERR, error, "scheme");
 			break;
+		case 'y':
+			unit_testing++;
+			break;
 		case 'v':
 			verbose++;
 			break;

Modified: user/marcel/mkimg/mkimg.h
==============================================================================
--- user/marcel/mkimg/mkimg.h	Sat Jun 28 04:10:46 2014	(r267994)
+++ user/marcel/mkimg/mkimg.h	Sat Jun 28 04:18:55 2014	(r267995)
@@ -50,6 +50,7 @@ struct part {
 extern STAILQ_HEAD(partlisthead, part) partlist;
 extern u_int nparts;
 
+extern u_int unit_testing;
 extern u_int verbose;
 
 extern u_int ncyls;
@@ -71,4 +72,7 @@ round_block(lba_t n)
 ssize_t sparse_write(int, const void *, size_t);
 #endif
 
+struct uuid;
+void mkimg_uuid(struct uuid *);
+
 #endif /* _MKIMG_MKIMG_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406280418.s5S4IuZf009015>