Skip to content

Commit 378a05f

Browse files
committed
Move phpdbg tests to .phpt mechanism
Also add a few more in-depth tests related to $argv, breakpoints and uncaught exceptions
1 parent 75a3de0 commit 378a05f

32 files changed

+991
-796
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,3 @@ before_script:
5050
# Run PHPs run-tests.php
5151
script:
5252
- ./sapi/cli/php run-tests.php -p `pwd`/sapi/cli/php $(if [ $ENABLE_DEBUG == 1 ]; then echo "-d opcache.enable_cli=1 -d zend_extension=`pwd`/modules/opcache.so"; fi) -g "FAIL,XFAIL,BORK,WARN,LEAK,SKIP" --offline --show-diff --set-timeout 120
53-
- ./sapi/cli/php sapi/phpdbg/tests/run-tests.php -diff2stdout --phpdbg sapi/phpdbg/phpdbg

run-tests.php

Lines changed: 96 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141

142142
$php = null;
143143
$php_cgi = null;
144+
$phpdbg = null;
144145

145146
if (getenv('TEST_PHP_EXECUTABLE')) {
146147
$php = getenv('TEST_PHP_EXECUTABLE');
@@ -158,6 +159,16 @@
158159
$php_cgi = null;
159160
}
160161
}
162+
163+
if (!getenv('TEST_PHPDBG_EXECUTABLE')) {
164+
$phpdbg = $cwd . '/sapi/phpdbg/phpdbg';
165+
166+
if (file_exists($phpdbg)) {
167+
putenv("TEST_PHP_CGI_EXECUTABLE=$phpdbg");
168+
} else {
169+
$phpdbg = null;
170+
}
171+
}
161172
}
162173
$environment['TEST_PHP_EXECUTABLE'] = $php;
163174
}
@@ -173,6 +184,17 @@
173184
$environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi;
174185
}
175186

187+
if (getenv('TEST_PHPDBG_EXECUTABLE')) {
188+
$phpdbg = getenv('TEST_PHPDBG_EXECUTABLE');
189+
190+
if ($phpdbg=='auto') {
191+
$phpdbg = $cwd . '/sapi/phpdbg/phpdbg';
192+
putenv("TEST_PHPDBG_EXECUTABLE=$phpdbg");
193+
}
194+
195+
$environment['TEST_PHPDBG_EXECUTABLE'] = $phpdbg;
196+
}
197+
176198
function verify_config()
177199
{
178200
global $php;
@@ -247,7 +269,7 @@ function verify_config()
247269

248270
function write_information($show_html)
249271
{
250-
global $cwd, $php, $php_cgi, $php_info, $user_tests, $ini_overwrites, $pass_options, $exts_to_test, $leak_check, $valgrind_header, $no_file_cache;
272+
global $cwd, $php, $php_cgi, $phpdbg, $php_info, $user_tests, $ini_overwrites, $pass_options, $exts_to_test, $leak_check, $valgrind_header, $no_file_cache;
251273

252274
// Get info from php
253275
$info_file = __DIR__ . '/run-test-info.php';
@@ -274,6 +296,14 @@ function write_information($show_html)
274296
$php_cgi_info = '';
275297
}
276298

299+
if ($phpdbg) {
300+
$phpdbg_info = `$phpdbg $pass_options $info_params $no_file_cache -qrr "$info_file"`;
301+
$php_info_sep = "\n---------------------------------------------------------------------";
302+
$phpdbg_info = "$php_info_sep\nPHP : $phpdbg $phpdbg_info$php_info_sep";
303+
} else {
304+
$phpdbg_info = '';
305+
}
306+
277307
@unlink($info_file);
278308

279309
// load list of enabled extensions
@@ -299,7 +329,7 @@ function write_information($show_html)
299329
// Write test context information.
300330
echo "
301331
=====================================================================
302-
PHP : $php $php_info $php_cgi_info
332+
PHP : $php $php_info $php_cgi_info $phpdbg_info
303333
CWD : $cwd
304334
Extra dirs : ";
305335
foreach ($user_tests as $test_dir) {
@@ -1205,6 +1235,10 @@ function run_test($php, $file, $env)
12051235
$php_cgi = $env['TEST_PHP_CGI_EXECUTABLE'];
12061236
}
12071237

1238+
if (isset($env['TEST_PHPDBG_EXECUTABLE'])) {
1239+
$phpdbg = $env['TEST_PHPDBG_EXECUTABLE'];
1240+
}
1241+
12081242
if (is_array($file)) {
12091243
$file = $file[0];
12101244
}
@@ -1290,7 +1324,7 @@ function run_test($php, $file, $env)
12901324

12911325
} else {
12921326

1293-
if (@count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) {
1327+
if (!isset($section_text['PHPDBG']) && @count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) {
12941328
$bork_info = "missing section --FILE--";
12951329
$borked = true;
12961330
}
@@ -1372,6 +1406,38 @@ function run_test($php, $file, $env)
13721406
}
13731407
}
13741408

