* skipped. Useful if testing a command which might not work on
* all variations of libguestfs builds. A test that has prerequisite
* of 'Always' is run unconditionally.
+ *
+ * In addition, packagers can skip individual tests by setting the
+ * environment variables: eg:
+ * SKIP_TEST_<CMD>_<NUM>=1 SKIP_TEST_COMMAND_3=1 (skips test #3 of command)
+ * SKIP_TEST_<CMD>=1 SKIP_TEST_ZEROFREE=1 (skips all zerofree tests)
*)
type tests = (test_init * test_prereq * test) list
and test =
and seq = cmd list
and cmd = string list
-(* Canned test prerequisites. *)
-let env_is_true env =
- sprintf "const char *str = getenv (\"%s\");
- return str && strcmp (str, \"1\") == 0;" env
-
(* Note about long descriptions: When referring to another
* action, use the format C<guestfs_other> (ie. the full name of
* the C function). This will be replaced as appropriate in other
(the C<-b> option).");
("command", (RString "output", [StringList "arguments"]), 50, [ProtocolLimitWarning],
- [InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ [InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 1"]], "Result1");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 2"]], "Result2\n");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 3"]], "\nResult3");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 4"]], "\nResult4\n");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 5"]], "\nResult5\n\n");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 6"]], "\n\nResult6\n\n");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 7"]], "");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 8"]], "\n");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 9"]], "\n\n");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 10"]], "Result10-1\nResult10-2\n");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput (
+ InitBasicFS, Always, TestOutput (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command 11"]], "Result11-1\nResult11-2");
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestLastFail (
+ InitBasicFS, Always, TestLastFail (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command"; "/test-command"]])],
locations.");
("command_lines", (RStringList "lines", [StringList "arguments"]), 51, [ProtocolLimitWarning],
- [InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ [InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 1"]], ["Result1"]);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 2"]], ["Result2"]);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 3"]], ["";"Result3"]);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 4"]], ["";"Result4"]);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 5"]], ["";"Result5";""]);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 6"]], ["";"";"Result6";""]);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 7"]], []);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 8"]], [""]);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 9"]], ["";""]);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 10"]], ["Result10-1";"Result10-2"]);
- InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList (
+ InitBasicFS, Always, TestOutputList (
[["upload"; "test-command"; "/test-command"];
["chmod"; "493"; "/test-command"];
["command_lines"; "/test-command 11"]], ["Result11-1";"Result11-2"])],
("lvremove", (RErr, [String "device"]), 77, [],
[InitEmpty, Always, TestOutputList (
- [["pvcreate"; "/dev/sda"];
- ["vgcreate"; "VG"; "/dev/sda"];
+ [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","];
+ ["pvcreate"; "/dev/sda1"];
+ ["vgcreate"; "VG"; "/dev/sda1"];
["lvcreate"; "LV1"; "VG"; "50"];
["lvcreate"; "LV2"; "VG"; "50"];
["lvremove"; "/dev/VG/LV1"];
["lvs"]], ["/dev/VG/LV2"]);
InitEmpty, Always, TestOutputList (
- [["pvcreate"; "/dev/sda"];
- ["vgcreate"; "VG"; "/dev/sda"];
+ [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","];
+ ["pvcreate"; "/dev/sda1"];
+ ["vgcreate"; "VG"; "/dev/sda1"];
["lvcreate"; "LV1"; "VG"; "50"];
["lvcreate"; "LV2"; "VG"; "50"];
["lvremove"; "/dev/VG"];
["lvs"]], []);
InitEmpty, Always, TestOutputList (
- [["pvcreate"; "/dev/sda"];
- ["vgcreate"; "VG"; "/dev/sda"];
+ [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","];
+ ["pvcreate"; "/dev/sda1"];
+ ["vgcreate"; "VG"; "/dev/sda1"];
["lvcreate"; "LV1"; "VG"; "50"];
["lvcreate"; "LV2"; "VG"; "50"];
["lvremove"; "/dev/VG"];
("vgremove", (RErr, [String "vgname"]), 78, [],
[InitEmpty, Always, TestOutputList (
- [["pvcreate"; "/dev/sda"];
- ["vgcreate"; "VG"; "/dev/sda"];
+ [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","];
+ ["pvcreate"; "/dev/sda1"];
+ ["vgcreate"; "VG"; "/dev/sda1"];
["lvcreate"; "LV1"; "VG"; "50"];
["lvcreate"; "LV2"; "VG"; "50"];
["vgremove"; "VG"];
["lvs"]], []);
InitEmpty, Always, TestOutputList (
- [["pvcreate"; "/dev/sda"];
- ["vgcreate"; "VG"; "/dev/sda"];
+ [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","];
+ ["pvcreate"; "/dev/sda1"];
+ ["vgcreate"; "VG"; "/dev/sda1"];
["lvcreate"; "LV1"; "VG"; "50"];
["lvcreate"; "LV2"; "VG"; "50"];
["vgremove"; "VG"];
("pvremove", (RErr, [String "device"]), 79, [],
[InitEmpty, Always, TestOutputList (
- [["pvcreate"; "/dev/sda"];
- ["vgcreate"; "VG"; "/dev/sda"];
+ [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","];
+ ["pvcreate"; "/dev/sda1"];
+ ["vgcreate"; "VG"; "/dev/sda1"];
["lvcreate"; "LV1"; "VG"; "50"];
["lvcreate"; "LV2"; "VG"; "50"];
["vgremove"; "VG"];
- ["pvremove"; "/dev/sda"];
+ ["pvremove"; "/dev/sda1"];
["lvs"]], []);
InitEmpty, Always, TestOutputList (
- [["pvcreate"; "/dev/sda"];
- ["vgcreate"; "VG"; "/dev/sda"];
+ [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","];
+ ["pvcreate"; "/dev/sda1"];
+ ["vgcreate"; "VG"; "/dev/sda1"];
["lvcreate"; "LV1"; "VG"; "50"];
["lvcreate"; "LV2"; "VG"; "50"];
["vgremove"; "VG"];
- ["pvremove"; "/dev/sda"];
+ ["pvremove"; "/dev/sda1"];
["vgs"]], []);
InitEmpty, Always, TestOutputList (
- [["pvcreate"; "/dev/sda"];
- ["vgcreate"; "VG"; "/dev/sda"];
+ [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","];
+ ["pvcreate"; "/dev/sda1"];
+ ["vgcreate"; "VG"; "/dev/sda1"];
["lvcreate"; "LV1"; "VG"; "50"];
["lvcreate"; "LV2"; "VG"; "50"];
["vgremove"; "VG"];
- ["pvremove"; "/dev/sda"];
+ ["pvremove"; "/dev/sda1"];
["pvs"]], [])],
"remove an LVM physical volume",
"\
["write_file"; "/new"; "test content"; "0"];
["umount"; "/"];
["lvresize"; "/dev/VG/LV"; "20"];
+ ["e2fsck_f"; "/dev/VG/LV"];
["resize2fs"; "/dev/VG/LV"];
["mount"; "/dev/VG/LV"; "/"];
["cat"; "/new"]], "test content")],
"resize an ext2/ext3 filesystem",
"\
This resizes an ext2 or ext3 filesystem to match the size of
-the underlying device.");
+the underlying device.
+
+I<Note:> It is sometimes required that you run C<guestfs_e2fsck_f>
+on the C<device> before calling this command. For unknown reasons
+C<resize2fs> sometimes gives an error about this and sometimes not.
+In any case, it is always safe to call C<guestfs_e2fsck_f> before
+calling this function.");
("find", (RStringList "names", [String "directory"]), 107, [],
[InitBasicFS, Always, TestOutputList (
The returned list is sorted.");
+ ("e2fsck_f", (RErr, [String "device"]), 108, [],
+ [], (* lvresize tests this *)
+ "check an ext2/ext3 filesystem",
+ "\
+This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
+filesystem checker on C<device>, noninteractively (C<-p>),
+even if the filesystem appears to be clean (C<-f>).
+
+This command is only needed because of C<guestfs_resize2fs>
+(q.v.). Normally you should use C<guestfs_fsck>.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
and generate_one_test name i (init, prereq, test) =
let test_name = sprintf "test_%s_%d" name i in
+ pr "\
+static int %s_skip (void)
+{
+ const char *str;
+
+ str = getenv (\"SKIP_%s\");
+ if (str && strcmp (str, \"1\") == 0) return 1;
+ str = getenv (\"SKIP_TEST_%s\");
+ if (str && strcmp (str, \"1\") == 0) return 1;
+ return 0;
+}
+
+" test_name (String.uppercase test_name) (String.uppercase name);
+
(match prereq with
| Disabled | Always -> ()
| If code | Unless code ->
pr "\n";
);
- pr "static int %s (void)\n" test_name;
- pr "{\n";
+ pr "\
+static int %s (void)
+{
+ if (%s_skip ()) {
+ printf (\"%%s skipped (reason: SKIP_TEST_* variable set)\\n\", \"%s\");
+ return 0;
+ }
+
+" test_name test_name test_name;
(match prereq with
| Disabled ->
pr " printf (\"%%s skipped (reason: test disabled in generator)\\n\", \"%s\");\n" test_name
| If _ ->
- pr " if (%s_prereq ()) {\n" test_name;
+ pr " if (! %s_prereq ()) {\n" test_name;
+ pr " printf (\"%%s skipped (reason: test prerequisite)\\n\", \"%s\");\n" test_name;
+ pr " return 0;\n";
+ pr " }\n";
+ pr "\n";
generate_one_test_body name i test_name init test;
- pr " } else\n";
- pr " printf (\"%%s skipped (reason: test prerequisite)\\n\", \"%s\");\n" test_name
| Unless _ ->
- pr " if (! %s_prereq ()) {\n" test_name;
+ pr " if (%s_prereq ()) {\n" test_name;
+ pr " printf (\"%%s skipped (reason: test prerequisite)\\n\", \"%s\");\n" test_name;
+ pr " return 0;\n";
+ pr " }\n";
+ pr "\n";
generate_one_test_body name i test_name init test;
- pr " } else\n";
- pr " printf (\"%%s skipped (reason: test prerequisite)\\n\", \"%s\");\n" test_name
| Always ->
generate_one_test_body name i test_name init test
);