From 2cf381081ae0b7c3fa80814bebd626cb678ca766 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 12 Jul 2014 16:34:51 +0300 Subject: run-tests: Add option to write CPython's test results to .exp files. Mostly to run testsuite on targets which doesn't have CPython. --- tests/run-tests | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/run-tests b/tests/run-tests index c6bc4020d..71a94f946 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -20,7 +20,7 @@ def rm_f(fname): if os.path.exists(fname): os.remove(fname) -def run_tests(pyb, tests): +def run_tests(pyb, tests, args): test_count = 0 testcase_count = 0 passed_count = 0 @@ -54,9 +54,15 @@ def run_tests(pyb, tests): # run CPython to work out expected output try: output_expected = subprocess.check_output([CPYTHON3, '-B', test_file]) + if args.write_exp: + with open(test_file_expected, 'wb') as f: + f.write(output_expected) except subprocess.CalledProcessError: output_expected = b'CPYTHON3 CRASH' + if args.write_exp: + continue + # run Micro Python if pyb is None: # run on PC @@ -113,6 +119,7 @@ def main(): cmd_parser = argparse.ArgumentParser(description='Run tests for Micro Python.') cmd_parser.add_argument('--pyboard', action='store_true', help='run the tests on the pyboard') cmd_parser.add_argument('-d', '--test-dirs', nargs='*', help='input test directories (if no files given)') + cmd_parser.add_argument('--write-exp', action='store_true', help='save .exp files to run tests w/o CPython') cmd_parser.add_argument('files', nargs='*', help='input test files') args = cmd_parser.parse_args() @@ -139,7 +146,7 @@ def main(): # tests explicitly given tests = args.files - if not run_tests(pyb, tests): + if not run_tests(pyb, tests, args): sys.exit(1) if __name__ == "__main__": -- cgit v1.2.3 From a1760a56ff2a9be9506e96f4cd17459bf2916b30 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 13 Jul 2014 18:49:56 +0300 Subject: test: Add run-tests-exp.sh, script to run testsuite with only sh dependency. This script uses expected test results as generated by run-tests --write-exp, and requires only standard unix shell funtionality (no bash). It is useful to run testsuite on embedded systems, where there's no CPython and Bash. --- tests/run-tests-exp.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 tests/run-tests-exp.sh (limited to 'tests') diff --git a/tests/run-tests-exp.sh b/tests/run-tests-exp.sh new file mode 100755 index 000000000..032c42dd3 --- /dev/null +++ b/tests/run-tests-exp.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# +# This is plain shell variant of run-tests script, which uses .exp files +# as generated by run-tests --write-exp. It is useful to run testsuite +# on embedded systems which doesn't have CPython3. +# + +RM="rm -f" +MP_PY=micropython + +numtests=0 +numtestcases=0 +numpassed=0 +numfailed=0 +namefailed= + +if [ $# -eq 0 ] +then + tests="basics/*.py micropython/*.py float/*.py import/*.py io/*.py misc/*.py" +else + tests="$@" +fi + +for infile in $tests +do + basename=`basename $infile .py` + outfile=${basename}.out + expfile=$infile.exp + + $MP_PY $infile > $outfile + numtestcases=$(expr $numtestcases + $(cat $expfile | wc -l)) + + diff --brief $expfile $outfile > /dev/null + + if [ $? -eq 0 ] + then + echo "pass $infile" + $RM $outfile + numpassed=$(expr $numpassed + 1) + else + echo "FAIL $infile" + numfailed=$(expr $numfailed + 1) + namefailed="$namefailed $basename" + fi + + numtests=$(expr $numtests + 1) +done + +echo "$numtests tests performed ($numtestcases individual testcases)" +echo "$numpassed tests passed" +if [ $numfailed != 0 ] +then + echo "$numfailed tests failed -$namefailed" + exit 1 +else + exit 0 +fi -- cgit v1.2.3