1409+
/* For phpdbg tests, check if phpdbg sapi is available and if it is, use it. */
1410+
if (array_key_exists('PHPDBG', $section_text)) {
1411+
if (!isset($section_text['STDIN'])) {
1412+
$section_text['STDIN'] = $section_text['PHPDBG']."\n";
1413+
}
1414+
1415+
if (isset($phpdbg)) {
1416+
$old_php = $php;
1417+
$php = $phpdbg . ' -qIb';
1418+
} else if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/phpdbg.exe")) {
1419+
$old_php = $php;
1420+
$php = realpath(dirname($php) . "/phpdbg.exe") . ' -qIb ';
1421+
} else {
1422+
if (file_exists(dirname($php) . "/../../sapi/phpdbg/phpdbg")) {
1423+
$old_php = $php;
1424+
$php = realpath(dirname($php) . "/../../sapi/phpdbg/phpdbg") . ' -qIb ';
1425+
} else if (file_exists("./sapi/phpdbg/phpdbg")) {
1426+
$old_php = $php;
1427+
$php = realpath("./sapi/phpdbg/phpdbg") . ' -qIb ';
1428+
} else if (file_exists(dirname($php) . "/phpdbg")) {
1429+
$old_php = $php;
1430+
$php = realpath(dirname($php) . "/phpdbg") . ' -qIb ';
1431+
} else {
1432+
show_result('SKIP', $tested, $tested_file, "reason: phpdbg not available");
1433+
1434+
junit_init_suite(junit_get_suitename_for($shortname));
1435+
junit_mark_test_as('SKIP', $shortname, $tested, 0, 'phpdbg not available');
1436+
return 'SKIPPED';
1437+
}
1438+
}
1439+
}
1440+
13751441
if (!$SHOW_ONLY_GROUPS) {
13761442
show_test($test_idx, $shortname);
13771443
}
@@ -1652,8 +1718,12 @@ function run_test($php, $file, $env)
16521718
}
16531719

16541720
// We've satisfied the preconditions - run the test!
1655-
show_file_block('php', $section_text['FILE'], 'TEST');
1656-
save_text($test_file, $section_text['FILE'], $temp_file);
1721+
if (isset($section_text['FILE'])) {
1722+
show_file_block('php', $section_text['FILE'], 'TEST');
1723+
save_text($test_file, $section_text['FILE'], $temp_file);
1724+
} else {
1725+
$test_file = $temp_file = "";
1726+
}
16571727

