From a9318f72c950ee4248afa3b35bef984c3fd52da8 Mon Sep 17 00:00:00 2001 From: DrChat Date: Wed, 20 Dec 2017 14:36:10 -0600 Subject: [PATCH] Validate trace executable before starting thread pool --- tools/xenosci/local_runner.py | 40 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/tools/xenosci/local_runner.py b/tools/xenosci/local_runner.py index 508f7cdf0..9f146a21d 100644 --- a/tools/xenosci/local_runner.py +++ b/tools/xenosci/local_runner.py @@ -27,19 +27,17 @@ def file_type(value): def run_dumper(exe_path, input_name): - try: - start_time = time.perf_counter() + start_time = time.perf_counter() - p = subprocess.Popen([ - exe_path, - input_name, - '--log_file=stdout', - ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - p.wait() - elapsed_time = time.perf_counter() - start_time - print("%.3f seconds, code %2d (%s)" % (elapsed_time, p.returncode, input_name)) - except OSError: - print("exe is invalid :(") + p = subprocess.Popen([ + exe_path, + input_name, + '--log_file=stdout', + ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p.wait() + elapsed_time = time.perf_counter() - start_time + print("%.3f seconds, code %2d (%s)" % + (elapsed_time, p.returncode, input_name)) def main(argv): @@ -60,6 +58,24 @@ def main(argv): print("No input files found!") return 1 + # Test the executable first. + valid = False + try: + p = subprocess.Popen([ + exepath, + '--log_file=stdout', + ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p.wait() + if p.returncode == 5: + # code 5 = invalid trace file / trace file unspecified + valid = True + except OSError: + pass + + if not valid: + print("Trace executable invalid!") + return 1 + print("Processing...") pool = Pool(args.j)