From dff0d51243d372b1efd30c7121f30fd2ef636b99 Mon Sep 17 00:00:00 2001 From: Gernot Vormayr Date: Tue, 7 Jan 2014 00:21:24 +0100 Subject: [PATCH] Add some basic and apparmor tests to fpm --- run-tests.php | 2 +- sapi/fpm/tests/001.phpt | 21 +++++++++ sapi/fpm/tests/002.phpt | 53 ++++++++++++++++++++++ sapi/fpm/tests/apparmor.phpt | 54 ++++++++++++++++++++++ sapi/fpm/tests/include.inc | 79 +++++++++++++++++++++++++++++++++ sapi/fpm/tests/skipapparmor.inc | 30 +++++++++++++ sapi/fpm/tests/skipif.inc | 13 ++++++ 7 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 sapi/fpm/tests/001.phpt create mode 100644 sapi/fpm/tests/002.phpt create mode 100644 sapi/fpm/tests/apparmor.phpt create mode 100644 sapi/fpm/tests/include.inc create mode 100644 sapi/fpm/tests/skipapparmor.inc create mode 100644 sapi/fpm/tests/skipif.inc diff --git a/run-tests.php b/run-tests.php index 45ea29de51..cd6038e9b1 100755 --- a/run-tests.php +++ b/run-tests.php @@ -850,7 +850,7 @@ $exts_skipped = 0; $ignored_by_ext = 0; sort($exts_to_test); $test_dirs = array(); -$optionals = array('tests', 'ext', 'Zend', 'ZendEngine2', 'sapi/cli', 'sapi/cgi'); +$optionals = array('tests', 'ext', 'Zend', 'ZendEngine2', 'sapi/cli', 'sapi/cgi', 'sapi/fpm'); foreach($optionals as $dir) { if (@filetype($dir) == 'dir') { diff --git a/sapi/fpm/tests/001.phpt b/sapi/fpm/tests/001.phpt new file mode 100644 index 0000000000..b721bfa925 --- /dev/null +++ b/sapi/fpm/tests/001.phpt @@ -0,0 +1,21 @@ +--TEST-- +FPM: version string +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(%d) "PHP %s (fpm%s (built: %s +Copyright (c) 1997-20%s The PHP Group +Zend Engine v%s, Copyright (c) 1998-20%s Zend Technologies +" +Done diff --git a/sapi/fpm/tests/002.phpt b/sapi/fpm/tests/002.phpt new file mode 100644 index 0000000000..2ef6cedc38 --- /dev/null +++ b/sapi/fpm/tests/002.phpt @@ -0,0 +1,53 @@ +--TEST-- +FPM: Startup and connect +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(%d) "[%d-%s-%d %d:%d:%d] NOTICE: fpm is running, pid %d +" +string(%d) "[%d-%s-%d %d:%d:%d] NOTICE: ready to handle connections +" +Done +--CLEAN-- + diff --git a/sapi/fpm/tests/apparmor.phpt b/sapi/fpm/tests/apparmor.phpt new file mode 100644 index 0000000000..cf9bd71118 --- /dev/null +++ b/sapi/fpm/tests/apparmor.phpt @@ -0,0 +1,54 @@ +--TEST-- +FPM: Apparmor Test +--DESCRIPTION-- +This test tries to launches a pool which tries to change to non existing +apparmor hat a. Test succeeds if apparmor is not running or hat is non +existant. +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(%d) "%s +" +--CLEAN-- + diff --git a/sapi/fpm/tests/include.inc b/sapi/fpm/tests/include.inc new file mode 100644 index 0000000000..983cbd3454 --- /dev/null +++ b/sapi/fpm/tests/include.inc @@ -0,0 +1,79 @@ + array('pipe', 'w')]; + } + /* Since it's not possible to spawn a process under linux without using a + * shell in php (why?!?) we need a little shell trickery, so that we can + * actually kill php-fpm */ + $fpm = proc_open('killit () { kill $child; }; trap killit TERM; '.get_fpm_path().' -F -O -y '.$cfg.' '.$extra_args.' 2>&1 & child=$!; wait', $desc, $pipes); + register_shutdown_function( + function($fpm) use($cfg) { + @unlink($cfg); + if (is_resource($fpm)) { + @proc_terminate($fpm); + while (proc_get_status($fpm)['running']) { + usleep(10000); + } + } + }, + $fpm + ); + if ($out !== false) { + $out = $pipes[1]; + } + return $fpm; +} +/* }}} */ + +function run_fpm_till($needle, $config, $max = 10) /* {{{ */ +{ + $i = 0; + $fpm = run_fpm($config, $tail); + if (is_resource($fpm)) { + while($i < $max) { + $i++; + $line = fgets($tail); + if(preg_match($needle, $line) === 1) { + break; + } + } + if ($i >= $max) { + $line = false; + } + proc_terminate($fpm); + stream_get_contents($tail); + fclose($tail); + proc_close($fpm); + } + return $line; +} +/* }}} */ + +?> diff --git a/sapi/fpm/tests/skipapparmor.inc b/sapi/fpm/tests/skipapparmor.inc new file mode 100644 index 0000000000..b286d0361d --- /dev/null +++ b/sapi/fpm/tests/skipapparmor.inc @@ -0,0 +1,30 @@ + diff --git a/sapi/fpm/tests/skipif.inc b/sapi/fpm/tests/skipif.inc new file mode 100644 index 0000000000..8c569daafd --- /dev/null +++ b/sapi/fpm/tests/skipif.inc @@ -0,0 +1,13 @@ + -- 2.40.0