Skip to content

Commit f620d9c

Browse files
committed
Unit Tests for phpGH-16551
1 parent 1cdf3fa commit f620d9c

9 files changed

+278
-0
lines changed

ext/opcache/tests/gh16551_001.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
GH-16551: opcache file cache read only: generate file cache
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit=disable
7+
opcache.jit_buffer_size=0
8+
opcache.file_cache="{TMP}"
9+
--EXTENSIONS--
10+
opcache
11+
--CONFLICTS--
12+
opcache_file_cache
13+
--FILE--
14+
<?php
15+
16+
$file = __DIR__ . '/gh16551_998.inc';
17+
$uncached_file = __DIR__ . '/gh16551_999.inc';
18+
19+
opcache_compile_file($file);
20+
21+
var_dump(
22+
opcache_is_script_cached($file)
23+
);
24+
25+
var_dump(
26+
opcache_is_script_cached_in_file_cache($file)
27+
);
28+
29+
var_dump(
30+
opcache_is_script_cached($uncached_file)
31+
);
32+
33+
var_dump(
34+
opcache_is_script_cached_in_file_cache($uncached_file)
35+
);
36+
37+
?>
38+
--EXPECT--
39+
bool(true)
40+
bool(true)
41+
bool(false)
42+
bool(false)

ext/opcache/tests/gh16551_002.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
GH-16551: opcache file cache read only: read file cache
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit=disable
7+
opcache.jit_buffer_size=0
8+
opcache.file_cache="{TMP}"
9+
opcache.file_cache_read_only=1
10+
--EXTENSIONS--
11+
opcache
12+
--CONFLICTS--
13+
opcache_file_cache
14+
--FILE--
15+
<?php
16+
17+
$file = __DIR__ . '/gh16551_998.inc';
18+
$uncached_file = __DIR__ . '/gh16551_999.inc';
19+
20+
var_dump(
21+
opcache_is_script_cached_in_file_cache($file)
22+
);
23+
24+
require $file;
25+
26+
var_dump(
27+
opcache_is_script_cached_in_file_cache($uncached_file)
28+
);
29+
30+
require $uncached_file;
31+
32+
?>
33+
--EXPECT--
34+
bool(true)
35+
9
36+
bool(false)
37+
8

ext/opcache/tests/gh16551_003.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
GH-16551: opcache file cache read only: read file cache with limited checks
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit=disable
7+
opcache.jit_buffer_size=0
8+
opcache.file_cache="{TMP}"
9+
opcache.file_cache_read_only=1
10+
opcache.revalidate_freq=0
11+
opcache.enable_file_override=true
12+
opcache.validate_timestamps=false
13+
opcache.file_cache_consistency_checks=false
14+
--EXTENSIONS--
15+
opcache
16+
--CONFLICTS--
17+
opcache_file_cache
18+
--FILE--
19+
<?php
20+
21+
$file = __DIR__ . '/gh16551_998.inc';
22+
$uncached_file = __DIR__ . '/gh16551_999.inc';
23+
24+
var_dump(
25+
opcache_is_script_cached_in_file_cache($file)
26+
);
27+
28+
require $file;
29+
30+
var_dump(
31+
opcache_is_script_cached_in_file_cache($uncached_file)
32+
);
33+
34+
require $uncached_file;
35+
36+
?>
37+
--EXPECT--
38+
bool(true)
39+
9
40+
bool(false)
41+
8

ext/opcache/tests/gh16551_004.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
GH-16551: opcache file cache read only: ensure we can't invalidate
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit=disable
7+
opcache.jit_buffer_size=0
8+
opcache.file_cache="{TMP}"
9+
opcache.file_cache_read_only=1
10+
--EXTENSIONS--
11+
opcache
12+
--CONFLICTS--
13+
opcache_file_cache
14+
--FILE--
15+
<?php
16+
17+
$file = __DIR__ . '/gh16551_998.inc';
18+
19+
var_dump(
20+
opcache_is_script_cached_in_file_cache($file)
21+
);
22+
23+
// invalidate SHM, but silently ignore file cache.
24+
opcache_invalidate($file, true);
25+
26+
var_dump(
27+
opcache_is_script_cached_in_file_cache($file)
28+
);
29+
30+
require $file;
31+
32+
?>
33+
--EXPECT--
34+
bool(true)
35+
bool(true)
36+
9

