From 4c2b9a3bc2f7bdb61361283621423187746f623d Mon Sep 17 00:00:00 2001 From: ptarjan Date: Mon, 15 Apr 2013 20:32:43 -0700 Subject: [PATCH] rewrite test running in php It turned out to be more lines but feels a bit more maintainable. Thoughts? I personally would like python more here but I think @kma likes php for scripting. --- hphp/test/README.md | 4 +- hphp/test/config.hdf | 1 + hphp/test/run | 337 ++++++++++++++++++++-------------- hphp/tools/run_test.py | 12 +- hphp/tools/verify_to_json.php | 8 +- 5 files changed, 219 insertions(+), 143 deletions(-) diff --git a/hphp/test/README.md b/hphp/test/README.md index ffca9c89d..a600e40f8 100644 --- a/hphp/test/README.md +++ b/hphp/test/README.md @@ -16,10 +16,10 @@ all sub-suites. `test/run test/quick` * Zend tests just with the interpreter in RepoAuthoritative mode - -`test/run test/zend/good interp 1` +`test/run test/zend/good -m interp -r` * Slow tests with the JIT in IR mode - -`test/run test/slow hhir` +`test/run test/slow -m hhir` * Run evertyhing that is supposed to pass - `fbmake runtests` diff --git a/hphp/test/config.hdf b/hphp/test/config.hdf index dacc4b9a6..38625f974 100644 --- a/hphp/test/config.hdf +++ b/hphp/test/config.hdf @@ -11,6 +11,7 @@ Eval { } AllowHhas = true EnableHipHopSyntax = true + EnableObjDestructCall = true } Sandbox { diff --git a/hphp/test/run b/hphp/test/run index 561f89e4e..d17f4af7f 100755 --- a/hphp/test/run +++ b/hphp/test/run @@ -1,154 +1,225 @@ -#!/bin/bash -# -# Run the test suites in various configurations. -# -# The first param is the directory or file to run. -# The second param is jit, hhir, or interp. -# The third param is a boolean if we should use repo mode or not. -# -# Server mode flags: (semi-functional--tests with warnings fail) -# -# MODE="server" -- run in server mode -# PORT -- port to use in server mode (default 8080) -# TEST_HOME -- the --home arg for server mode -# -# Other flags: -# -# VERIFY_EXTRA_ARGS -- extra args to pass to verify -# VERIFY_EXTRA_CMD_ARGS -- extra args to pass to hhvm -# -# For use in the Makefile -# -# HHVM -- path to the hhvm binary to use -# VERIFY_HHBC -- path to use for the an hhbc repo -# +#!/bin/env php +"; +} -: ${FBMAKE_BIN_ROOT=$HPHP_HOME/_bin} +function help() { + global $argv; + $help = << 'repo', + 'm:' => 'mode:', + '' => 'server', + 'h' => 'help', + ); + $options = array(); + $files = array(); + for ($i = 1; $i < count($argv); $i++) { + $arg = $argv[$i]; + $found = false; + if ($arg && $arg[0] == '-') { + foreach ($parameters as $short => $long) { + if ($arg == '-'.str_replace(':', '', $short) || + $arg == '--'.str_replace(':', '', $long)) { + if (substr($long, -1, 1) == ':') { + $value = $argv[++$i]; + } else { + $value = true; + } + $options[str_replace(':', '', $long)] = $value; + $found = true; + break; + } + } + } + if (!$found && $arg) { + $files[] = $arg; + } + } + return array($options, $files); +} -# Find a config.hdf in the test dir or a parents -# inspired by http://unix.stackexchange.com/questions/13464/ +function find_tests($files) { + if (!$files) { + $files = array($_ENV['HPHP_HOME'].'/hphp/test/quick'); + } + foreach ($files as &$file) { + if (!stat($file)) { + if ($file == 'jit' || $file == 'hhir' || $file == 'interp') { + error( + "I'm really sorry to change this, but now the mode is ". + "passed with '-m $file', and repo mode is turned on with '-r'" + ); + } + error("Not valid file or directory: '$file'"); + } + $file = preg_replace(',//+,', '/', realpath($file)); + $file = preg_replace(',^'.getcwd().'/,', '', $file); + } + $files = implode(' ', $files); + $tests = explode("\n", shell_exec("find $files -name *.php -o -name *.hhas")); + if (!$tests) { + error(usage()); + } + asort($tests); + return array_filter($tests); +} -if [ -f $TEST_PATH ]; then - cur_dir=`dirname $TEST_PATH`; -else - cur_dir="$TEST_PATH/" -fi -slashes=${cur_dir//[^\/]/} -config="test/config.hdf" -for (( n=${#slashes}; n>0; --n )); do - if [ -f "$cur_dir/config.hdf" ]; then - config="$cur_dir/config.hdf" - break - fi - cur_dir="$cur_dir/.." -done -cmd="$HHVM --config $config" +function find_config($tests, $name) { + $dirs = array_map('dirname', $tests); + $configs = array_map(function($test) use ($name) { + return find_config_for_dir($test, $name); + }, $tests); + $configs = array_unique($configs); + if (!count($configs) == 1) { + error( + "These tests would use many different configs and we only support ". + "using one for all the tests. Need these configs: ". + implode(' ', $configs)."" + ); + } + return array_values($configs)[0]; +} -if [ -f $TEST_PATH ]; then - cur_dir=`dirname $TEST_PATH`; -else - cur_dir="$TEST_PATH/" -fi -slashes=${cur_dir//[^\/]/} -config="test/hphp_config.hdf" -for (( n=${#slashes}; n>0; --n )); do - if [ -f "$cur_dir/hphp_config.hdf" ]; then - config="$cur_dir/hphp_config.hdf" - break - fi - cur_dir="$cur_dir/.." -done -HPHP_ARGS="--config $config" +function find_config_for_dir($dir, $name) { + while ($dir && stat($dir)) { + $config = "$dir/$name"; + if (is_file($config)) { + return $config; + } + $dir = substr($dir, 0, strrpos($dir, '/')); + } + return $name; +} -if [ x"$MODE" = x"server" ] ; then - : ${PORT:=8080} - : ${TEST_HOME:=.} - cmd="$cmd -m server -v Server.SourceRoot=%s -p %s" - verify_args="--server --port $PORT --home $TEST_HOME" -else - cmd="$cmd --file %3\$s" -fi -verify_args="$verify_args --hhvm $HHVM" -if [ "$REPO" -a "$REPO" != "0" ]; then - verify_args="$verify_args --repo 1" -else - verify_args="$verify_args --repo 0" -fi -cmd="$cmd -v Eval.EnableObjDestructCall=true" +function is_server($options) { + return idx($options, 'server'); +} -case $VQ in - jit) - cmd="$cmd $jit_args" - ;; - hhir) - cmd="$cmd $hhir_args" - ;; - interp) - cmd="$cmd $interp_args" - ;; - *) - echo "Unknown VQ '$VQ'. Choose either jit, hhir or interp" - exit 1 - ;; -esac +function file_arg($options) { + if (is_server($options)) { + return '-m server -v Server.SourceRoot=%s -p %s'; + } else { + return '--file %3\$s'; + } +} -exec $VERIFY_SCRIPT --command="$cmd $VERIFY_EXTRA_CMD_ARGS" $verify_args \ - $VERIFY_EXTRA_ARGS --hphp="$HPHP $HPHP_ARGS" $qtests +function mode_arg($options) { + $verify_hhbc = idx_file($_ENV, 'VERIFY_HHBC', bin_root().'/verify.hhbc'); + $repo_args = "-v Repo.Local.Mode=-- -v Repo.Central.Path=$verify_hhbc"; + $jit_args = "$repo_args -v Eval.Jit=true -v Eval.JitEnableRenameFunction=true"; + $mode = idx($options, 'mode'); + switch ($mode) { + case '': + case 'jit': + return $jit_args; + case 'hhir': + return "$jit_args -v Eval.JitUseIR=true -v Eval.HHIRDisableTx64=true"; + case 'interp': + return "$repo_args -v Eval.Jit=false"; + default: + error("-m must be one of hhir | jit | interp. Got: '$mode'"); + } +} + +function command_arg($options, $tests) { + return array( + idx_file($_ENV, 'HHVM', bin_root().'/hphp/hhvm/hhvm'), + '--config', + find_config($tests, 'config.hdf'), + file_arg($options), + mode_arg($options), + ); +} + +function hphp_arg($options, $tests) { + return array( + idx_file($_ENV, 'HPHP', bin_root().'/hphp/hhvm/hphp'), + '--config', + find_config($tests, 'hphp_config.hdf'), + ); +} + +function verify_args($options) { + $args = array(); + if (is_server($options)) { + $args[] = '--server --port 8080 --home .'; + } + $args[] = "--hhvm"; + $args[] = idx_file($_ENV, 'HHVM',bin_root().'/hphp/hhvm/hhvm'); + if (isset($options['repo'])) { + $args[] = '--repo 1'; + } else { + $args[] = '--repo 0'; + } + return $args; +} + +list($options, $files) = get_options($argv); +if (isset($options['help'])) { + error(help()); +} +$tests = find_tests($files); + +$verify = array( + $_ENV['HPHP_HOME'].'/hphp/test/verify', + '--command="'.implode(' ', command_arg($options, $tests)).'"', + implode(' ', verify_args($options)), + '--hphp="'.implode(' ', hphp_arg($options, $tests)).'"', + implode(' ', $tests), +); + +passthru(implode(' ', $verify), $return_status); +exit($return_status); diff --git a/hphp/tools/run_test.py b/hphp/tools/run_test.py index 6f425e0f2..dd731d234 100755 --- a/hphp/tools/run_test.py +++ b/hphp/tools/run_test.py @@ -43,7 +43,7 @@ def main(): repo = '' if arg.startswith('Repo'): arg = arg.replace('Repo', '') - repo = '1' + repo = '-r' for mode, vq in modes.items(): if arg.startswith(mode): @@ -57,19 +57,19 @@ def main(): raise Exception('Extra? "%s"' % arg) path = 'test/' + dir + subpath - cmd = ['test/run', path, vq, repo] + cmd = ['test/run', path, '-m', vq, repo] print ' '.join(cmd) - subprocess.call(cmd) - return + return subprocess.call(cmd) raise Exception('Unknown mode "%s"' % arg) os.chdir(home + '/hphp') cmd = sys.argv cmd[0] = root + '/hphp/test/test' - subprocess.call(cmd) + return subprocess.call(cmd) def camel_to_slash(name): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1/\2', name) return re.sub('([a-z0-9])([A-Z])', r'\1/\2', s1).lower() -main() + +sys.exit(main()) diff --git a/hphp/tools/verify_to_json.php b/hphp/tools/verify_to_json.php index df77fb3eb..cf2d47999 100755 --- a/hphp/tools/verify_to_json.php +++ b/hphp/tools/verify_to_json.php @@ -12,9 +12,13 @@ if (count($argv) != 6) { exit(1); } -$cmd = "FBMAKE_BIN_ROOT=$HPHP_HOME/$argv[5] " . - "$HPHP_HOME/hphp/tools/$argv[1] $argv[2] $argv[3] $argv[4]"; +$repo = ''; +if ($argv[4]) { + $repo = '-r'; +} +$cmd = "FBMAKE_BIN_ROOT=$HPHP_HOME/$argv[5] " . + "$argv[1] $argv[2] -m $argv[3] $repo"; loop_tests($cmd, function ($line) { if (preg_match('/^(test[^\s]*).*/', $line, &$m)) { start($m[1]);