Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions tools/bisect/bisect_hang.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@

from bisect_common import *

MAX_RT_FACTOR = 1.3

# TODO: detect missing file
def run(cppcheck_path, options, elapsed_time=None):
timeout = None
if elapsed_time:
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
print('done')
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

Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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