noinst_PROGRAM = generator
-generator: $(OBJECTS) ../images/test.iso
+generator: $(OBJECTS)
$(OCAMLC) -o generator $(OCAMLCFLAGS) $(OCAMLCLIBS) $(OBJECTS)
.ml.cmo:
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
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
(*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. *)
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
*)
| 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 =
| TestOutputTrue s | TestOutputFalse s
| TestOutputLength (s, _) | TestOutputBuffer (s, _)
| TestOutputStruct (s, _)
+ | TestOutputFileMD5 (s, _)
| TestLastFail s -> s
let c_quote str =