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.
Esse commit está contido em:
ptarjan
2013-04-15 20:32:43 -07:00
commit de Sara Golemon
commit 4c2b9a3bc2
5 arquivos alterados com 219 adições e 143 exclusões
+2 -2
Ver Arquivo
@@ -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`
+1
Ver Arquivo
@@ -11,6 +11,7 @@ Eval {
}
AllowHhas = true
EnableHipHopSyntax = true
EnableObjDestructCall = true
}
Sandbox {
+204 -133
Ver Arquivo
@@ -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
<?php
/**
* Run the test suites in various configurations.
*/
######################################################################
function usage() {
global $argv;
return " $argv[0] [-m jit|hhir|interp] [-r] <tests/directories>";
}
: ${FBMAKE_BIN_ROOT=$HPHP_HOME/_bin}
function help() {
global $argv;
$help = <<<EOT
DEFAULT_VERIFY_HHBC=$FBMAKE_BIN_ROOT/verify.hhbc
DEFAULT_HHVM=$FBMAKE_BIN_ROOT/hphp/hhvm/hhvm
DEFAULT_HPHP=$FBMAKE_BIN_ROOT/hphp/hhvm/hphp
# Examples
QTESTS_SKIP='autoload5.php condinfinite.php condinfinite2.php define_b.php
_fbcufa_init.php include_b.php include_c.php include_d.php
include2_a.php include2_b.php infinite.php ReqOnce_b.php include3_a.php
include_backtrace2.php backup_cycle_collector.php
redeclared_class1.php redeclared_class2.php'
Quick tests in JIT mode:
$argv[0]
VERIFY_SCRIPT=./test/verify
Quick tests in HHIR mode:
$argv[0] -m hhir
######################################################################
Slow tests in interp mode:
$argv[0] -m interp test/slow
if [ x"$HPHP_HOME" = x"" ] ; then
echo "HPHP_HOME must be set in your environment"
exit 1
fi
Slow closure tests in JIT mode:
$argv[0] test/slow/closure
: ${HHVM:=$DEFAULT_HHVM}
: ${HPHP:=$DEFAULT_HPHP}
: ${VERIFY_HHBC:=$DEFAULT_VERIFY_HHBC}
: ${VQ:=jit}
: ${REPO:=0}
: ${TEST_PATH:=test/quick}
Slow closure tests in JIT mode with RepoAuthoritative:
$argv[0] -r test/slow/closure
cd $HPHP_HOME/hphp
Zend tests with a "z" in their name:
$argv[0] test/zend/good/*/*z*.php
EOT;
return usage().$help;
}
if [ $# -ge 1 ]; then
TEST_PATH=$1;
fi
if [ $# -ge 2 ]; then
VQ=$2;
fi
if [ $# -ge 3 ]; then
REPO=$3;
fi
function error($message) {
echo "$message\n";
exit(1);
}
######################################################################
if (!isset($_ENV['HPHP_HOME'])) {
error("HPHP_HOME must be set in your environment");
}
skip_list=
for x in $QTESTS_SKIP ; do
skip_list="$skip_list $TEST_PATH/$x"
done
function idx($array, $key, $default = null) {
return isset($array[$key]) ? $array[$key] : $default;
}
qtests=$(comm -23 \
<(find $TEST_PATH -name \*.php -o -name \*.hhas | sort) \
<(echo $skip_list|sed -e 's/ /\n/g'|sort))
function idx_file($array, $key, $default = null) {
return is_file(idx($array, $key)) ? realpath($array[$key]) : $default;
}
repo_args="-v Repo.Local.Mode=-- -v Repo.Central.Path=$VERIFY_HHBC"
interp_args="$repo_args -v Eval.Jit=false"
jit_args="$repo_args -v Eval.Jit=true -v Eval.JitEnableRenameFunction=true"
hhir_args="$jit_args -v Eval.JitUseIR=true -v Eval.HHIRDisableTx64=true"
function bin_root() {
return idx($_ENV, 'FBMAKE_BIN_ROOT', $_ENV['HPHP_HOME'].'/_bin');
}
######################################################################
function get_options($argv) {
$parameters = array(
'r' => '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);
+6 -6
Ver Arquivo
@@ -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())
+6 -2
Ver Arquivo
@@ -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]);