From a5926e5177b9afa6d642d5d46e1493dc2ac8e3cd Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 20 Jun 2013 03:20:02 +0000 Subject: [PATCH] improve run_tests.py robustness as well as support cleaning of test directory after each full run-through of the tests --- .regression.yml | 3 +++ tools/parse_test_results.py | 2 +- tools/run_tests.py | 28 +++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.regression.yml b/.regression.yml index 2433a02a6..18cad6a21 100644 --- a/.regression.yml +++ b/.regression.yml @@ -5,6 +5,9 @@ project: libtorrent branch: trunk +clean: + - test_tmp_* + time_limit: 500 features: diff --git a/tools/parse_test_results.py b/tools/parse_test_results.py index 3f44e33bf..4a109c7da 100755 --- a/tools/parse_test_results.py +++ b/tools/parse_test_results.py @@ -137,7 +137,7 @@ def parse_tests(rev_dir): j = json.loads(open(f, 'rb').read()) timestamp = os.stat(f).st_mtime except: - print 'FAILED TO LOAD "%s"' %f + print '\nFAILED TO LOAD "%s"\n' %f continue platform = platform_toolset[0] diff --git a/tools/run_tests.py b/tools/run_tests.py index 60519ea88..387709b93 100755 --- a/tools/run_tests.py +++ b/tools/run_tests.py @@ -183,7 +183,7 @@ def main(argv): try: cfg = open('.regression.yml', 'r') except: - print '.regressions.yml not found in current directory' + print '.regression.yml not found in current directory' sys.exit(1) cfg = yaml.load(cfg.read()) @@ -196,7 +196,7 @@ def main(argv): for d in cfg['test_dirs']: test_dirs.append(d) else: - print 'no test directory specified by .regressions.yml' + print 'no test directory specified by .regression.yml' sys.exit(1) configs = [] @@ -206,6 +206,10 @@ def main(argv): else: configs = [['']] + clean_files = [] + if 'clean' in cfg: + clean_files = cfg['clean'] + branch_name = 'trunk' if 'branch' in cfg: branch_name = cfg['branch'] @@ -272,9 +276,27 @@ def main(argv): print '' # each file contains a full set of tests for one speific toolset and platform - f = open(os.path.join(rev_dir, build_platform + '#' + toolset + '.json'), 'w+') + try: + f = open(os.path.join(rev_dir, build_platform + '#' + toolset + '.json'), 'w+') + except IOError: + rev_dir = os.path.join(current_dir, 'regression_tests') + try: os.mkdir(rev_dir) + except: pass + rev_dir = os.path.join(rev_dir, '%s-%d' % (branch_name, revision)) + try: os.mkdir(rev_dir) + except: pass + f = open(os.path.join(rev_dir, build_platform + '#' + toolset + '.json'), 'w+') + print >>f, json.dumps(results) f.close() + + if len(clean_files) > 0: + for filt in clean_files: + for f in glob.glob(filt): + # a precautio to make sure a malicious repo + # won't clean things outside of the test directory + if not os.path.abspath(f).startswith(test_dir): continue + os.rmdirs(f) finally: # always restore current directory os.chdir(current_dir)