Extend test suite to support XFAIL section

This commit is contained in:
Dmitry Stogov 2022-11-22 10:43:29 +03:00
parent c9212a1f57
commit c6aeb417fa
9 changed files with 52 additions and 41 deletions

View File

@ -6,51 +6,31 @@
* Authors: Dmitry Stogov <dmitry@php.net> * Authors: Dmitry Stogov <dmitry@php.net>
*/ */
function parse_test($test, &$name, &$code, &$expect, &$args, &$target) { function parse_test($test, &$name, &$code, &$expect, &$args, &$target, &$xfail) {
$sections = array();
$text = @file_get_contents($test); $text = @file_get_contents($test);
if (!$text) { if (!$text || !preg_match_all("/^--[A-Z]+--$/m", $text, $r, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
return false; return false;
} }
$p1 = strpos($text, '--TEST--'); foreach($r as $sect) {
$p_args = strpos($text, '--ARGS--'); if (isset($sect_name)) {
$p_target = strpos($text, '--TARGET--'); $sections[$sect_name] = trim(substr($text, $sect_offset, $sect[0][1] - $sect_offset));
$p3 = strpos($text, '--CODE--'); }
$p4 = strpos($text, '--EXPECT--'); $sect_name = $sect[0][0];
if ($p1 === false || $p3 === false || $p4 === false || $p1 > $p3 || $p3 > $p4) { $sect_offset = $sect[0][1] + strlen($sect_name);
}
if (isset($sect_name)) {
$sections[$sect_name] = trim(substr($text, $sect_offset));
}
if (!isset($sections['--TEST--']) || !isset($sections['--CODE--']) || !isset($sections['--EXPECT--'])) {
return false; return false;
} }
$code = trim(substr($text, $p3 + strlen('--CODE--'), $p4 - $p3 - strlen('--CODE--'))); $name = $sections['--TEST--'];
$expect = trim(substr($text, $p4 + strlen('--EXPECT--'))); $code = $sections['--CODE--'];
$expect = str_replace("\r", "", $expect); $expect = $sections['--EXPECT--'];
$args = isset($sections['--ARGS--']) ? $sections['--ARGS--'] : "--save";
$end_name = $p3; $target = isset($sections['--TARGET--']) ? $sections['--TARGET--'] : null;
$args = "--save"; $xfail = isset($sections['--XFAIL--']) ? $sections['--XFAIL--'] : null;
$target = null;
if ($p_args !== false ) {
$end = ($p_target !== false && $p_target > $p_args) ? $p_target : $p3;
if ($p_args < $p1 || $p_args > $end) {
return false;
}
if ($p_args < $end_name) {
$end_name = $p_args;
}
$args = trim(substr($text, $p_args + strlen('--ARGS--'), $end - $p_args - strlen('--ARGS--')));
}
if ($p_target !== false ) {
$end = ($p_args !== false && $p_args > $p_target) ? $p_args : $p3;
if ($p_target < $p1 || $p_target > $end) {
return false;
}
if ($p_target < $end_name) {
$end_name = $p_target;
}
$target = trim(substr($text, $p_target + strlen('--TARGET--'), $end - $p_target - strlen('--TARGET--')));
}
$name = trim(substr($text, $p1 + strlen('--TEST--'), $end_name - $p1 - strlen('--TEST--')));
return true; return true;
} }
@ -120,11 +100,12 @@ function run_tests() {
$tests = find_tests("$src_dir/tests"); $tests = find_tests("$src_dir/tests");
$bad = array(); $bad = array();
$failed = array(); $failed = array();
$xfailed = array();
$total = count($tests); $total = count($tests);
$count = 0; $count = 0;
foreach($tests as $test) { foreach($tests as $test) {
$count++; $count++;
if (parse_test($test, $name, $code, $expect, $opt, $test_target)) { if (parse_test($test, $name, $code, $expect, $opt, $test_target, $xfail)) {
if ($test_target !== null && $target != $test_target) { if ($test_target !== null && $target != $test_target) {
echo "\r\e[1;33mSKIP\e[0m: $name [$test]\n"; echo "\r\e[1;33mSKIP\e[0m: $name [$test]\n";
$skiped++; $skiped++;
@ -138,6 +119,9 @@ function run_tests() {
echo str_repeat(" ", $len); echo str_repeat(" ", $len);
if ($ret) { if ($ret) {
echo "\r\e[1;32mPASS\e[0m: $name [$test]\n"; echo "\r\e[1;32mPASS\e[0m: $name [$test]\n";
} else if (isset($xfail)) {
echo "\r\e[1;31mXFAIL\e[0m: $name [$test] XFAIL REASON: $xfail\n";
$xfailed[$test] = array($name, $xfail);
} else { } else {
echo "\r\e[1;31mFAIL\e[0m: $name [$test]\n"; echo "\r\e[1;31mFAIL\e[0m: $name [$test]\n";
$failed[$test] = $name; $failed[$test] = $name;
@ -165,9 +149,20 @@ function run_tests() {
} }
echo "Total: " . count($tests) . "\n"; echo "Total: " . count($tests) . "\n";
echo "Passed: " . (count($tests) - count($failed) - $skiped) . "\n"; echo "Passed: " . (count($tests) - count($failed) - $skiped) . "\n";
echo "Expected fail: " . count($xfailed) . "\n";
echo "Failed: " . count($failed) . "\n"; echo "Failed: " . count($failed) . "\n";
echo "Skiped: " . $skiped . "\n"; echo "Skiped: " . $skiped . "\n";
if (count($xfailed) > 0) {
echo "-------------------------------\n";
echo "EXPECTED FAILED TESTS\n";
echo "-------------------------------\n";
foreach ($xfailed as $test => list($name, $xfail)) {
echo "$name [$test] XFAIL REASON: $xfail\n";
}
}
if (count($failed) > 0) { if (count($failed) > 0) {
echo "-------------------------------\n";
echo "FAILED TESTS\n";
echo "-------------------------------\n"; echo "-------------------------------\n";
foreach ($failed as $test => $name) { foreach ($failed as $test => $name) {
echo "$name [$test]\n"; echo "$name [$test]\n";

View File

@ -2,6 +2,8 @@
Simple CALL Simple CALL
--TARGET-- --TARGET--
x86 x86
--XFAIL--
TAILCALL for functions with stack argumnts is not implemented
--ARGS-- --ARGS--
-S --run -S --run
--CODE-- --CODE--

View File

@ -2,6 +2,8 @@
Indirect Tail CALL Indirect Tail CALL
--TARGET-- --TARGET--
x86 x86
--XFAIL--
TAILCALL for functions with stack argumnts is not implemented
--ARGS-- --ARGS--
-S -S
--CODE-- --CODE--

View File

@ -2,6 +2,8 @@
009: add function 009: add function
--TARGET-- --TARGET--
x86 x86
--XFAIL--
64-bit integers are not implemented on 32-bit systems
--ARGS-- --ARGS--
-S -S
--CODE-- --CODE--

View File

@ -2,6 +2,8 @@
001: type conversion SEXT 001: type conversion SEXT
--TARGET-- --TARGET--
x86 x86
--XFAIL--
64-bit integers are not implemented on 32-bit systems
--ARGS-- --ARGS--
-S -S
--CODE-- --CODE--

View File

@ -2,6 +2,8 @@
002: type conversion ZEXT 002: type conversion ZEXT
--TARGET-- --TARGET--
x86 x86
--XFAIL--
64-bit integers are not implemented on 32-bit systems
--ARGS-- --ARGS--
-S -S
--CODE-- --CODE--

View File

@ -2,6 +2,8 @@
004: type conversion BITCAST 004: type conversion BITCAST
--TARGET-- --TARGET--
x86 x86
--XFAIL--
64-bit integers are not implemented on 32-bit systems
--ARGS-- --ARGS--
-S -S
--CODE-- --CODE--

View File

@ -2,6 +2,8 @@
010: type conversion BITCAST 010: type conversion BITCAST
--TARGET-- --TARGET--
x86 x86
--XFAIL--
64-bit integers are not implemented on 32-bit systems
--ARGS-- --ARGS--
-S -S
--CODE-- --CODE--

View File

@ -2,6 +2,8 @@
009: sub function 009: sub function
--TARGET-- --TARGET--
x86 x86
--XFAIL--
64-bit integers are not implemented on 32-bit systems
--ARGS-- --ARGS--
-S -S
--CODE-- --CODE--