16581728
if (array_key_exists('GET', $section_text)) {
16591729
$query_string = trim($section_text['GET']);
@@ -1741,7 +1811,7 @@ function run_test($php, $file, $env)
17411811
$env['REQUEST_METHOD'] = 'PUT';
17421812

17431813
if (empty($request)) {
1744-
junit_mark_test_as('BORK', $shortname, $tested, null, 'empty $request');
1814+
junit_mark_test_as('BORK', $shortname, $tested, null, 'empty $request');
17451815
return 'BORKED';
17461816
}
17471817

@@ -1765,34 +1835,33 @@ function run_test($php, $file, $env)
17651835

17661836
$cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
17671837

1768-
} else if (array_key_exists('GZIP_POST', $section_text) && !empty($section_text['GZIP_POST'])) {
1769-
1770-
$post = trim($section_text['GZIP_POST']);
1771-
$post = gzencode($post, 9, FORCE_GZIP);
1772-
$env['HTTP_CONTENT_ENCODING'] = 'gzip';
1838+
} else if (array_key_exists('GZIP_POST', $section_text) && !empty($section_text['GZIP_POST'])) {
17731839

1774-
save_text($tmp_post, $post);
1775-
$content_length = strlen($post);
1840+
$post = trim($section_text['GZIP_POST']);
1841+
$post = gzencode($post, 9, FORCE_GZIP);
1842+
$env['HTTP_CONTENT_ENCODING'] = 'gzip';
17761843

1777-
$env['REQUEST_METHOD'] = 'POST';
1778-
$env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
1779-
$env['CONTENT_LENGTH'] = $content_length;
1844+
save_text($tmp_post, $post);
1845+
$content_length = strlen($post);
17801846

1781-
$cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
1847+
$env['REQUEST_METHOD'] = 'POST';
1848+
$env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
1849+
$env['CONTENT_LENGTH'] = $content_length;
17821850

1783-
} else if (array_key_exists('DEFLATE_POST', $section_text) && !empty($section_text['DEFLATE_POST'])) {
1784-
$post = trim($section_text['DEFLATE_POST']);
1785-
$post = gzcompress($post, 9);
1786-
$env['HTTP_CONTENT_ENCODING'] = 'deflate';
1787-
save_text($tmp_post, $post);
1788-
$content_length = strlen($post);
1851+
$cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
17891852

1790-
$env['REQUEST_METHOD'] = 'POST';
1791-
$env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
1792-
$env['CONTENT_LENGTH'] = $content_length;
1853+
} else if (array_key_exists('DEFLATE_POST', $section_text) && !empty($section_text['DEFLATE_POST'])) {
1854+
$post = trim($section_text['DEFLATE_POST']);
1855+
$post = gzcompress($post, 9);
1856+
$env['HTTP_CONTENT_ENCODING'] = 'deflate';
1857+
save_text($tmp_post, $post);
1858+
$content_length = strlen($post);
17931859

1794-
$cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
1860+
$env['REQUEST_METHOD'] = 'POST';
1861+
$env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
1862+
$env['CONTENT_LENGTH'] = $content_length;
17951863

1864+
$cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
17961865

17971866
} else {
17981867

sapi/phpdbg/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dnl $Id$
33
dnl
44

55
PHP_ARG_ENABLE(phpdbg, for phpdbg support,
6-
[ --enable-phpdbg Build phpdbg], no, no)
6+
[ --enable-phpdbg Build phpdbg], yes, yes)
77

88
PHP_ARG_ENABLE(phpdbg-webhelper, for phpdbg web SAPI support,
99
[ --enable-phpdbg-webhelper Build phpdbg web SAPI support], yes, yes)

