Skip to content

Commit 1cd2d7e

Browse files
committed
Add JIT/FFI tests
1 parent 6110b33 commit 1cd2d7e

File tree

62 files changed

+1951
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1951
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
FFI/JIT 001: Read Variable (scalar)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
extern int64_t stdout;
16+
EOF, 'libc.so.6');
17+
18+
$x = 0;
19+
for ($i = 0; $i < 5; $i++) {
20+
$x = $ffi->stdout;
21+
}
22+
var_dump($x);
23+
}
24+
test();
25+
?>
26+
--EXPECTF--
27+
int(%i)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
FFI/JIT 002: Read Variable (array)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
extern int8_t stdout[8];
16+
EOF, 'libc.so.6');
17+
18+
$x = 0;
19+
for ($i = 0; $i < 5; $i++) {
20+
$x = $ffi->stdout;
21+
}
22+
var_dump($x);
23+
}
24+
test();
25+
?>
26+
--EXPECTF--
27+
object(FFI\CData:int8_t[8])#%d (8) {
28+
[0]=>
29+
int(%i)
30+
[1]=>
31+
int(%i)
32+
[2]=>
33+
int(%i)
34+
[3]=>
35+
int(%i)
36+
[4]=>
37+
int(%i)
38+
[5]=>
39+
int(%i)
40+
[6]=>
41+
int(%i)
42+
[7]=>
43+
int(%i)
44+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
FFI/JIT 003: Read Variable (struct)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
typedef struct _IO_FILE { int32_t a; int32_t b;} FILE;
16+
extern FILE stdout;
17+
EOF, 'libc.so.6');
18+
19+
$x = 0;
20+
for ($i = 0; $i < 5; $i++) {
21+
$x = $ffi->stdout;
22+
}
23+
var_dump($x);
24+
}
25+
test();
26+
?>
27+
--EXPECTF--
28+
object(FFI\CData:struct _IO_FILE)#%d (2) {
29+
["a"]=>
30+
int(%i)
31+
["b"]=>
32+
int(%i)
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
FFI/JIT 004: Read Variable (struct ptr)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
typedef struct _IO_FILE FILE;
16+
extern FILE *stdout;
17+
EOF, 'libc.so.6');
18+
19+
$x = 0;
20+
for ($i = 0; $i < 5; $i++) {
21+
$x = $ffi->stdout;
22+
}
23+
var_dump($x);
24+
}
25+
test();
26+
?>
27+
--EXPECTF--
28+
object(FFI\CData:struct _IO_FILE*)#%d (1) {
29+
[0]=>
30+
object(FFI\CData:struct _IO_FILE)#%d (0) {
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
FFI/JIT 005: Read Variable (func)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
typedef int32_t (*func)(int32_t);
16+
extern func stdout;
17+
EOF, 'libc.so.6');
18+
19+
$x = 0;
20+
for ($i = 0; $i < 5; $i++) {
21+
$x = $ffi->stdout;
22+
}
23+
var_dump($x);
24+
}
25+
test();
26+
?>
27+
--EXPECTF--
28+
object(FFI\CData:int32_t(*)())#%d (1) {
29+
[0]=>
30+
object(FFI\CData:int32_t())#%d (0) {
31+
}
32+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
FFI/JIT 006: Write Variable (scalar)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
extern int64_t stdout;
16+
EOF, 'libc.so.6');
17+
18+
for ($i = 0; $i < 5; $i++) {
19+
$ffi->stdout = $i;
20+
}
21+
var_dump($ffi->stdout);
22+
}
23+
test();
24+
?>
25+
--EXPECT--
26+
int(4)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
FFI/JIT 007: Write Variable (scalar cdata)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
extern int64_t stdout;
16+
EOF, 'libc.so.6');
17+
18+
$x = $ffi->cast('int64_t', 42);
19+
var_dump($x);
20+
for ($i = 0; $i < 5; $i++) {
21+
$ffi->stdout = $x;
22+
}
23+
var_dump($ffi->stdout);
24+
}
25+
test();
26+
?>
27+
--EXPECTF--
28+
object(FFI\CData:int64_t)#%d (1) {
29+
["cdata"]=>
30+
int(42)
31+
}
32+
int(42)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
FFI/JIT 008: Write Variable (struct ptr null)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
typedef struct _IO_FILE FILE;
16+
extern FILE *stdout;
17+
EOF, 'libc.so.6');
18+
19+
for ($i = 0; $i < 5; $i++) {
20+
$ffi->stdout = null;
21+
}
22+
var_dump($ffi->stdout);
23+
}
24+
test();
25+
?>
26+
--EXPECT--
27+
NULL
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
FFI/JIT 009: Write Variable (struct ptr cdata)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
typedef struct _IO_FILE FILE;
16+
extern FILE *stdout;
17+
EOF, 'libc.so.6');
18+
19+
$x = $ffi->cast('FILE*', 42);
20+
var_dump($x);
21+
for ($i = 0; $i < 5; $i++) {
22+
$ffi->stdout = $x;
23+
}
24+
var_dump($ffi->stdout);
25+
var_dump($ffi->cast('intptr_t', $ffi->stdout));
26+
}
27+
test();
28+
?>
29+
--EXPECTF--
30+
object(FFI\CData:struct _IO_FILE*)#%d (1) {
31+
[0]=>
32+
object(FFI\CData:struct _IO_FILE)#%d (0) {
33+
}
34+
}
35+
object(FFI\CData:struct _IO_FILE*)#%d (1) {
36+
[0]=>
37+
object(FFI\CData:struct _IO_FILE)#%d (0) {
38+
}
39+
}
40+
object(FFI\CData:int%d_t)#%d (1) {
41+
["cdata"]=>
42+
int(42)
43+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
FFI/JIT 010: Modify Variable (scalar)
3+
--INI--
4+
ffi.enable=1
5+
;opcache.jit=tracing
6+
opcache.jit_hot_loop=1
7+
opcache.jit_hot_func=0
8+
opcache.jit_hot_return=0
9+
opcache.jit_hot_side_exit=0
10+
;opcache.jit_debug=0x180005
11+
--FILE--
12+
<?php
13+
function test() {
14+
$ffi = FFI::cdef(<<<EOF
15+
extern int64_t stdout;
16+
EOF, 'libc.so.6');
17+
18+
$ffi->stdout = null;
19+
for ($i = 0; $i < 5; $i++) {
20+
$ffi->stdout += $i;
21+
}
22+
var_dump($ffi->stdout);
23+
}
24+
test();
25+
?>
26+
--EXPECT--
27+
int(10)

0 commit comments

Comments
 (0)