From 5aada6f54a14f3a395979691b30b036b6ab244c3 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 17 Jan 2025 02:40:05 -0600 Subject: [PATCH] test.py/bench.py: Limited -d/--disk and -t/--trace to one thread It doesn't really make sense to write to disk/trace files with multiple threads, the result usually ends up clobbered and useless. If we only pass disk/trace files to the first thread, the result is at at least useable, even if it only represents 1/j tests. This is actually quite a nice way to sample filesystem images in multithreaded tests. As a side effect, this also changes test.py/bench.py to no longer pass -d/--disk or -t/--trace to runner queries, which is probably a good thing? These should be ignored in queries anyways. --- scripts/bench.py | 56 ++++++++++++++++++++++++++---------------------- scripts/test.py | 56 ++++++++++++++++++++++++++---------------------- 2 files changed, 60 insertions(+), 52 deletions(-) diff --git a/scripts/bench.py b/scripts/bench.py index 15c0e2b7..3f491e66 100755 --- a/scripts/bench.py +++ b/scripts/bench.py @@ -649,7 +649,7 @@ def compile(bench_paths, **args): f.writeln() -def find_runner(runner, id=None, **args): +def find_runner(runner, id=None, main=True, **args): cmd = runner.copy() # run under some external command? @@ -683,22 +683,26 @@ def find_runner(runner, id=None, **args): cmd.append('--define-depth=%s' % args['define_depth']) if args.get('all'): cmd.append('-a') - if args.get('disk'): - cmd.append('-d%s' % args['disk']) - if args.get('trace'): - cmd.append('-t%s' % args['trace']) - if args.get('trace_backtrace'): - cmd.append('--trace-backtrace') - if args.get('trace_period'): - cmd.append('--trace-period=%s' % args['trace_period']) - if args.get('trace_freq'): - cmd.append('--trace-freq=%s' % args['trace_freq']) - if args.get('read_sleep'): - cmd.append('--read-sleep=%s' % args['read_sleep']) - if args.get('prog_sleep'): - cmd.append('--prog-sleep=%s' % args['prog_sleep']) - if args.get('erase_sleep'): - cmd.append('--erase-sleep=%s' % args['erase_sleep']) + + # only one thread should write to disk/trace, otherwise the output + # ends up clobbered and useless + if main: + if args.get('disk'): + cmd.append('-d%s' % args['disk']) + if args.get('trace'): + cmd.append('-t%s' % args['trace']) + if args.get('trace_backtrace'): + cmd.append('--trace-backtrace') + if args.get('trace_period'): + cmd.append('--trace-period=%s' % args['trace_period']) + if args.get('trace_freq'): + cmd.append('--trace-freq=%s' % args['trace_freq']) + if args.get('read_sleep'): + cmd.append('--read-sleep=%s' % args['read_sleep']) + if args.get('prog_sleep'): + cmd.append('--prog-sleep=%s' % args['prog_sleep']) + if args.get('erase_sleep'): + cmd.append('--erase-sleep=%s' % args['erase_sleep']) # defines? if args.get('define') and id is None: @@ -716,7 +720,7 @@ def find_runner(runner, id=None, **args): return cmd def find_perms(runner, bench_ids=[], **args): - runner_ = find_runner(runner, **args) + runner_ = find_runner(runner, main=False, **args) case_suites = {} expected_case_perms = co.OrderedDict() expected_perms = 0 @@ -790,7 +794,7 @@ def find_perms(runner, bench_ids=[], **args): total_perms) def find_path(runner, id, **args): - runner_ = find_runner(runner, id, **args) + runner_ = find_runner(runner, id, main=False, **args) path = None # query from runner cmd = runner_ + ['--list-case-paths', id] @@ -818,7 +822,7 @@ def find_path(runner, id, **args): return path def find_defines(runner, id, **args): - runner_ = find_runner(runner, id, **args) + runner_ = find_runner(runner, id, main=False, **args) # query permutation defines from runner cmd = runner_ + ['--list-permutation-defines', id] if args.get('verbose'): @@ -914,7 +918,7 @@ def find_ids(runner, bench_ids=[], **args): def list_(runner, bench_ids=[], **args): - cmd = find_runner(runner, **args) + cmd = find_runner(runner, main=False, **args) cmd.extend(find_ids(runner, bench_ids, **args)) if args.get('summary'): cmd.append('--summary') @@ -1151,7 +1155,7 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args): list(last_stdout), last_assert) - def run_job(start=None, step=None): + def run_job(main=True, start=None, step=None): nonlocal failed_perms nonlocal failures nonlocal killed @@ -1160,10 +1164,10 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args): start = start or 0 step = step or 1 while start < total_perms: - runner_ = find_runner(runner, **args) + runner_ = find_runner(runner, main=main, **args) if args.get('isolate') or args.get('valgrind'): runner_.append('-s%s,%s,%s' % (start, start+step, step)) - else: + elif start != 0 or step != 1: runner_.append('-s%s,,%s' % (start, step)) runner_.extend(bench_ids) @@ -1205,11 +1209,11 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args): if 'jobs' in args: for job in range(args['jobs']): runners.append(th.Thread( - target=run_job, args=(job, args['jobs']), + target=run_job, args=(job == 0, job, args['jobs']), daemon=True)) else: runners.append(th.Thread( - target=run_job, args=(None, None), + target=run_job, args=(True, None, None), daemon=True)) def print_update(done): diff --git a/scripts/test.py b/scripts/test.py index 411d6b65..20f7a0b4 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -667,7 +667,7 @@ def compile(test_paths, **args): f.writeln() -def find_runner(runner, id=None, **args): +def find_runner(runner, id=None, main=True, **args): cmd = runner.copy() # run under some external command? @@ -703,22 +703,26 @@ def find_runner(runner, id=None, **args): cmd.append('-P%s' % args['powerloss']) if args.get('all'): cmd.append('-a') - if args.get('disk'): - cmd.append('-d%s' % args['disk']) - if args.get('trace'): - cmd.append('-t%s' % args['trace']) - if args.get('trace_backtrace'): - cmd.append('--trace-backtrace') - if args.get('trace_period'): - cmd.append('--trace-period=%s' % args['trace_period']) - if args.get('trace_freq'): - cmd.append('--trace-freq=%s' % args['trace_freq']) - if args.get('read_sleep'): - cmd.append('--read-sleep=%s' % args['read_sleep']) - if args.get('prog_sleep'): - cmd.append('--prog-sleep=%s' % args['prog_sleep']) - if args.get('erase_sleep'): - cmd.append('--erase-sleep=%s' % args['erase_sleep']) + + # only one thread should write to disk/trace, otherwise the output + # ends up clobbered and useless + if main: + if args.get('disk'): + cmd.append('-d%s' % args['disk']) + if args.get('trace'): + cmd.append('-t%s' % args['trace']) + if args.get('trace_backtrace'): + cmd.append('--trace-backtrace') + if args.get('trace_period'): + cmd.append('--trace-period=%s' % args['trace_period']) + if args.get('trace_freq'): + cmd.append('--trace-freq=%s' % args['trace_freq']) + if args.get('read_sleep'): + cmd.append('--read-sleep=%s' % args['read_sleep']) + if args.get('prog_sleep'): + cmd.append('--prog-sleep=%s' % args['prog_sleep']) + if args.get('erase_sleep'): + cmd.append('--erase-sleep=%s' % args['erase_sleep']) # defines? if args.get('define') and id is None: @@ -736,7 +740,7 @@ def find_runner(runner, id=None, **args): return cmd def find_perms(runner, test_ids=[], **args): - runner_ = find_runner(runner, **args) + runner_ = find_runner(runner, main=False, **args) case_suites = {} expected_case_perms = co.OrderedDict() expected_perms = 0 @@ -810,7 +814,7 @@ def find_perms(runner, test_ids=[], **args): total_perms) def find_path(runner, id, **args): - runner_ = find_runner(runner, id, **args) + runner_ = find_runner(runner, id, main=False, **args) path = None # query from runner cmd = runner_ + ['--list-case-paths', id] @@ -838,7 +842,7 @@ def find_path(runner, id, **args): return path def find_defines(runner, id, **args): - runner_ = find_runner(runner, id, **args) + runner_ = find_runner(runner, id, main=False, **args) # query permutation defines from runner cmd = runner_ + ['--list-permutation-defines', id] if args.get('verbose'): @@ -934,7 +938,7 @@ def find_ids(runner, test_ids=[], **args): def list_(runner, test_ids=[], **args): - cmd = find_runner(runner, **args) + cmd = find_runner(runner, main=False, **args) cmd.extend(find_ids(runner, test_ids, **args)) if args.get('summary'): cmd.append('--summary') @@ -1123,7 +1127,7 @@ def run_stage(name, runner, test_ids, stdout_, trace_, output_, **args): list(last_stdout), last_assert) - def run_job(start=None, step=None): + def run_job(main=True, start=None, step=None): nonlocal failed_perms nonlocal failures nonlocal killed @@ -1132,10 +1136,10 @@ def run_stage(name, runner, test_ids, stdout_, trace_, output_, **args): start = start or 0 step = step or 1 while start < total_perms: - runner_ = find_runner(runner, **args) + runner_ = find_runner(runner, main=main, **args) if args.get('isolate') or args.get('valgrind'): runner_.append('-s%s,%s,%s' % (start, start+step, step)) - else: + elif start != 0 or step != 1: runner_.append('-s%s,,%s' % (start, step)) runner_.extend(test_ids) @@ -1189,11 +1193,11 @@ def run_stage(name, runner, test_ids, stdout_, trace_, output_, **args): if 'jobs' in args: for job in range(args['jobs']): runners.append(th.Thread( - target=run_job, args=(job, args['jobs']), + target=run_job, args=(job == 0, job, args['jobs']), daemon=True)) else: runners.append(th.Thread( - target=run_job, args=(None, None), + target=run_job, args=(True, None, None), daemon=True)) def print_update(done):