ext/opcache/tests/gh16551_005.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
GH-16551: opcache file cache read only: ensure cache files aren't created
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit=disable
7+
opcache.jit_buffer_size=0
8+
opcache.file_cache="{TMP}"
9+
opcache.file_cache_read_only=1
10+
--EXTENSIONS--
11+
opcache
12+
--CONFLICTS--
13+
opcache_file_cache
14+
--FILE--
15+
<?php
16+
17+
$uncached_file = __DIR__ . '/gh16551_999.inc';
18+
19+
var_dump(
20+
opcache_is_script_cached($uncached_file)
21+
);
22+
23+
var_dump(
24+
opcache_is_script_cached_in_file_cache($uncached_file)
25+
);
26+
27+
opcache_compile_file($uncached_file);
28+
29+
var_dump(
30+
opcache_is_script_cached($uncached_file)
31+
);
32+
33+
var_dump(
34+
opcache_is_script_cached_in_file_cache($uncached_file)
35+
);
36+
37+
?>
38+
--EXPECT--
39+
bool(false)
40+
bool(false)
41+
bool(true)
42+
bool(false)

ext/opcache/tests/gh16551_099.phpt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
--TEST--
2+
GH-16551: opcache file cache read only: double check file_cache_only
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit=disable
7+
opcache.jit_buffer_size=0
8+
opcache.file_cache="{PWD}"
9+
opcache.file_cache_only=1
10+
--EXTENSIONS--
11+
opcache
12+
--CONFLICTS--
13+
opcache_file_cache
14+
--FILE--
15+
<?php
16+
17+
$uncached_file = __DIR__ . '/gh16551_999.inc';
18+
19+
var_dump(
20+
opcache_is_script_cached($uncached_file)
21+
);
22+
23+
var_dump(
24+
opcache_is_script_cached_in_file_cache($uncached_file)
25+
);
26+
27+
opcache_compile_file($uncached_file);
28+
29+
var_dump(
30+
opcache_is_script_cached($uncached_file)
31+
);
32+
33+
// check the cache file itself exists...
34+
if (substr(PHP_OS, 0, 3) !== 'WIN') {
35+
$pattern = __DIR__ . '/*/' . __DIR__ . '/*16551_999.inc.bin';
36+
} else {
37+
$pattern = __DIR__ . '/*/*/' . str_replace(':', '', __DIR__) . '/*16551_999.inc.bin';
38+
}
39+
foreach (glob($pattern) as $p) {
40+
var_dump($p !== false);
41+
}
42+
43+
// check it is reported as existing...
44+
var_dump(
45+
opcache_is_script_cached_in_file_cache($uncached_file)
46+
);
47+
48+
?>
49+
--CLEAN--
50+
<?php
51+
if (substr(PHP_OS, 0, 3) !== 'WIN') {
52+
$pattern = __DIR__ . '/*/' . __DIR__ . '/*16551_999.inc.bin';
53+
} else {
54+
$pattern = __DIR__ . '/*/*/' . str_replace(':', '', __DIR__) . '/*16551_999.inc.bin';
55+
}
56+
foreach (glob($pattern) as $p) {
57+
unlink($p);
58+
$p = dirname($p);
59+
while(strlen($p) > strlen(__DIR__)) {
60+
rmdir($p);
61+
$p = dirname($p);
62+
}
63+
}
64+
?>
65+
--EXPECT--
66+
bool(false)
67+
bool(false)
68+
bool(false)
69+
bool(true)
70+
bool(true)

ext/opcache/tests/gh16551_998.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$a = 4+5;
4+
5+
echo $a . "\n";

ext/opcache/tests/gh16551_999.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$a = 3+5;
4+
5+
echo $a . "\n";
File renamed without changes.

0 commit comments

Comments
 (0)