sapi/phpdbg/create-test.php

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
+----------------------------------------------------------------------+
6+
| PHP Version 7 |
7+
+----------------------------------------------------------------------+
8+
| Copyright (c) 1997-2015 The PHP Group |
9+
+----------------------------------------------------------------------+
10+
| This source file is subject to version 3.01 of the PHP license, |
11+
| that is bundled with this package in the file LICENSE, and is |
12+
| available through the world-wide-web at the following url: |
13+
| http://www.php.net/license/3_01.txt |
14+
| If you did not receive a copy of the PHP license and are unable to |
15+
| obtain it through the world-wide-web, please send a note to |
16+
| license@php.net so we can mail you a copy immediately. |
17+
+----------------------------------------------------------------------+
18+
| Authors: Bob Weinand <bwoebi@php.net> |
19+
+----------------------------------------------------------------------+
20+
*/
21+
22+
#####
23+
## This is just a helper for intercepting stdin/stdout and the file and create a half-finished test.
24+
## The output still may need adapting to match file names etc.
25+
#####
26+
27+
error_reporting(-1);
28+
29+
$phpdbg = getenv('TEST_PHPDBG_EXECUTABLE') ?: null;
30+
$pass_options = " -qbI";
31+
$file = "";
32+
$cmdargv = "";
33+
34+
if (isset($argc) && $argc > 1) {
35+
$post_ddash = false;
36+
for ($i = 1; $i < $argc; $i++) {
37+
if ($argv[$i][0] == "-" && !$post_ddash) {
38+
switch (substr($argv[$i], 1)) {
39+
case "p":
40+
$phpdbg = $argv[++$i];
41+
break;
42+
case "n":
43+
$pass_options .= " -n";
44+
break;
45+
case "d":
46+
$pass_options .= " -d ".escapeshellarg($argv[++$i]);
47+
$ini[] = $argv[$i];
48+
break;
49+
case "-":
50+
$post_ddash = true;
51+
break;
52+
}
53+
} else {
54+
$real_argv[] = $argv[$i];
55+
}
56+
}
57+
if (isset($real_argv[0])) {
58+
$file = realpath($real_argv[0]);
59+
$cmdargv = implode(" ", array_map("escapeshellarg", array_slice($real_argv, 1)));
60+
}
61+
}
62+
63+
$proc = proc_open("$phpdbg $pass_options $file -- $cmdargv", [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes);
64+
if (!$proc) {
65+
die("Couldn't start phpdbg\n");
66+
}
67+
68+
$input = $output = "";
69+
70+
stream_set_blocking(STDIN, false);
71+
72+
do {
73+
$r = [$pipes[1], STDIN];
74+
$w = $e = null;
75+
$n = @stream_select($r, $w, $e, null);
76+
77+
if ($n > 0) {
78+
if ("" != $in = fread(STDIN, 1024)) {
79+
$input .= $in;
80+
fwrite($pipes[0], $in);
81+
continue;
82+
}
83+
84+
if (feof(STDIN)) {
85+
die("stdin closed?!\n");
86+
}
87+
88+
if (feof($pipes[1])) {
89+
$n = false;
90+
} else {
91+
$output .= $c = fgetc($pipes[1]);
92+
echo $c;
93+
}
94+
}
95+
} while ($n !== false);
96+
97+
stream_set_blocking(STDIN, true);
98+
99+
print "\n";
100+
if (!isset($name)) {
101+
print "Specifiy the test description: ";
102+
$desc = trim(fgets(STDIN));
103+
}
104+
while (!isset($testfile)) {
105+
print "Specifiy the test file name (leave empty to write to stderr): ";
106+
$testfile = trim(fgets(STDIN));
107+
if ($testfile != "" && file_exists($testfile)) {
108+
print "That file already exists. Type y or yes to overwrite: ";
109+
$y = trim(fgets(STDIN));
110+
if ($y !== "y" && $y !== "yes") {
111+
unset($testfile);
112+
}
113+
}
114+
}
115+
116+
$output = str_replace("string(".strlen($file).") \"$file\"", 'string(%d) "%s"', $output);
117+
$output = str_replace($file, "%s", $output);
118+
$input = trim($input);
119+
120+
$testdata = <<<TEST
121+
--TEST--
122+
$desc
123+
--PHPDBG--
124+
$input
125+
--EXPECTF--
126+
$output
127+
TEST;
128+
129+
if (!empty($ini)) {
130+
$testdata .= "\n--INI--\n".implode("\n", $ini);
131+
}
132+
if ($cmdargv != "") {
133+
$testdata .= "\n--ARGS--\n$cmdargv";
134+
}
135+
if ($file != "") {
136+
$testdata .= "\n--FILE--\n".file_get_contents($file);
137+
}
138+
139+
if ($testfile == "") {
140+
print "\n";
141+
} elseif (file_put_contents($testfile, $testdata)) {
142+
print "Test saved to $testfile\n";
143+
} else {
144+
print "The test could not be saved to $testfile; outputting on stderr now\n";
145+
$testfile = "";
146+
}
147+
148+
if ($testfile == "") {
149+
fwrite(STDERR, $testdata);
150+
}

sapi/phpdbg/tests/basic_run.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Basic run
3+
--PHPDBG--
4+
r
5+
q
6+
--EXPECTF--
7+
prompt> [Nothing to execute!]
8+
prompt>

0 commit comments

Comments
 (0)