diff options
Diffstat (limited to 'ext/opcache/tests')
23 files changed, 658 insertions, 0 deletions
diff --git a/ext/opcache/tests/001_cli.phpt b/ext/opcache/tests/001_cli.phpt new file mode 100644 index 0000000000..c51db23f56 --- /dev/null +++ b/ext/opcache/tests/001_cli.phpt @@ -0,0 +1,19 @@ +--TEST-- +001: O+ works in CLI +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$config = opcache_get_configuration(); +$status = opcache_get_status(); +var_dump($config["directives"]["opcache.enable"]); +var_dump($config["directives"]["opcache.enable_cli"]); +var_dump($status["opcache_enabled"]); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) diff --git a/ext/opcache/tests/blacklist.inc b/ext/opcache/tests/blacklist.inc new file mode 100644 index 0000000000..a9db751419 --- /dev/null +++ b/ext/opcache/tests/blacklist.inc @@ -0,0 +1,3 @@ +<?php + echo "ok\n"; +?> diff --git a/ext/opcache/tests/blacklist.phpt b/ext/opcache/tests/blacklist.phpt new file mode 100644 index 0000000000..18c205cacf --- /dev/null +++ b/ext/opcache/tests/blacklist.phpt @@ -0,0 +1,33 @@ +--TEST-- +Blacklist (with glob, quote and comments) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.blacklist_filename={PWD}/opcache-*.blacklist +opcache.file_update_protection=0 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$conf = opcache_get_configuration(); +$conf = $conf['blacklist']; +$conf[3] = preg_replace("!^\\Q".dirname(__FILE__)."\\E!", "__DIR__", $conf[3]); +$conf[4] = preg_replace("!^\\Q".dirname(__FILE__)."\\E!", "__DIR__", $conf[4]); +print_r($conf); +include("blacklist.inc"); +$status = opcache_get_status(); +print_r(count($status['scripts'])); +?> +--EXPECT-- +Array +( + [0] => /path/to/foo + [1] => /path/to/foo2 + [2] => /path/to/bar + [3] => __DIR__/blacklist.inc + [4] => __DIR__/current.php + [5] => /tmp/path/?nocache.inc + [6] => /tmp/path/*/somedir +) +ok +1 diff --git a/ext/opcache/tests/bug64353.phpt b/ext/opcache/tests/bug64353.phpt new file mode 100644 index 0000000000..b1f0c6e713 --- /dev/null +++ b/ext/opcache/tests/bug64353.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #64353 (Built-in classes can be unavailable with dynamic includes and OPcache) +--INI-- +allow_url_include=1 +opcache.enable=1 +opcache.enable_cli=1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +class BugLoader extends php_user_filter { + public function filter($in, $out, &$consumed, $closing) { + if (!class_exists("Test")) { + eval("class Test extends ArrayObject {}"); + } + while ($bucket = stream_bucket_make_writeable($in)) { + $consumed += $bucket->datalen; + stream_bucket_append($out, $bucket); + } + return PSFS_PASS_ON; + } +} + +stream_filter_register('bug.test', 'BugLoader'); +include "php://filter/read=bug.test/resource=data://text/plain,<?php\n"; +echo "OK\n"; +?> +--EXPECT-- +OK diff --git a/ext/opcache/tests/bug64482.inc b/ext/opcache/tests/bug64482.inc new file mode 100644 index 0000000000..e3d2b210c5 --- /dev/null +++ b/ext/opcache/tests/bug64482.inc @@ -0,0 +1,2 @@ +<?php +echo "Dynamic include"; diff --git a/ext/opcache/tests/bug64482.phpt b/ext/opcache/tests/bug64482.phpt new file mode 100644 index 0000000000..fa722f6d45 --- /dev/null +++ b/ext/opcache/tests/bug64482.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #64482 (Opcodes for dynamic includes should not be cached) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +include 'bug64482.inc'; +echo "\n"; +include 'php://filter/read=string.toupper/resource=bug64482.inc'; +echo "\n"; +?> +--EXPECT-- +Dynamic include +DYNAMIC INCLUDE diff --git a/ext/opcache/tests/bug65510.phpt b/ext/opcache/tests/bug65510.phpt new file mode 100644 index 0000000000..ba19d27d6f --- /dev/null +++ b/ext/opcache/tests/bug65510.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #65510 (5.5.2 crashes in _get_zval_ptr_ptr_var) +--INI-- +allow_url_include=1 +opcache.enable=1 +opcache.enable_cli=1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +function parseQuery() { + $m = array("l", "a", "r", "u", "e", "n", "c", "e"); + foreach($m as $n) { + @list($a, $b) = $n; + } +} +parseQuery(); +echo "ok\n"; +--EXPECT-- +ok diff --git a/ext/opcache/tests/bug65559.phpt b/ext/opcache/tests/bug65559.phpt new file mode 100644 index 0000000000..0d40cf10f8 --- /dev/null +++ b/ext/opcache/tests/bug65559.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #65559 (cache not cleared if changes occur while running) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=2 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$file = __DIR__ . "/bug6559.inc.php"; +file_put_contents($file, '<?php return 1;'); +$var = include $file; +var_dump($var); +file_put_contents($file, '<?php return 2;'); +$var = include $file; +var_dump($var); +@unlink($file); +?> +--EXPECT-- +int(1) +int(2) diff --git a/ext/opcache/tests/bug65665.phpt b/ext/opcache/tests/bug65665.phpt new file mode 100644 index 0000000000..ac5c18dd83 --- /dev/null +++ b/ext/opcache/tests/bug65665.phpt @@ -0,0 +1,118 @@ +--TEST-- +Bug #65665 (Exception not properly caught when opcache enabled) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +function foo() { + try + { + switch (1) + { + case 0: + try + { + + } + catch (Exception $e) + { + + } + + break; + + case 1: + try + { + throw new Exception('aaa'); + } + catch (Exception $e) + { + echo "correct\n"; + } + + break; + } + } + catch (Exception $e) + { + echo "wrong\n"; + } + return; +} + +function foo1() { + try + { + switch (1) + { + case 0: + try + { + + } + catch (Exception $e) + { +dummy: + echo "ect\n"; + } + + break; + + case 1: + try + { + throw new Exception('aaa'); + } + catch (Exception $e) + { + echo "corr"; + goto dummy; + } + break; + } + } + catch (Exception $e) + { + echo "wrong\n"; + } + return; +} + +function foo2() { + try + { + switch (1) + { + case 0: + try + { +dummy: + throw new Exception('aaa'); + } + catch (Exception $e) + { + echo "correct\n"; + } + + break; + + case 1: + goto dummy; + break; + } + } + catch (Exception $e) + { + echo "wrong\n"; + } + return; +} +foo();foo1();foo2(); +--EXPECT-- +correct +correct +correct diff --git a/ext/opcache/tests/bug65845.phpt b/ext/opcache/tests/bug65845.phpt new file mode 100644 index 0000000000..2ae5f3974a --- /dev/null +++ b/ext/opcache/tests/bug65845.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #65845 (Error when Zend Opcache Optimizer is fully enabled) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$Pile['vars'][(string)'toto'] = 'tutu'; +var_dump($Pile['vars']['toto']); +?> +--EXPECT-- +string(4) "tutu" diff --git a/ext/opcache/tests/bug65915.phpt b/ext/opcache/tests/bug65915.phpt new file mode 100644 index 0000000000..6496ee3253 --- /dev/null +++ b/ext/opcache/tests/bug65915.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #65915 (Inconsistent results with require return value) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$tmp = __DIR__ . "/bug65915.inc.php"; + +file_put_contents($tmp, '<?php return function(){ return "a";};'); +$f = require $tmp; +var_dump($f()); + +opcache_invalidate($tmp, true); + +file_put_contents($tmp, '<?php return function(){ return "b";};'); +$f = require $tmp; +var_dump($f()); + +@unlink($tmp); +?> +--EXPECT-- +string(1) "a" +string(1) "b" diff --git a/ext/opcache/tests/bug66176.phpt b/ext/opcache/tests/bug66176.phpt new file mode 100644 index 0000000000..a91024a616 --- /dev/null +++ b/ext/opcache/tests/bug66176.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #66176 (Invalid constant substitution) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.file_update_protection=0 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +function foo($v) { + global $a; + return $a[$v]; +} +$a = array(PHP_VERSION => 1); +var_dump(foo(PHP_VERSION)); +--EXPECT-- +int(1) diff --git a/ext/opcache/tests/issue0057.phpt b/ext/opcache/tests/issue0057.phpt new file mode 100644 index 0000000000..49e9156f15 --- /dev/null +++ b/ext/opcache/tests/issue0057.phpt @@ -0,0 +1,38 @@ +--TEST-- +ISSUE #57 (segfaults in drupal7) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +class ZException extends Exception { +} + +function dummy($query) { + try { + switch ($query) { + case 1; + break; + case 2; + break; + default: + throw new Exception('exception'); + } + } catch (ZException $e) { + return NULL; + } +} + +try { + dummy(0); +} catch (Exception $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +exception diff --git a/ext/opcache/tests/issue0079.phpt b/ext/opcache/tests/issue0079.phpt new file mode 100644 index 0000000000..4458fce5bc --- /dev/null +++ b/ext/opcache/tests/issue0079.phpt @@ -0,0 +1,34 @@ +--TEST-- +ISSUE #79 (Optimization Problem/Bug) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +class Test { + public function run() { + $r = $this->my_parse_m(); + var_dump ($r); + return $r; + } + + public function my_parse_m() { + $test = true; + if ($test === true) { + $a = 'b'; + } else { + return false; + } +// flush(); + return true; + } +} + +$t = new Test(); +var_dump ($t->run()); +--EXPECT-- +bool(true) +bool(true) diff --git a/ext/opcache/tests/issue0115.phpt b/ext/opcache/tests/issue0115.phpt new file mode 100644 index 0000000000..0dfdd9f0eb --- /dev/null +++ b/ext/opcache/tests/issue0115.phpt @@ -0,0 +1,48 @@ +--TEST-- +ISSUE #115 (path issue when using phar) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +phar.readonly=0 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (php_sapi_name() != "cli") die("skip CLI only"); ?> +--FILE-- +<?php +$stub = '<?php +Phar::interceptFileFuncs(); +require "phar://this/index.php"; +__HALT_COMPILER(); ?>'; +$p = new Phar(__DIR__ . '/issue0115_1.phar.php', 0, 'this'); +$p['index.php'] = '<?php +echo "Hello from Index 1.\n"; +require_once "phar://this/hello.php"; +'; +$p['hello.php'] = "Hello World 1!\n"; +$p->setStub($stub); +unset($p); +$p = new Phar(__DIR__ . '/issue0115_2.phar.php', 0, 'this'); +$p['index.php'] = '<?php +echo "Hello from Index 2.\n"; +require_once "phar://this/hello.php"; +'; +$p['hello.php'] = "Hello World 2!\n"; +$p->setStub($stub); +unset($p); + +include "php_cli_server.inc"; +php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1'); +echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0115_1.phar.php'); +echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0115_2.phar.php'); +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/issue0115_1.phar.php'); +@unlink(__DIR__ . '/issue0115_2.phar.php'); +?> +--EXPECT-- +Hello from Index 1. +Hello World 1! +Hello from Index 2. +Hello World 2! diff --git a/ext/opcache/tests/issue0128.phpt b/ext/opcache/tests/issue0128.phpt new file mode 100644 index 0000000000..637f675ac2 --- /dev/null +++ b/ext/opcache/tests/issue0128.phpt @@ -0,0 +1,16 @@ +--TEST-- +ISSUE #128 (opcache_invalidate segmentation fault) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +var_dump(opcache_invalidate('1')); +var_dump("okey"); +?> +--EXPECT-- +bool(false) +string(4) "okey" diff --git a/ext/opcache/tests/issue0140.phpt b/ext/opcache/tests/issue0140.phpt new file mode 100644 index 0000000000..98e0e45cc2 --- /dev/null +++ b/ext/opcache/tests/issue0140.phpt @@ -0,0 +1,43 @@ +--TEST-- +Issue #140: "opcache.enable_file_override" doesn't respect "opcache.revalidate_freq" +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.revalidate_freq=0 +opcache.file_update_protection=0 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +<?php if (php_sapi_name() != "cli") die("skip CLI only"); ?> +--FILE-- +<?php +define("FILENAME", dirname(__FILE__) . "/issuer0140.inc.php"); +file_put_contents(FILENAME, "1\n"); + +var_dump(is_readable(FILENAME)); +include(FILENAME); +var_dump(filemtime(FILENAME)); + +sleep(2); +file_put_contents(FILENAME, "2\n"); + +var_dump(is_readable(FILENAME)); +include(FILENAME); +var_dump(filemtime(FILENAME)); + +sleep(2); +unlink(FILENAME); + +var_dump(is_readable(FILENAME)); +var_dump(@include(FILENAME)); +var_dump(@filemtime(FILENAME)); +?> +--EXPECTF-- +bool(true) +1 +int(%d) +bool(true) +2 +int(%d) +bool(false) +bool(false) +bool(false) diff --git a/ext/opcache/tests/issue0149.phpt b/ext/opcache/tests/issue0149.phpt new file mode 100644 index 0000000000..8c7f1bb7e0 --- /dev/null +++ b/ext/opcache/tests/issue0149.phpt @@ -0,0 +1,35 @@ +--TEST-- +ISSUE #149 (Phar mount points not working this OPcache enabled) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +phar.readonly=0 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (php_sapi_name() != "cli") die("skip CLI only"); ?> +--FILE-- +<?php +$stub = "<?php header('Content-Type: text/plain;'); +Phar::mount('this.file', '". __FILE__ . "'); +echo 'OK\n'; +__HALT_COMPILER(); ?>"; +$p = new Phar(__DIR__ . '/issue0149.phar.php', 0, 'this'); +$p['index.php'] = ""; # A Phar must have at least one file, hence this dummy +$p->setStub($stub); +unset($p); + +include "php_cli_server.inc"; +php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1'); +echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0149.phar.php'); +echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0149.phar.php'); +echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0149.phar.php'); +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/issue0149.phar.php'); +?> +--EXPECT-- +OK +OK +OK diff --git a/ext/opcache/tests/opcache-1.blacklist b/ext/opcache/tests/opcache-1.blacklist new file mode 100644 index 0000000000..5f498d637c --- /dev/null +++ b/ext/opcache/tests/opcache-1.blacklist @@ -0,0 +1,5 @@ +; comments are allowed in blacklist file +; and empty line are ignored + +/path/to/foo +"/path/to/foo2"
\ No newline at end of file diff --git a/ext/opcache/tests/opcache-2.blacklist b/ext/opcache/tests/opcache-2.blacklist new file mode 100644 index 0000000000..575d9fab30 --- /dev/null +++ b/ext/opcache/tests/opcache-2.blacklist @@ -0,0 +1,6 @@ +/path/to/bar +; wildcard and relative entires +blacklist.inc +./current.php +/tmp/path/?nocache.inc +/tmp/path/*/somedir diff --git a/ext/opcache/tests/php_cli_server.inc b/ext/opcache/tests/php_cli_server.inc new file mode 100644 index 0000000000..0878bfafc0 --- /dev/null +++ b/ext/opcache/tests/php_cli_server.inc @@ -0,0 +1,47 @@ +<?php +define ("PHP_CLI_SERVER_HOSTNAME", "localhost"); +define ("PHP_CLI_SERVER_PORT", 8964); +define ("PHP_CLI_SERVER_ADDRESS", PHP_CLI_SERVER_HOSTNAME.":".PHP_CLI_SERVER_PORT); + +function php_cli_server_start($ini = "") { + $php_executable = getenv('TEST_PHP_EXECUTABLE'); + $doc_root = __DIR__; + + $descriptorspec = array( + 0 => STDIN, + 1 => STDOUT, + 2 => STDERR, + ); + + if (substr(PHP_OS, 0, 3) == 'WIN') { + $cmd = "{$php_executable} -t {$doc_root} $ini -S " . PHP_CLI_SERVER_ADDRESS; + $handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true)); + } else { + $cmd = "exec {$php_executable} -t {$doc_root} $ini -S " . PHP_CLI_SERVER_ADDRESS . " 2>/dev/null"; + $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root); + } + + // note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.' + // it might not be listening yet...need to wait until fsockopen() call returns + $i = 0; + while (($i++ < 30) && !($fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT))) { + usleep(10000); + } + + if ($fp) { + fclose($fp); + } + + register_shutdown_function( + function($handle) { + proc_terminate($handle); + }, + $handle + ); + // don't bother sleeping, server is already up + // server can take a variable amount of time to be up, so just sleeping a guessed amount of time + // does not work. this is why tests sometimes pass and sometimes fail. to get a reliable pass + // sleeping doesn't work. +} +?> + diff --git a/ext/opcache/tests/revalidate_path_01.phpt b/ext/opcache/tests/revalidate_path_01.phpt new file mode 100644 index 0000000000..cf2ac0d829 --- /dev/null +++ b/ext/opcache/tests/revalidate_path_01.phpt @@ -0,0 +1,61 @@ +--TEST-- +revalidate_path 01: OPCache must cache only resolved real paths when revalidate_path is set +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.revalidate_path=1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +<?php if (php_sapi_name() != "cli") die("skip CLI only"); ?> +--FILE-- +<?php +$dir = dirname(__FILE__); +$dir1 = "$dir/test1"; +$dir2 = "$dir/test2"; +$link = "$dir/test"; +$file1 = "$dir1/index.php"; +$file2 = "$dir2/index.php"; +$main = "$dir/main.php"; +@mkdir($dir1); +@mkdir($dir2); +@file_put_contents($main, '<?php include(\'' . $link .'/index.php\');'); +@file_put_contents($file1, "TEST 1\n"); +@file_put_contents($file2, "TEST 2\n"); +while (filemtime($file1) != filemtime($file2)) { + touch($file1); + touch($file2); +} +@unlink($link); +@symlink($dir1, $link); + +include "php_cli_server.inc"; +//php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.revalidate_path=1'); +php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.revalidate_path=1 -d opcache.file_update_protection=0 -d realpath_cache_size=0'); +echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/main.php'); +echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/main.php'); +@unlink($link); +@symlink($dir2, $link); +echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/main.php'); +echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/main.php'); +?> +--CLEAN-- +<?php +$dir = dirname(__FILE__); +$dir1 = "$dir/test1"; +$dir2 = "$dir/test2"; +$link = "$dir/test"; +$file1 = "$dir1/index.php"; +$file2 = "$dir2/index.php"; +$main = "$dir/main.php"; +@unlink($main); +@unlink($link); +@unlink($file1); +@unlink($file2); +@rmdir($dir1); +@rmdir($dir2); +?> +--EXPECT-- +TEST 1 +TEST 1 +TEST 2 +TEST 2 diff --git a/ext/opcache/tests/skipif.inc b/ext/opcache/tests/skipif.inc new file mode 100644 index 0000000000..c5a8181039 --- /dev/null +++ b/ext/opcache/tests/skipif.inc @@ -0,0 +1,3 @@ +<?php + if (!extension_loaded('Zend OPcache')) die('skip Zend OPcache extension not available'); +?> |