php: restructure and expand tests

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_090_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
  090_version and 100_launch
This commit is contained in:
Pino Toscano
2016-02-12 15:10:07 +01:00
parent 9753986819
commit 7a598a0c02
9 changed files with 112 additions and 46 deletions

14
.gitignore vendored
View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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