mirror of
https://github.com/danog/ir.git
synced 2025-01-22 05:31:32 +01:00
Adopt IR test engine for Windows (this requires php and diff installed)
This commit is contained in:
parent
e9a4b5efeb
commit
300665700f
76
ir-test.php
76
ir-test.php
@ -45,10 +45,15 @@ function run_test($build_dir, $test, $name, $code, $expect, $args) {
|
||||
if (!@file_put_contents($input, $code)) {
|
||||
return false;
|
||||
}
|
||||
@system("$build_dir/ir $input $args >$output 2>&1");
|
||||
// if (@system("$build_dir/ir $input $args 2>&1 >$output") != 0) {
|
||||
// return false;
|
||||
// }
|
||||
if (PHP_OS_FAMILY != "Windows") {
|
||||
$cmd = "$build_dir/ir $input $args >$output 2>&1";
|
||||
} else {
|
||||
$cmd = "$build_dir\\ir $input $args --no-abort-fault >$output 2>&1";
|
||||
}
|
||||
$ret = @system($cmd);
|
||||
if ($ret === false) {
|
||||
return false;
|
||||
}
|
||||
$out = @file_get_contents($output);
|
||||
if ($out === false) {
|
||||
return false;
|
||||
@ -59,7 +64,15 @@ function run_test($build_dir, $test, $name, $code, $expect, $args) {
|
||||
if (!@file_put_contents("$base.exp", "$expect\n")) {
|
||||
return false;
|
||||
}
|
||||
if (@system("diff -u $base.exp $output > $base.diff") != 0) {
|
||||
if (PHP_OS_FAMILY != "Windows") {
|
||||
$cmd = "diff -u $base.exp $output > $base.diff";
|
||||
} else {
|
||||
/* Diff somehow resets terminal and breaks "cooring".
|
||||
* "start" is added wspecially to prevent this
|
||||
*/
|
||||
$cmd = "start diff --strip-trailing-cr -u $base.exp $output > $base.diff 2>&1";
|
||||
}
|
||||
if (@system($cmd) != 0) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@ -93,10 +106,21 @@ function find_tests($dir) {
|
||||
}
|
||||
|
||||
function run_tests() {
|
||||
global $show_diff, $colorize;
|
||||
|
||||
$build_dir = getenv("BUILD_DIR") ?? ".";
|
||||
$src_dir = getenv("SRC_DIR") ?? ".";
|
||||
$skiped = 0;
|
||||
$target = @system("$build_dir/ir --target");
|
||||
if (PHP_OS_FAMILY != "Windows") {
|
||||
$cmd = "$build_dir/ir --target";
|
||||
} else {
|
||||
$cmd = "$build_dir\\ir --target";
|
||||
}
|
||||
$target = @system($cmd);
|
||||
if ($target === false) {
|
||||
echo "Cannot run '$cmd'\n";
|
||||
return 1;
|
||||
}
|
||||
$tests = find_tests("$src_dir/tests");
|
||||
$bad = array();
|
||||
$failed = array();
|
||||
@ -107,7 +131,11 @@ function run_tests() {
|
||||
$count++;
|
||||
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";
|
||||
if ($colorize) {
|
||||
echo "\r\e[1;33mSKIP\e[0m: $name [$test]\n";
|
||||
} else {
|
||||
echo "\rSKIP: $name [$test]\n";
|
||||
}
|
||||
$skiped++;
|
||||
continue;
|
||||
}
|
||||
@ -116,23 +144,38 @@ function run_tests() {
|
||||
echo $str;
|
||||
flush();
|
||||
$ret = run_test($build_dir, $test, $name, $code, $expect, $opt);
|
||||
echo str_repeat(" ", $len);
|
||||
echo str_repeat(" ", $len);
|
||||
if ($ret) {
|
||||
echo "\r\e[1;32mPASS\e[0m: $name [$test]\n";
|
||||
if ($colorize) {
|
||||
echo "\r\e[1;32mPASS\e[0m: $name [$test]\n";
|
||||
} else {
|
||||
echo "\rPASS: $name [$test]\n";
|
||||
}
|
||||
} else if (isset($xfail)) {
|
||||
echo "\r\e[1;31mXFAIL\e[0m: $name [$test] XFAIL REASON: $xfail\n";
|
||||
if ($colorize) {
|
||||
echo "\r\e[1;31mXFAIL\e[0m: $name [$test] XFAIL REASON: $xfail\n";
|
||||
} else {
|
||||
echo "\rXFAIL: $name [$test] XFAIL REASON: $xfail\n";
|
||||
}
|
||||
$xfailed[$test] = array($name, $xfail);
|
||||
} else {
|
||||
echo "\r\e[1;31mFAIL\e[0m: $name [$test]\n";
|
||||
if ($colorize) {
|
||||
echo "\r\e[1;31mFAIL\e[0m: $name [$test]\n";
|
||||
} else {
|
||||
echo "\rFAIL: $name [$test]\n";
|
||||
}
|
||||
$failed[$test] = $name;
|
||||
global $show_diff;
|
||||
if ($show_diff) {
|
||||
$base = substr($test, 0, -4);
|
||||
echo file_get_contents("$base.diff");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "\r\e[1;31mBROK\e[0m: $name [$test]\n";
|
||||
if ($colorize) {
|
||||
echo "\r\e[1;31mBROK\e[0m: $name [$test]\n";
|
||||
} else {
|
||||
echo "\rBROK: $name [$test]\n";
|
||||
}
|
||||
$bad[] = $test;
|
||||
}
|
||||
}
|
||||
@ -173,5 +216,12 @@ function run_tests() {
|
||||
return count($failed) > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
$colorize = true;
|
||||
if (function_exists('sapi_windows_vt100_support') && !sapi_windows_vt100_support(STDOUT, true)) {
|
||||
$colorize = false;
|
||||
}
|
||||
if (in_array('--no-color', $argv, true)) {
|
||||
$colorize = false;
|
||||
}
|
||||
$show_diff = in_array('--show-diff', $argv, true);
|
||||
exit(run_tests());
|
||||
|
11
ir_emit.c
11
ir_emit.c
@ -218,12 +218,21 @@ static void *ir_resolve_sym_name(const char *name)
|
||||
DWORD cbNeeded;
|
||||
uint32_t i = 0;
|
||||
|
||||
/* Quick workaraund to prevent *.irt tests failures */
|
||||
// TODO: try to find a general solution ???
|
||||
if (strcmp(name, "printf") == 0) {
|
||||
return (void*)printf;
|
||||
}
|
||||
|
||||
addr = NULL;
|
||||
|
||||
EnumProcessModules(GetCurrentProcess(), mods, sizeof(mods), &cbNeeded);
|
||||
|
||||
while(!addr && i < (cbNeeded / sizeof(HMODULE))) {
|
||||
while(i < (cbNeeded / sizeof(HMODULE))) {
|
||||
addr = GetProcAddress(mods[i], name);
|
||||
if (addr) {
|
||||
return addr;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
#endif
|
||||
|
19
ir_main.c
19
ir_main.c
@ -229,7 +229,9 @@ int main(int argc, char **argv)
|
||||
uint32_t mflags = 0;
|
||||
uint64_t debug_regset = 0xffffffffffffffff;
|
||||
bool dump_size = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
bool abort_fault = 1;
|
||||
#endif
|
||||
ir_consistency_check();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
@ -332,6 +334,10 @@ int main(int argc, char **argv)
|
||||
}
|
||||
debug_regset = strtoull(argv[i + 1], NULL, 0);
|
||||
i++;
|
||||
#ifdef _WIN32
|
||||
} else if (strcmp(argv[i], "--no-abort-fault") == 0) {
|
||||
abort_fault = 0;
|
||||
#endif
|
||||
} else if (argv[i][0] == '-') {
|
||||
fprintf(stderr, "ERROR: Unknown option '%s' (use --help)\n", argv[i]);
|
||||
return 1;
|
||||
@ -361,6 +367,12 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!abort_fault) {
|
||||
_set_abort_behavior(0, _WRITE_ABORT_MSG|_CALL_REPORTFAULT);
|
||||
}
|
||||
#endif
|
||||
|
||||
ir_loader_init();
|
||||
|
||||
ir_init(&ctx, 256, 1024);
|
||||
@ -411,6 +423,11 @@ int main(int argc, char **argv)
|
||||
if (entry) {
|
||||
if (dump_asm) {
|
||||
ir_disasm_add_symbol("test", (uintptr_t)entry, size);
|
||||
#ifdef _WIN32
|
||||
/* Quick workaraund to prevent *.irt tests failures */
|
||||
// TODO: try to find a general solution ???
|
||||
ir_disasm_add_symbol("printf", (uintptr_t)(void*)printf, sizeof(void*));
|
||||
#endif
|
||||
ir_disasm("test", entry, size, 0, &ctx, stderr);
|
||||
}
|
||||
if (dump_size) {
|
||||
|
6
ir_ra.c
6
ir_ra.c
@ -875,7 +875,11 @@ static int ir_block_cmp(void *data, const void *b1, const void *b2)
|
||||
if (d1 > d2) {
|
||||
return -1;
|
||||
} else if (d1 == d2) {
|
||||
return 0;
|
||||
if (ctx->cfg_blocks[*(ir_ref*)b1].start < ctx->cfg_blocks[*(ir_ref*)b2].start) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
@ -34,6 +34,10 @@ CC=cl.exe
|
||||
LD=link.exe
|
||||
!endif
|
||||
|
||||
!if "$(PHP)" == ""
|
||||
PHP=php.exe
|
||||
!endif
|
||||
|
||||
!if "$(TARGET)" == ""
|
||||
TARGET = $(VSCMD_ARG_TGT_ARCH)
|
||||
!endif
|
||||
@ -101,6 +105,9 @@ builddir:
|
||||
|
||||
test: $(BUILD_DIR)\ir.exe
|
||||
$(BUILD_DIR)\ir.exe $(SRC_DIR)\test.ir --dump --save $(BUILD_DIR)\test.log
|
||||
set BUILD_DIR=$(BUILD_DIR)
|
||||
set SRC_DIR=$(SRC_DIR)
|
||||
$(PHP) $(SRC_DIR)\ir-test.php
|
||||
|
||||
clean:
|
||||
del /f /q $(BUILD_DIR)\*.obj $(BUILD_DIR)\*.exe $(BUILD_DIR)\*.pdb $(BUILD_DIR)\*.ilk $(BUILD_DIR)\*.h
|
||||
|
Loading…
x
Reference in New Issue
Block a user