You can supply zero or as many tests as you want per API call.
-Note that the test environment has 3 block devices, of size 500MB,
-50MB and 10MB (respectively /dev/sda, /dev/sdb, /dev/sdc), and
-a fourth ISO block device with some known files on it (/dev/sdd).
+The test environment has 4 block devices:
+ /dev/sda 500MB General block device for testing.
+ /dev/sdb 50MB /dev/sdb1 is an ext2 filesystem used for testing
+ filesystem write operations.
+ /dev/sdc 10MB Used in a few tests where 2 block devices are needed.
+ /dev/sdd - ISO with fixed content (see images/test.iso).
+
+To be able to run the tests in a reasonable amount of time, the
+virtual machine and block devices are reused between tests. So don't
+try testing kill_subprocess :-x Between each test we blockdev-setrw,
+umount-all, lvm-remove-all.
+
+Each test starts with an initial scenario, selected using one of the
+'Init*' expressions, described in generator/generator_types.ml. These
+initialize the disks in a particular way as described. You should not
+assume anything about the previous contents of other disks that are
+not initialized.
+
+You can add a prerequisite clause to any individual test. This is a
+run-time check, which, if it fails, causes the test to be 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.
-Note for partitioning purposes, the 500MB device has 1015 cylinders.
-Number of cylinders was 63 for IDE emulated disks with precisely
-the same size. How exactly this is calculated is a mystery.
-
-The ISO block device (/dev/sdd) comes from images/test.iso.
-
-To be able to run the tests in a reasonable amount of time,
-the virtual machine and block devices are reused between tests.
-So don't try testing kill_subprocess :-x
+In addition, packagers can skip individual tests by setting the
+environment variables: eg:
-Between each test we blockdev-setrw, umount-all, lvm-remove-all.
+ 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)
-Don't assume anything about the previous contents of the block
-devices. Use 'Init*' to create some initial scenarios.
+and packagers can run only certain tests by setting eg:
-You can add a prerequisite clause to any individual test. This
-is a run-time check, which, if it fails, causes the test to be
-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.
+ TEST_ONLY="vfs_type zerofree"
-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)
+See capitests/tests.c for more details of how these environment
+variables work.
Debugging
----------------------------------------------------------------------
("list_partitions", (RStringList "partitions", [], []), 8, [],
[InitBasicFS, Always, TestOutputListOfDevices (
- [["list_partitions"]], ["/dev/sda1"]);
+ [["list_partitions"]], ["/dev/sda1"; "/dev/sdb1"]);
InitEmpty, Always, TestOutputListOfDevices (
[["part_init"; "/dev/sda"; "mbr"];
["part_add"; "/dev/sda"; "p"; "64"; "204799"];
["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
["part_add"; "/dev/sda"; "p"; "409600"; "-64"];
- ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])],
+ ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"; "/dev/sdb1"])],
"list the partitions",
"\
List all the partitions detected on all block devices.
See also C<guestfs_download>, C<guestfs_pread>.");
("pwrite_device", (RInt "nbytes", [Device "device"; BufferIn "content"; Int64 "offset"], []), 275, [ProtocolLimitWarning],
- [InitPartition, Always, TestOutputList (
+ [InitPartition, Always, TestOutputListOfDevices (
[["pwrite_device"; "/dev/sda"; "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"; "446"];
["blockdev_rereadpt"; "/dev/sda"];
- ["list_partitions"]], [])],
+ ["list_partitions"]], ["/dev/sdb1"])],
"write to part of a device",
"\
This command writes to part of a device. It writes the data
/* Cancel previous alarm. */
alarm (0);
+ /* Create ext2 filesystem on /dev/sdb1 partition. */
+ if (guestfs_part_disk (g, \"/dev/sdb\", \"mbr\") == -1) {
+ printf (\"guestfs_part_disk FAILED\\n\");
+ exit (EXIT_FAILURE);
+ }
+ if (guestfs_mkfs (g, \"ext2\", \"/dev/sdb1\") == -1) {
+ printf (\"guestfs_mkfs (/dev/sdb1) FAILED\\n\");
+ exit (EXIT_FAILURE);
+ }
+
nr_tests = %d;
" (500 * 1024 * 1024) (50 * 1024 * 1024) (10 * 1024 * 1024) nr_tests;
["umount_all"];
["lvm_remove_all"];
["mount_ro"; "/dev/sdd"; "/"]]
+ | InitScratchFS ->
+ pr " /* InitScratchFS for %s */\n" test_name;
+ List.iter (generate_test_command_call test_name)
+ [["blockdev_setrw"; "/dev/sda"];
+ ["umount_all"];
+ ["lvm_remove_all"];
+ ["mount_options"; ""; "/dev/sdb1"; "/"]]
);
let get_seq_last = function
| InitEmpty
(* /dev/sda contains a single partition /dev/sda1, with random
- * content. /dev/sdb and /dev/sdc may have random content.
- * No LVM.
+ * content. No LVM.
*)
| InitPartition
(* /dev/sda contains a single partition /dev/sda1, which is formatted
* as ext2, empty [except for lost+found] and mounted on /.
- * /dev/sdb and /dev/sdc may have random content.
* No LVM.
+ *
+ * Note: for testing filesystem operations, it is quicker to use
+ * InitScratchFS
*)
| InitBasicFS
* /dev/sda1 (is a PV):
* /dev/VG/LV (size 8MB):
* formatted as ext2, empty [except for lost+found], mounted on /
- * /dev/sdb and /dev/sdc may have random content.
+ *
+ * Note: only use this if you really need a freshly created filesystem
+ * on LVM. Normally you should use InitScratchFS instead.
*)
| InitBasicFSonLVM
*)
| InitISOFS
+ (* /dev/sdb1 (write scratch disk) is mounted on /. The filesystem
+ * will be empty.
+ *
+ * Note that this filesystem is not recreated between tests, and
+ * could contain random files and directories from previous tests.
+ * Therefore it is recommended that you create uniquely named files
+ * and directories for your tests.
+ *)
+ | InitScratchFS
+
(* Sequence of commands for testing. *)
and seq = cmd list
and cmd = string list