From: Richard Jones Date: Sat, 11 Sep 2010 11:19:25 +0000 (+0100) Subject: generator: Calculate MD5 of test.iso at runtime. X-Git-Tag: 1.5.12~4 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=b42262c3db6013c363e2532cf7a466ccaf4d49f0;p=libguestfs.git generator: Calculate MD5 of test.iso at runtime. Because this used to be compiled into the C test, it changed every time the ISO was rebuilt (which because of Makefile deps was every run). Now it is calculated at runtime so the C test file doesn't keep changing. --- diff --git a/generator/Makefile.am b/generator/Makefile.am index 7ef5d9d..919fb50 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -56,7 +56,7 @@ OCAMLCLIBS = xml-light.cma unix.cma str.cma noinst_PROGRAM = generator -generator: $(OBJECTS) ../images/test.iso +generator: $(OBJECTS) $(OCAMLC) -o generator $(OCAMLCFLAGS) $(OCAMLCLIBS) $(OBJECTS) .ml.cmo: @@ -87,9 +87,6 @@ stamp-generator: generator mkdir -p $(top_srcdir)/csharp cd $(top_srcdir) && generator/generator -../images/test.iso: - make -C ../images test.iso - CLEANFILES = $(noinst_DATA) $(noinst_PROGRAM) *.cmi *.cmo *~ SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index bde9e6c..014687d 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -4632,9 +4632,9 @@ You will get undefined results for other partition table types (see C)."); ("checksum_device", (RString "checksum", [String "csumtype"; Device "device"]), 237, [], - [InitISOFS, Always, TestOutput ( + [InitISOFS, Always, TestOutputFileMD5 ( [["checksum_device"; "md5"; "/dev/sdd"]], - (Digest.to_hex (Digest.file "images/test.iso")))], + "../images/test.iso")], "compute MD5, SHAx or CRC checksum of the contents of a device", "\ This call computes the MD5, SHAx or CRC checksum of the diff --git a/generator/generator_capitests.ml b/generator/generator_capitests.ml index f6c71be..044c70d 100644 --- a/generator/generator_capitests.ml +++ b/generator/generator_capitests.ml @@ -91,6 +91,28 @@ incr (guestfs_h *g, void *iv) (*i)++; } +/* Get md5sum of the named file. */ +static void +md5sum (const char *filename, char *result) +{ + char cmd[256]; + snprintf (cmd, sizeof cmd, \"md5sum %%s\", filename); + FILE *pp = popen (cmd, \"r\"); + if (pp == NULL) { + perror (cmd); + exit (EXIT_FAILURE); + } + if (fread (result, 1, 32, pp) != 32) { + perror (\"md5sum: fread\"); + exit (EXIT_FAILURE); + } + if (pclose (pp) == -1) { + perror (\"pclose\"); + exit (EXIT_FAILURE); + } + result[32] = '\\0'; +} + "; (* Generate a list of commands which are not tested anywhere. *) @@ -650,6 +672,19 @@ and generate_one_test_body name i test_name init test = in List.iter (generate_test_command_call test_name) seq; generate_test_command_call ~test test_name last + | TestOutputFileMD5 (seq, filename) -> + pr " /* TestOutputFileMD5 for %s (%d) */\n" name i; + pr " char expected[33];\n"; + pr " md5sum (\"%s\", expected);\n" filename; + let seq, last = get_seq_last seq in + let test () = + pr " if (STRNEQ (r, expected)) {\n"; + pr " fprintf (stderr, \"%s: expected \\\"%%s\\\" but got \\\"%%s\\\"\\n\", expected, r);\n" test_name; + pr " return -1;\n"; + pr " }\n" + in + List.iter (generate_test_command_call test_name) seq; + generate_test_command_call ~test test_name last | TestLastFail seq -> pr " /* TestLastFail for %s (%d) */\n" name i; let seq, last = get_seq_last seq in diff --git a/generator/generator_types.ml b/generator/generator_types.ml index 647d66f..49d3792 100644 --- a/generator/generator_types.ml +++ b/generator/generator_types.ml @@ -260,9 +260,15 @@ and test = *) | TestOutputStruct of seq * test_field_compare list - (* Run the command sequence and expect the final command (only) - * to fail. + (* Run the command sequence and expect the output of the final + * command to be a string which is the hex MD5 of the content of + * the named file. *) + | TestOutputFileMD5 of seq * string + + (* Run the command sequence and expect the final command (only) + * to fail. + *) | TestLastFail of seq and test_field_compare = diff --git a/generator/generator_utils.ml b/generator/generator_utils.ml index e3a74e0..329e6ce 100644 --- a/generator/generator_utils.ml +++ b/generator/generator_utils.ml @@ -239,6 +239,7 @@ let seq_of_test = function | TestOutputTrue s | TestOutputFalse s | TestOutputLength (s, _) | TestOutputBuffer (s, _) | TestOutputStruct (s, _) + | TestOutputFileMD5 (s, _) | TestLastFail s -> s let c_quote str =