feat(tests): 添加编译器路径配置选项支持

- 添加 --no-aot 参数以支持非AOT编译模式运行测试
- 添加 --compiler 参数用于指定编译器二进制文件路径
- 设置默认编译器路径为 ./bin/compiler.php
- 支持通过 --compiler 指定自定义编译器如 swoole_compiler
- 修改系统调用以使用配置的编译器路径替代硬编码路径
- 更新全局变量声明以包含新的编译器路径参数
pull/1/head
韩天峰 4 months ago
parent 67f477d705
commit d387667f1e
  1. 19
      run-tests.php

@ -128,6 +128,12 @@ Options:
Run the tests multiple times in the same process and check the Run the tests multiple times in the same process and check the
output of the last execution (CLI SAPI only). output of the last execution (CLI SAPI only).
--no-aot Run tests without AOT compilation (plain PHP mode).
--compiler <path>
Use specified compiler binary (default: ./bin/compiler.php).
For bootstrap testing, use: --compiler ./swoole_compiler
--bless Bless failed tests using scripts/dev/bless_tests.php. --bless Bless failed tests using scripts/dev/bless_tests.php.
HELP; HELP;
@ -149,7 +155,7 @@ function main(): void
$end_time, $environment, $end_time, $environment,
$exts_skipped, $exts_tested, $exts_to_test, $failed_tests_file, $exts_skipped, $exts_tested, $exts_to_test, $failed_tests_file,
$ignored_by_ext, $ini_overwrites, $colorize, $ignored_by_ext, $ini_overwrites, $colorize,
$log_format, $no_clean, $no_aot, $no_file_cache, $log_format, $no_clean, $no_aot, $compiler_path, $no_file_cache,
$pass_options, $php, $php_cgi, $preload, $pass_options, $php, $php_cgi, $preload,
$result_tests_file, $slow_min_ms, $start_time, $result_tests_file, $slow_min_ms, $start_time,
$temp_source, $temp_target, $test_cnt, $temp_source, $temp_target, $test_cnt,
@ -494,6 +500,9 @@ function main(): void
case '--no-aot': case '--no-aot':
$no_aot = true; $no_aot = true;
break; break;
case '--compiler':
$compiler_path = $argv[++$i];
break;
case '--color': case '--color':
$colorize = true; $colorize = true;
break; break;
@ -665,6 +674,9 @@ function main(): void
if (!$php) { if (!$php) {
$php = getenv('TEST_PHP_EXECUTABLE') ?: PHP_BINARY; $php = getenv('TEST_PHP_EXECUTABLE') ?: PHP_BINARY;
} }
if (!$compiler_path) {
$compiler_path = './bin/compiler.php';
}
$php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE') ?: get_binary($php, 'php-cgi', 'sapi/cgi/php-cgi'); $php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE') ?: get_binary($php, 'php-cgi', 'sapi/cgi/php-cgi');
$phpdbg = getenv('TEST_PHPDBG_EXECUTABLE') ?: get_binary($php, 'phpdbg', 'sapi/phpdbg/phpdbg'); $phpdbg = getenv('TEST_PHPDBG_EXECUTABLE') ?: get_binary($php, 'phpdbg', 'sapi/phpdbg/phpdbg');
@ -1811,6 +1823,7 @@ function run_test(string $php, $file, array $env): string
global $slow_min_ms; global $slow_min_ms;
global $preload, $file_cache; global $preload, $file_cache;
global $num_repeats; global $num_repeats;
global $compiler_path;
// Parallel testing // Parallel testing
global $workerID; global $workerID;
global $show_progress; global $show_progress;
@ -4201,6 +4214,8 @@ function debug()
function compile_php_file(string $file): string function compile_php_file(string $file): string
{ {
global $compiler_path;
$data = trim(file_get_contents($file)); $data = trim(file_get_contents($file));
if (!str_starts_with($data, '<?php') or !str_ends_with($data, '?>')) { if (!str_starts_with($data, '<?php') or !str_ends_with($data, '?>')) {
throw new Exception('Invalid PHP file'); throw new Exception('Invalid PHP file');
@ -4208,7 +4223,7 @@ function compile_php_file(string $file): string
if (!str_contains($data, 'function main()')) { if (!str_contains($data, 'function main()')) {
file_put_contents($file, "<?php\nfunction main() {\n" . substr($data, 5, -2) . "\n}\n"); file_put_contents($file, "<?php\nfunction main() {\n" . substr($data, 5, -2) . "\n}\n");
} }
system('./bin/compiler.php ' . $file); system($compiler_path . ' ' . $file);
$binary_file = str_replace('-', '_', basename($file, '.php')); $binary_file = str_replace('-', '_', basename($file, '.php'));
if (!file_exists($binary_file)) { if (!file_exists($binary_file)) {
throw new Exception('Compilation failed'); throw new Exception('Compilation failed');

Loading…
Cancel
Save