Rename the existing tests according to the naming/numbering described in guestfs-hacking(1), and improve the current ones: - guestfs_php_001.phpt: rename to guestfs_020_create.phpt - guestfs_php_003.phpt: rename to guestfs_070_optargs.phpt - guestfs_php_bindtests.phpt: rename to guestfs_090_bindtests.phpt - guestfs_091_version.phpt: new, checks taken from the former guestfs_php_002.phpt - guestfs_100_launch.phpt: new, modelled after the equivalent in e.g. OCaml/Perl/Python - guestfs_php_002.phpt: remove, as what it did is now covered by 091_version and 100_launch --- .gitignore | 14 ++--- generator/main.ml | 2 +- php/Makefile.am | 2 +- php/extension/tests/guestfs_020_create.phpt | 13 +++++ php/extension/tests/guestfs_070_optargs.phpt | 29 ++++++++++ php/extension/tests/guestfs_091_version.phpt | 20 +++++++ php/extension/tests/guestfs_100_launch.phpt | 82 ++++++++++++++++++++++++++++ php/extension/tests/guestfs_php_001.phpt | 13 ----- php/extension/tests/guestfs_php_002.phpt | 36 ------------ php/extension/tests/guestfs_php_003.phpt | 29 ---------- php/run-php-tests.sh | 2 +- 11 files changed, 154 insertions(+), 88 deletions(-) create mode 100644 php/extension/tests/guestfs_020_create.phpt create mode 100644 php/extension/tests/guestfs_070_optargs.phpt create mode 100644 php/extension/tests/guestfs_091_version.phpt create mode 100644 php/extension/tests/guestfs_100_launch.phpt delete mode 100644 php/extension/tests/guestfs_php_001.phpt delete mode 100644 php/extension/tests/guestfs_php_002.phpt delete mode 100644 php/extension/tests/guestfs_php_003.phpt diff --git a/.gitignore b/.gitignore index e34edb5..db354bc 100644 --- a/.gitignore +++ b/.gitignore @@ -367,12 +367,6 @@ Makefile.in /php/extension/configure.in /php/extension/env /php/extension/guestfs_php.c -/php/extension/guestfs_php_*.diff -/php/extension/guestfs_php_*.exp -/php/extension/guestfs_php_*.log -/php/extension/guestfs_php_*.out -/php/extension/guestfs_php_*.php -/php/extension/guestfs_php_*.sh /php/extension/install-sh /php/extension/libtool /php/extension/ltmain.sh @@ -385,7 +379,13 @@ Makefile.in /php/extension/php-for-tests.sh /php/extension/php_guestfs_php.h /php/extension/run-tests.php -/php/extension/tests/guestfs_php_bindtests.phpt +/php/extension/tests/guestfs_*.diff +/php/extension/tests/guestfs_*.exp +/php/extension/tests/guestfs_*.log +/php/extension/tests/guestfs_*.out +/php/extension/tests/guestfs_*.php +/php/extension/tests/guestfs_*.sh +/php/extension/tests/guestfs_090_bindtests.phpt /php/extension/tmp-php.ini /pick-guests.pl /po-docs/*/*.1 diff --git a/generator/main.ml b/generator/main.ml index b209511..ca882b1 100644 --- a/generator/main.ml +++ b/generator/main.ml @@ -158,7 +158,7 @@ Run it from the top source directory using the command output_to "csharp/Libguestfs.cs" generate_csharp; output_to "php/extension/php_guestfs_php.h" generate_php_h; output_to "php/extension/guestfs_php.c" generate_php_c; - output_to "php/extension/tests/guestfs_php_bindtests.phpt" generate_php_bindtests; + output_to "php/extension/tests/guestfs_090_bindtests.phpt" generate_php_bindtests; output_to "erlang/guestfs.erl" generate_erlang_erl; output_to "erlang/erl-guestfs.c" generate_erlang_c; output_to ~perm:0o555 "erlang/bindtests.erl" generate_erlang_bindtests; diff --git a/php/Makefile.am b/php/Makefile.am index 14b4219..836f4ba 100644 --- a/php/Makefile.am +++ b/php/Makefile.am @@ -24,7 +24,7 @@ generator_built = \ EXTRA_DIST = \ $(generator_built) \ run-php-tests.sh \ - extension/tests/guestfs_php_*.phpt \ + extension/tests/guestfs_*.phpt \ extension/config.m4 \ README-PHP \ guestfs_php.ini diff --git a/php/extension/tests/guestfs_020_create.phpt b/php/extension/tests/guestfs_020_create.phpt new file mode 100644 index 0000000..013ebb5 --- /dev/null +++ b/php/extension/tests/guestfs_020_create.phpt @@ -0,0 +1,13 @@ +--TEST-- +Load the module and create a handle. +--FILE-- +<?php +$g = guestfs_create (); +if ($g == false) { + echo ("Failed to create guestfs_php handle.\n"); + exit; +} +echo ("Created guestfs_php handle.\n"); +?> +--EXPECT-- +Created guestfs_php handle. diff --git a/php/extension/tests/guestfs_070_optargs.phpt b/php/extension/tests/guestfs_070_optargs.phpt new file mode 100644 index 0000000..e268e98 --- /dev/null +++ b/php/extension/tests/guestfs_070_optargs.phpt @@ -0,0 +1,29 @@ +--TEST-- +Check function with optional arguments. +--FILE-- +<?php +$g = guestfs_create (); +if ($g == false) { + echo ("Failed to create guestfs_php handle.\n"); + exit; +} +if (guestfs_add_drive ($g, "/dev/null") == false) { + echo ("Failed add_drive, no optional arguments: " . guestfs_last_error ($g) . "\n"); + exit; +} +if (guestfs_add_drive ($g, "/dev/null", 0) == false) { + echo ("Failed add_drive, one optional argument: " . guestfs_last_error ($g) . "\n"); + exit; +} +if (guestfs_add_drive ($g, "/dev/null", 1) == false) { + echo ("Failed add_drive, one optional argument: " . guestfs_last_error ($g) . "\n"); + exit; +} +if (guestfs_add_drive ($g, "/dev/null", 1, "raw") == false) { + echo ("Failed add_drive, two optional arguments: " . guestfs_last_error ($g) . "\n"); + exit; +} +echo ("Completed tests OK.\n"); +?> +--EXPECT-- +Completed tests OK. diff --git a/php/extension/tests/guestfs_091_version.phpt b/php/extension/tests/guestfs_091_version.phpt new file mode 100644 index 0000000..365094c --- /dev/null +++ b/php/extension/tests/guestfs_091_version.phpt @@ -0,0 +1,20 @@ +--TEST-- +Check the result of guestfs_version(). +--FILE-- +<?php +$g = guestfs_create (); + +$version = guestfs_version ($g); +echo (gettype ($version["major"]) . "\n"); +echo (gettype ($version["minor"]) . "\n"); +echo (gettype ($version["release"]) . "\n"); +echo (gettype ($version["extra"]) . "\n"); + +echo ("OK\n"); +?> +--EXPECT-- +integer +integer +integer +string +OK diff --git a/php/extension/tests/guestfs_100_launch.phpt b/php/extension/tests/guestfs_100_launch.phpt new file mode 100644 index 0000000..cd4661a --- /dev/null +++ b/php/extension/tests/guestfs_100_launch.phpt @@ -0,0 +1,82 @@ +--TEST-- +Launch, create partitions and LVs and filesystems. +--FILE-- +<?php +$g = guestfs_create (); +guestfs_add_drive_scratch ($g, 500 * 1024 * 1024); +guestfs_launch ($g); + +guestfs_pvcreate ($g, "/dev/sda"); +guestfs_vgcreate ($g, "VG", array ("/dev/sda")); +guestfs_lvcreate ($g, "LV1", "VG", 200); +guestfs_lvcreate ($g, "LV2", "VG", 200); + +$lvs = guestfs_lvs ($g); +var_dump ($lvs); + +guestfs_mkfs ($g, "ext2", "/dev/VG/LV1"); +guestfs_mount ($g, "/dev/VG/LV1", "/"); +guestfs_mkdir ($g, "/p"); +guestfs_touch ($g, "/q"); + +function dir_cmp ($a, $b) +{ + return strcmp ($a["name"], $b["name"]); +} +function dir_extract ($n) +{ + return array ("name" => $n["name"], "ftyp" => $n["ftyp"]); +} +$dirs = guestfs_readdir ($g, "/"); +usort ($dirs, "dir_cmp"); +$dirs = array_map ("dir_extract", $dirs); +var_dump ($dirs); + +guestfs_shutdown ($g); +echo ("OK\n"); +?> +--EXPECT-- +array(2) { + [0]=> + string(11) "/dev/VG/LV1" + [1]=> + string(11) "/dev/VG/LV2" +} +array(5) { + [0]=> + array(2) { + ["name"]=> + string(1) "." + ["ftyp"]=> + string(1) "d" + } + [1]=> + array(2) { + ["name"]=> + string(2) ".." + ["ftyp"]=> + string(1) "d" + } + [2]=> + array(2) { + ["name"]=> + string(10) "lost+found" + ["ftyp"]=> + string(1) "d" + } + [3]=> + array(2) { + ["name"]=> + string(1) "p" + ["ftyp"]=> + string(1) "d" + } + [4]=> + array(2) { + ["name"]=> + string(1) "q" + ["ftyp"]=> + string(1) "r" + } +} +OK diff --git a/php/extension/tests/guestfs_php_001.phpt b/php/extension/tests/guestfs_php_001.phpt deleted file mode 100644 index 013ebb5..0000000 --- a/php/extension/tests/guestfs_php_001.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Load the module and create a handle. ---FILE-- -<?php -$g = guestfs_create (); -if ($g == false) { - echo ("Failed to create guestfs_php handle.\n"); - exit; -} -echo ("Created guestfs_php handle.\n"); -?> ---EXPECT-- -Created guestfs_php handle. diff --git a/php/extension/tests/guestfs_php_002.phpt b/php/extension/tests/guestfs_php_002.phpt deleted file mode 100644 index 91b2067..0000000 --- a/php/extension/tests/guestfs_php_002.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -Launch the appliance and run basic tests. ---FILE-- -<?php -$g = guestfs_create (); -if ($g == false) { - echo ("Failed to create guestfs_php handle.\n"); - exit; -} - -if (! guestfs_add_drive_scratch ($g, 100 * 1024 * 1024) || - ! guestfs_launch ($g) || - ! guestfs_part_disk ($g, "/dev/sda", "mbr") || - ! guestfs_pvcreate ($g, "/dev/sda1") || - ! guestfs_vgcreate ($g, "VG", array ("/dev/sda1")) || - ! guestfs_lvcreate ($g, "LV", "VG", 64) || - ! guestfs_mkfs ($g, "ext2", "/dev/VG/LV")) { - die ("Error: ".guestfs_last_error ($g)."\n"); -} - -$version = guestfs_version ($g); -if ($version == false) { - echo ("Error: ".guestfs_last_error ($g)."\n"); - exit; -} -if (!is_int ($version["major"]) || - !is_int ($version["minor"]) || - !is_int ($version["release"]) || - !is_string ($version["extra"])) { - echo ("Error: incorrect return type from guestfs_version\n"); -} - -echo ("OK\n"); -?> ---EXPECT-- -OK diff --git a/php/extension/tests/guestfs_php_003.phpt b/php/extension/tests/guestfs_php_003.phpt deleted file mode 100644 index e268e98..0000000 --- a/php/extension/tests/guestfs_php_003.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -Check function with optional arguments. ---FILE-- -<?php -$g = guestfs_create (); -if ($g == false) { - echo ("Failed to create guestfs_php handle.\n"); - exit; -} -if (guestfs_add_drive ($g, "/dev/null") == false) { - echo ("Failed add_drive, no optional arguments: " . guestfs_last_error ($g) . "\n"); - exit; -} -if (guestfs_add_drive ($g, "/dev/null", 0) == false) { - echo ("Failed add_drive, one optional argument: " . guestfs_last_error ($g) . "\n"); - exit; -} -if (guestfs_add_drive ($g, "/dev/null", 1) == false) { - echo ("Failed add_drive, one optional argument: " . guestfs_last_error ($g) . "\n"); - exit; -} -if (guestfs_add_drive ($g, "/dev/null", 1, "raw") == false) { - echo ("Failed add_drive, two optional arguments: " . guestfs_last_error ($g) . "\n"); - exit; -} -echo ("Completed tests OK.\n"); -?> ---EXPECT-- -Completed tests OK. diff --git a/php/run-php-tests.sh b/php/run-php-tests.sh index f2f80ea..4132927 100755 --- a/php/run-php-tests.sh +++ b/php/run-php-tests.sh @@ -41,7 +41,7 @@ rm -f env echo "PATH=$PATH" > env printenv | grep -E '^(LIBGUESTFS|LIBVIRT|LIBVIRTD|VIRTLOCKD|LD|MALLOC)_' >> env -TESTS=$(echo tests/guestfs_php_*.phpt) +TESTS=$(echo tests/guestfs_*.phpt) echo TESTS: $TESTS make test TESTS="$TESTS" PHP_EXECUTABLE="$PWD/php-for-tests.sh" REPORT_EXIT_STATUS=1 TEST_TIMEOUT=300 -- 2.5.0