diff options
author | Richard Jones <rjones@redhat.com> | 2010-09-11 12:19:25 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-09-11 12:44:55 +0100 |
commit | b42262c3db6013c363e2532cf7a466ccaf4d49f0 (patch) | |
tree | 63ab41928219239474778dbd6e887c515650e81f /generator | |
parent | 451a28349b11fe08cb3f7ca84e58b6e69646707b (diff) | |
download | libguestfs-b42262c3db6013c363e2532cf7a466ccaf4d49f0.tar.gz libguestfs-b42262c3db6013c363e2532cf7a466ccaf4d49f0.tar.xz libguestfs-b42262c3db6013c363e2532cf7a466ccaf4d49f0.zip |
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.
Diffstat (limited to 'generator')
-rw-r--r-- | generator/Makefile.am | 5 | ||||
-rw-r--r-- | generator/generator_actions.ml | 4 | ||||
-rw-r--r-- | generator/generator_capitests.ml | 35 | ||||
-rw-r--r-- | generator/generator_types.ml | 10 | ||||
-rw-r--r-- | generator/generator_utils.ml | 1 |
5 files changed, 47 insertions, 8 deletions
diff --git a/generator/Makefile.am b/generator/Makefile.am index 7ef5d9db..919fb502 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 bde9e6c7..014687d1 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<guestfs_part_get_parttype>)."); ("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 f6c71be7..044c70d4 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 647d66f3..49d37922 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 e3a74e08..329e6ceb 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 = |