From c6aeb417fa068d22364155c5a22a2ac3df903b0a Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 22 Nov 2022 10:43:29 +0300 Subject: [PATCH] Extend test suite to support XFAIL section --- ir-test.php | 77 +++++++++++++++----------------- tests/debug.x86/tailcall_001.irt | 2 + tests/debug.x86/tailcall_002.irt | 2 + tests/x86/add_009.irt | 2 + tests/x86/conv_001.irt | 2 + tests/x86/conv_002.irt | 2 + tests/x86/conv_004.irt | 2 + tests/x86/conv_010.irt | 2 + tests/x86/sub_009.irt | 2 + 9 files changed, 52 insertions(+), 41 deletions(-) diff --git a/ir-test.php b/ir-test.php index e0918f8..29527b8 100644 --- a/ir-test.php +++ b/ir-test.php @@ -6,51 +6,31 @@ * Authors: Dmitry Stogov */ -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); - if (!$text) { + if (!$text || !preg_match_all("/^--[A-Z]+--$/m", $text, $r, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) { return false; } - $p1 = strpos($text, '--TEST--'); - $p_args = strpos($text, '--ARGS--'); - $p_target = strpos($text, '--TARGET--'); - $p3 = strpos($text, '--CODE--'); - $p4 = strpos($text, '--EXPECT--'); - if ($p1 === false || $p3 === false || $p4 === false || $p1 > $p3 || $p3 > $p4) { + foreach($r as $sect) { + if (isset($sect_name)) { + $sections[$sect_name] = trim(substr($text, $sect_offset, $sect[0][1] - $sect_offset)); + } + $sect_name = $sect[0][0]; + $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; } - $code = trim(substr($text, $p3 + strlen('--CODE--'), $p4 - $p3 - strlen('--CODE--'))); - $expect = trim(substr($text, $p4 + strlen('--EXPECT--'))); - $expect = str_replace("\r", "", $expect); - - $end_name = $p3; - $args = "--save"; - $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--'))); - + $name = $sections['--TEST--']; + $code = $sections['--CODE--']; + $expect = $sections['--EXPECT--']; + $args = isset($sections['--ARGS--']) ? $sections['--ARGS--'] : "--save"; + $target = isset($sections['--TARGET--']) ? $sections['--TARGET--'] : null; + $xfail = isset($sections['--XFAIL--']) ? $sections['--XFAIL--'] : null; return true; } @@ -120,11 +100,12 @@ function run_tests() { $tests = find_tests("$src_dir/tests"); $bad = array(); $failed = array(); + $xfailed = array(); $total = count($tests); $count = 0; foreach($tests as $test) { $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) { echo "\r\e[1;33mSKIP\e[0m: $name [$test]\n"; $skiped++; @@ -138,6 +119,9 @@ function run_tests() { echo str_repeat(" ", $len); if ($ret) { 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 { echo "\r\e[1;31mFAIL\e[0m: $name [$test]\n"; $failed[$test] = $name; @@ -165,9 +149,20 @@ function run_tests() { } echo "Total: " . count($tests) . "\n"; echo "Passed: " . (count($tests) - count($failed) - $skiped) . "\n"; + echo "Expected fail: " . count($xfailed) . "\n"; echo "Failed: " . count($failed) . "\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) { + echo "-------------------------------\n"; + echo "FAILED TESTS\n"; echo "-------------------------------\n"; foreach ($failed as $test => $name) { echo "$name [$test]\n"; diff --git a/tests/debug.x86/tailcall_001.irt b/tests/debug.x86/tailcall_001.irt index bedc0b0..d6ef5dd 100644 --- a/tests/debug.x86/tailcall_001.irt +++ b/tests/debug.x86/tailcall_001.irt @@ -2,6 +2,8 @@ Simple CALL --TARGET-- x86 +--XFAIL-- +TAILCALL for functions with stack argumnts is not implemented --ARGS-- -S --run --CODE-- diff --git a/tests/debug.x86/tailcall_002.irt b/tests/debug.x86/tailcall_002.irt index 2b4df85..386b323 100644 --- a/tests/debug.x86/tailcall_002.irt +++ b/tests/debug.x86/tailcall_002.irt @@ -2,6 +2,8 @@ Indirect Tail CALL --TARGET-- x86 +--XFAIL-- +TAILCALL for functions with stack argumnts is not implemented --ARGS-- -S --CODE-- diff --git a/tests/x86/add_009.irt b/tests/x86/add_009.irt index 828d26d..fadf81a 100644 --- a/tests/x86/add_009.irt +++ b/tests/x86/add_009.irt @@ -2,6 +2,8 @@ 009: add function --TARGET-- x86 +--XFAIL-- +64-bit integers are not implemented on 32-bit systems --ARGS-- -S --CODE-- diff --git a/tests/x86/conv_001.irt b/tests/x86/conv_001.irt index 34416ab..f2b828c 100644 --- a/tests/x86/conv_001.irt +++ b/tests/x86/conv_001.irt @@ -2,6 +2,8 @@ 001: type conversion SEXT --TARGET-- x86 +--XFAIL-- +64-bit integers are not implemented on 32-bit systems --ARGS-- -S --CODE-- diff --git a/tests/x86/conv_002.irt b/tests/x86/conv_002.irt index 3191a9f..4b13eb0 100644 --- a/tests/x86/conv_002.irt +++ b/tests/x86/conv_002.irt @@ -2,6 +2,8 @@ 002: type conversion ZEXT --TARGET-- x86 +--XFAIL-- +64-bit integers are not implemented on 32-bit systems --ARGS-- -S --CODE-- diff --git a/tests/x86/conv_004.irt b/tests/x86/conv_004.irt index 1796947..76c13e7 100644 --- a/tests/x86/conv_004.irt +++ b/tests/x86/conv_004.irt @@ -2,6 +2,8 @@ 004: type conversion BITCAST --TARGET-- x86 +--XFAIL-- +64-bit integers are not implemented on 32-bit systems --ARGS-- -S --CODE-- diff --git a/tests/x86/conv_010.irt b/tests/x86/conv_010.irt index 8cc1608..6cdf1e8 100644 --- a/tests/x86/conv_010.irt +++ b/tests/x86/conv_010.irt @@ -2,6 +2,8 @@ 010: type conversion BITCAST --TARGET-- x86 +--XFAIL-- +64-bit integers are not implemented on 32-bit systems --ARGS-- -S --CODE-- diff --git a/tests/x86/sub_009.irt b/tests/x86/sub_009.irt index 94aa998..ecd6c79 100644 --- a/tests/x86/sub_009.irt +++ b/tests/x86/sub_009.irt @@ -2,6 +2,8 @@ 009: sub function --TARGET-- x86 +--XFAIL-- +64-bit integers are not implemented on 32-bit systems --ARGS-- -S --CODE--