13
13
14
14
namespace Reli \Lib \PhpProcessReader \CallTraceReader ;
15
15
16
+ use PHPUnit \Framework \Attributes \DataProviderExternal ;
16
17
use Reli \BaseTestCase ;
17
18
use Reli \Inspector \Settings \TargetPhpSettings \TargetPhpSettings ;
18
19
use Reli \Lib \ByteStream \IntegerByteSequence \LittleEndianReader ;
22
23
use Reli \Lib \Elf \SymbolResolver \Elf64SymbolResolverCreator ;
23
24
use Reli \Lib \File \CatFileReader ;
24
25
use Reli \Lib \PhpInternals \Opcodes \OpcodeFactory ;
25
- use Reli \Lib \PhpInternals \ZendTypeReader ;
26
26
use Reli \Lib \PhpInternals \ZendTypeReaderCreator ;
27
27
use Reli \Lib \PhpProcessReader \PhpGlobalsFinder ;
28
28
use Reli \Lib \PhpProcessReader \PhpSymbolReaderCreator ;
29
29
use Reli \Lib \Process \MemoryMap \ProcessMemoryMapCreator ;
30
30
use Reli \Lib \Process \MemoryReader \MemoryReader ;
31
31
use Reli \Lib \Process \ProcessSpecifier ;
32
+ use Reli \TargetPhpVmProvider ;
32
33
33
34
class CallTraceReaderTest extends BaseTestCase
34
35
{
@@ -47,17 +48,16 @@ protected function tearDown(): void
47
48
}
48
49
}
49
50
50
- public function testReadCallTrace ()
51
+ #[DataProviderExternal(TargetPhpVmProvider::class, 'allSupported ' )]
52
+ public function testReadCallTrace (string $ php_version , string $ docker_image_name ): void
51
53
{
52
54
$ memory_reader = new MemoryReader ();
53
55
$ executor_globals_reader = new CallTraceReader (
54
56
$ memory_reader ,
55
57
new ZendTypeReaderCreator (),
56
58
new OpcodeFactory ()
57
59
);
58
- $ tmp_file = tempnam (sys_get_temp_dir (), 'reli-prof-test ' );
59
- file_put_contents (
60
- $ tmp_file ,
60
+ $ target_script =
61
61
<<<CODE
62
62
<?php
63
63
class A {
@@ -69,22 +69,18 @@ public function wait() {
69
69
fputs(STDOUT, "a \n");
70
70
\$object->wait();
71
71
CODE
72
- );
73
- $ this ->child = proc_open (
74
- [
75
- PHP_BINARY ,
76
- $ tmp_file ,
77
- ],
78
- [
79
- ['pipe ' , 'r ' ],
80
- ['pipe ' , 'w ' ],
81
- ['pipe ' , 'w ' ]
82
- ],
72
+ ;
73
+ $ pipes = [];
74
+ [$ this ->child , $ pid ] = TargetPhpVmProvider::runScriptViaContainer (
75
+ $ docker_image_name ,
76
+ $ target_script ,
83
77
$ pipes
84
78
);
85
79
86
- fgets ($ pipes [1 ]);
80
+ $ s = fgets ($ pipes [1 ]);
81
+ $ this ->assertSame ("a \n" , $ s );
87
82
$ child_status = proc_get_status ($ this ->child );
83
+ $ this ->assertSame (true , $ child_status ['running ' ]);
88
84
$ php_symbol_reader_creator = new PhpSymbolReaderCreator (
89
85
$ memory_reader ,
90
86
new ProcessModuleSymbolReaderCreator (
@@ -108,17 +104,21 @@ public function wait() {
108
104
109
105
/** @var int $child_status['pid'] */
110
106
$ executor_globals_address = $ php_globals_finder ->findExecutorGlobals (
111
- new ProcessSpecifier ($ child_status ['pid ' ]),
112
- new TargetPhpSettings ()
107
+ new ProcessSpecifier ($ pid ),
108
+ new TargetPhpSettings (
109
+ php_version: $ php_version ,
110
+ )
113
111
);
114
112
$ sapi_globals_address = $ php_globals_finder ->findSAPIGlobals (
115
- new ProcessSpecifier ($ child_status ['pid ' ]),
116
- new TargetPhpSettings ()
113
+ new ProcessSpecifier ($ pid ),
114
+ new TargetPhpSettings (
115
+ php_version: $ php_version ,
116
+ )
117
117
);
118
118
119
119
$ call_trace = $ executor_globals_reader ->readCallTrace (
120
- $ child_status [ ' pid ' ] ,
121
- ZendTypeReader:: V81 ,
120
+ $ pid ,
121
+ $ php_version ,
122
122
$ executor_globals_address ,
123
123
$ sapi_globals_address ,
124
124
PHP_INT_MAX ,
@@ -142,7 +142,7 @@ public function wait() {
142
142
$ call_trace ->call_frames [1 ]->getFullyQualifiedFunctionName ()
143
143
);
144
144
$ this ->assertSame (
145
- $ tmp_file ,
145
+ ' /source ' ,
146
146
$ call_trace ->call_frames [1 ]->file_name
147
147
);
148
148
$ this ->assertSame (
@@ -154,7 +154,7 @@ public function wait() {
154
154
$ call_trace ->call_frames [2 ]->getFullyQualifiedFunctionName ()
155
155
);
156
156
$ this ->assertSame (
157
- $ tmp_file ,
157
+ ' /source ' ,
158
158
$ call_trace ->call_frames [2 ]->file_name
159
159
);
160
160
$ this ->assertSame (
0 commit comments