diff --git a/tools/bisect/bisect_hang.py b/tools/bisect/bisect_hang.py index ad0497396c9..71e8d8313fc 100644 --- a/tools/bisect/bisect_hang.py +++ b/tools/bisect/bisect_hang.py @@ -4,6 +4,8 @@ from bisect_common import * +MAX_RT_FACTOR = 1.3 + # TODO: detect missing file def run(cppcheck_path, options, elapsed_time=None): timeout = None @@ -11,10 +13,10 @@ def run(cppcheck_path, options, elapsed_time=None): timeout = elapsed_time * 2 cmd = options.split() cmd.insert(0, cppcheck_path) - print('running {}'.format(cppcheck_path)) - with subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) as p: + print('running (timeout: {}) {}'.format(timeout, cppcheck_path)) + with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) as p: try: - p.communicate(timeout=timeout) + stdout, _ = p.communicate(timeout=timeout) if p.returncode != 0: print('error') return None @@ -22,8 +24,11 @@ def run(cppcheck_path, options, elapsed_time=None): except subprocess.TimeoutExpired: print('timeout') p.kill() - p.communicate() + stdout, _ = p.communicate() return False + finally: + stdout = stdout.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') + print(stdout) return True @@ -33,6 +38,10 @@ def run(cppcheck_path, options, elapsed_time=None): options = sys.argv[2] if '--error-exitcode=0' not in options: options += ' --error-exitcode=0' +if '--showtime=file' not in options: + options += ' --showtime=file-total' +if '-q' not in options: + options += ' -q' if len(sys.argv) >= 4: elapsed_time = float(sys.argv[3]) else: @@ -56,7 +65,7 @@ def run(cppcheck_path, options, elapsed_time=None): elapsed_time = time.perf_counter() - t print('elapsed_time: {}'.format(elapsed_time)) # TODO: write to stdout and redirect all all printing to stderr - sys.exit(round(elapsed_time + .5)) # return the time + sys.exit(max(round(elapsed_time - .5), 1)) # return the time t = time.perf_counter() run_res = run(cppcheck_path, options, elapsed_time) @@ -66,7 +75,7 @@ def run(cppcheck_path, options, elapsed_time=None): # TODO: handle error result print('elapsed_time: {}'.format(run_time)) # TODO: write to stdout and redirect all printing to stderr - sys.exit(round(run_time + .5)) # return the time + sys.exit(max(round(run_time - .5), 1)) # return the time if run_res is None: sys.exit(EC_SKIP) # error occurred @@ -75,5 +84,12 @@ def run(cppcheck_path, options, elapsed_time=None): sys.exit(EC_BAD if not invert else EC_GOOD) # timeout occurred print('run_time: {}'.format(run_time)) +run_time_factor = run_time / elapsed_time +print('run_time_factor: {}'.format(run_time_factor)) +run_time_diff = run_time - elapsed_time +print('run_time_diff: {}'.format(run_time_diff)) + +if run_time_factor >= MAX_RT_FACTOR: + sys.exit(EC_BAD if not invert else EC_GOOD) # factor exceeded sys.exit(EC_GOOD if not invert else EC_BAD) # no timeout