Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
56a9903
Created new test_runner.c and test_.py
geky Apr 16, 2022
d683f1c
Reintroduced test-defines into the new test_runner
geky Apr 18, 2022
4b0aa62
Some more minor improvements to the test_runner
geky Apr 18, 2022
9281ce2
More test_runner progress
geky Apr 18, 2022
92a600a
Added trace and persist flags to test_runner
geky Apr 19, 2022
6443693
Putting together rewritten test.py script
geky Apr 24, 2022
5812d2b
Reworked how multi-layered defines work in the test-runner
geky Apr 25, 2022
5ee4b05
Misc test-runner improvements
geky Apr 25, 2022
4962829
Continued progress toward feature parity with new test-runner
geky May 1, 2022
be0e6ad
More progress toward test-runner feature parity
geky May 2, 2022
5a572ce
Reworked how test defines are implemented to support recursion
geky May 8, 2022
d679fbb
In ./scripts/test.py, readded external commands, tweaked subprocesses
geky May 8, 2022
0781f50
Ported tests to new framework
geky May 14, 2022
4a42326
Moved test suites into custom linker section
geky May 14, 2022
1616115
Fix test.py hang on ctrl-C, cleanup TODOs
geky May 15, 2022
2b11f2b
Tweaked generation of .cgi files, error code for recursion in stack.py
geky May 15, 2022
4a7e94f
Reimplemented coverage.py, using only gcov and with line+branch coverage
geky May 16, 2022
5b0a6d4
Reworked scripts to move field details into classes
geky May 21, 2022
46cc6d4
Added support for annotated source in coverage.py
geky May 23, 2022
92eee8e
Removed some prefixes from Makefile variables where not necessary
geky Aug 15, 2022
b08463f
Reworked scripts/pretty_asserts.py a bit
geky Aug 16, 2022
a368d3a
Moved emulation of erase values up into lfs_testbd
geky Aug 17, 2022
01b11da
Added a simple test that the block device works
geky Aug 17, 2022
61455b6
Added back heuristic-based power-loss testing
geky Aug 19, 2022
4689678
Added --color to test.py, fixed some terminal-clobbering issues
geky Aug 22, 2022
3f4f859
Readded support for mirror writes to a file in testbd
geky Aug 23, 2022
552336e
Added optional read/prog/erase delays to testbd
geky Aug 23, 2022
5279fc6
Implemented exhaustive testing of n nested powerlosses
geky Aug 25, 2022
c9a6e3a
Added tailpipe.py and improved redirecting test trace/log output over…
geky Aug 27, 2022
91200e6
Added tracebd.py, a script for rendering block device operations
geky Sep 2, 2022
a208d84
Reworked test defines a bit to use one common array layout
geky Sep 6, 2022
c7f7094
Several tweaks to test.py and test runner
geky Sep 9, 2022
5a2ff17
Changed test identifier separator # -> :
geky Sep 9, 2022
bfbe44e
Dropped permutation number for full leb16-encoded defines
geky Sep 10, 2022
03c1a4e
Added permutations and ranges to test defines
geky Sep 11, 2022
23fba40
Added option for updating a CSV file with test results
geky Sep 12, 2022
acdea18
Made summary.py more powerful, dropped -m from size scripts
geky Sep 14, 2022
1fcd82d
Made test.py output parsable by summary.py
geky Sep 16, 2022
11d6d12
Dropped namespacing of test cases
geky Sep 17, 2022
20ec0be
Cleaned up a number of small tweaks in the scripts
geky Sep 19, 2022
4fe0738
Added bench.py and bench_runner.c for benchmarking
geky Sep 20, 2022
9a0e3be
Added a quick trie to avoid running redundant test/bench permutations
geky Sep 20, 2022
7591d9c
Added plot.py for in-terminal plotting
geky Sep 22, 2022
fb58148
Consistent handling of by/field arguments for plot.py and summary.py
geky Sep 23, 2022
42d889e
Reworked/simplified tracebd.py a bit
geky Sep 25, 2022
9507e62
Several tweaks to script flags
geky Sep 27, 2022
a2fb708
Added stddev/gmean/gstddev to summary.py
geky Sep 27, 2022
274222b
Added some automatic sizing for field-names in scripts/runners
geky Sep 27, 2022
296c5af
Renamed bench_read/prog/erased -> bench_readed/proged/erased
geky Sep 27, 2022
ca66993
Tweaked scripts to share more code, added coverage calls/hits
geky Oct 2, 2022
490e1c4
Added perf.py a wrapper around Linux's perf tool for perf sampling
geky Oct 2, 2022
df283ae
Added recursive results to perf.py
geky Oct 9, 2022
29cbafe
Renamed coverage.py -> cov.py
geky Oct 9, 2022
3a33c37
Added perfbd.py and block device performance sampling in bench-runner
geky Oct 13, 2022
b2a2cc9
Added teepipe.py and watch.py
geky Oct 16, 2022
559e174
Added plotmpl.py for creating svg/png plots with matplotlib
geky Oct 20, 2022
6fce9e5
Changed plotmpl.py/plot.py to not treat missing values as discontinui…
geky Nov 10, 2022
1a07c2c
A number of small script fixes/tweaks from usage
geky Nov 11, 2022
e35e078
Renamed prefix.py -> changeprefix.py and updated to use argparse
geky Nov 16, 2022
bcc88f5
A couple Makefile-related tweaks
geky Nov 17, 2022
f734941
Changed default build target lfs.a -> liblfs.a
geky Nov 17, 2022
6c18b4d
Added a simple help rule to the Makefile
geky Nov 17, 2022
f89d758
Fixed test out-of-space issues with powerloss testing
geky Nov 28, 2022
eba5553
Fixed hidden orphans by separating deorphan search into two passes
geky Nov 28, 2022
0b11ce0
Fixed incorrect calculation of extra space needed in mdir blocks
geky Nov 19, 2022
387cf6f
Fixed a couple corner cases in scripts when fields are empty
geky Nov 19, 2022
65923cd
Adopted script changes in GitHub Actions
geky Nov 17, 2022
397aa27
Removed unnecessarily heavy RAM usage from logs in bench/test.py
geky Nov 23, 2022
a659c02
Added a bot-generated PR-comment with a simple status table
geky Nov 23, 2022
4a20934
Fixed bench workflow + changeprefix issue in prefix releases
geky Nov 27, 2022
0c781dd
Merge remote-tracking branch 'origin/master' into test-and-bench-runners
geky Dec 7, 2022
9990342
Fixed Clang testing in CI, removed override vars in Makefile
geky Nov 29, 2022
c4b3e9d
A couple of script changes after CI integration
geky Nov 29, 2022
9b687dd
Added make benchmarks/testmarks rules
geky Nov 29, 2022
cda2f6f
Changed test_runner to run with -Pnone,linear by default
geky Nov 30, 2022
d8e7ffb
Changed lfs_emubd_get* -> lfs_emubd_*
geky Nov 30, 2022
b0382fa
Added BENCH/TEST_PRNG, replacing other ad-hoc sources of randomness
geky Nov 30, 2022
2d2dd8b
Added plotmpl.py --github flag to match the website's foreground/back…
geky Dec 2, 2022
cfd4e60
Added --subplot* to plotmpl.py
geky Dec 13, 2022
1f37eb5
Adopted --subplot* in plot.py
geky Dec 15, 2022
801cf27
Tweaked/fixed a number of small runner things after a bit of use
geky Dec 17, 2022
c2147c4
Added --gdb-pl to test.py for breaking on specific powerlosses
geky Dec 10, 2022
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
Prev Previous commit
Next Next commit
Dropped namespacing of test cases
The main benefit is small test ids everywhere, though this is with the
downside of needing longer names to properly prefix and avoid
collisions. But this fits into the rest of the scripts with globally
unique names a bit better. This is a C project after all.

The other small benefit is test generators may have an easier time since
per-case symbols can expect to be unique.
  • Loading branch information
geky committed Sep 17, 2022
commit 11d6d1251e4ac377f91e1b4cd89f43c717a80bdb
248 changes: 123 additions & 125 deletions runners/test_runner.c

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions runners/test_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ typedef struct test_define {
} test_define_t;

struct test_case {
const char *id;
const char *name;
const char *path;
test_flags_t flags;
Expand All @@ -50,7 +49,6 @@ struct test_case {
};

struct test_suite {
const char *id;
const char *name;
const char *path;
test_flags_t flags;
Expand Down
189 changes: 134 additions & 55 deletions scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,10 @@ def parse_define(v):
print('%swarning:%s in %s, found unused key %r' % (
'\x1b[01;33m' if args['color'] else '',
'\x1b[m' if args['color'] else '',
self.id(),
self.name,
k),
file=sys.stderr)

def id(self):
return '%s:%s' % (self.suite, self.name)


class TestSuite:
# create a TestSuite object from a toml file
Expand Down Expand Up @@ -221,13 +218,10 @@ def __init__(self, path, args={}):
print('%swarning:%s in %s, found unused key %r' % (
'\x1b[01;33m' if args['color'] else '',
'\x1b[m' if args['color'] else '',
self.id(),
self.name,
k),
file=sys.stderr)

def id(self):
return self.name



def compile(test_paths, **args):
Expand All @@ -244,17 +238,45 @@ def compile(test_paths, **args):
print('no test suites found in %r?' % test_paths)
sys.exit(-1)

# load the suites
suites = [TestSuite(path, args) for path in paths]
suites.sort(key=lambda s: s.name)

# check for name conflicts, these will cause ambiguity problems later
# when running tests
seen = {}
for suite in suites:
if suite.name in seen:
print('%swarning:%s conflicting suite %r, %s and %s' % (
'\x1b[01;33m' if args['color'] else '',
'\x1b[m' if args['color'] else '',
suite.name,
suite.path,
seen[suite.name].path),
file=sys.stderr)
seen[suite.name] = suite

for case in suite.cases:
# only allow conflicts if a case and its suite share a name
if case.name in seen and not (
isinstance(seen[case.name], TestSuite)
and seen[case.name].cases == [case]):
print('%swarning:%s conflicting case %r, %s and %s' % (
'\x1b[01;33m' if args['color'] else '',
'\x1b[m' if args['color'] else '',
case.name,
case.path,
seen[case.name].path),
file=sys.stderr)
seen[case.name] = case

# we can only compile one test suite at a time
if not args.get('source'):
if len(paths) > 1:
if len(suites) > 1:
print('more than one test suite for compilation? (%r)' % test_paths)
sys.exit(-1)

# load our suite
suite = TestSuite(paths[0], args)
else:
# load all suites
suites = [TestSuite(path, args) for path in paths]
suites.sort(key=lambda s: s.name)
suite = suites[0]

# write generated test source
if 'output' in args:
Expand Down Expand Up @@ -332,7 +354,7 @@ def write_case_functions(f, suite, case):
f.writeln('void __test__%s__%s__run('
'__attribute__((unused)) struct lfs_config *cfg) {'
% (suite.name, case.name))
f.writeln(4*' '+'// test case %s' % case.id())
f.writeln(4*' '+'// test case %s' % case.name)
if case.code_lineno is not None:
f.writeln(4*' '+'#line %d "%s"'
% (case.code_lineno, suite.path))
Expand Down Expand Up @@ -384,10 +406,14 @@ def write_case_functions(f, suite, case):
f.writeln()

# create suite struct
f.writeln('__attribute__((section("_test_suites")))')
#
# note we place this in the custom test_suites section with
# minimum alignment, otherwise GCC ups the alignment to
# 32-bytes for some reason
f.writeln('__attribute__((section("_test_suites"), '
'aligned(1)))')
f.writeln('const struct test_suite __test__%s__suite = {'
% suite.name)
f.writeln(4*' '+'.id = "%s",' % suite.id())
f.writeln(4*' '+'.name = "%s",' % suite.name)
f.writeln(4*' '+'.path = "%s",' % suite.path)
f.writeln(4*' '+'.flags = %s,'
Expand All @@ -408,7 +434,6 @@ def write_case_functions(f, suite, case):
for case in suite.cases:
# create case structs
f.writeln(8*' '+'{')
f.writeln(12*' '+'.id = "%s",' % case.id())
f.writeln(12*' '+'.name = "%s",' % case.name)
f.writeln(12*' '+'.path = "%s",' % case.path)
f.writeln(12*' '+'.flags = %s,'
Expand Down Expand Up @@ -534,8 +559,13 @@ def list_(runner, test_ids=[], **args):
return sp.call(cmd)


def find_cases(runner_, ids=[], **args):
# query from runner
def find_perms(runner_, ids=[], **args):
case_suites = {}
expected_case_perms = co.defaultdict(lambda: 0)
expected_perms = 0
total_perms = 0

# query cases from the runner
cmd = runner_ + ['--list-cases'] + ids
if args.get('verbose'):
print(' '.join(shlex.quote(c) for c in cmd))
Expand All @@ -545,21 +575,17 @@ def find_cases(runner_, ids=[], **args):
universal_newlines=True,
errors='replace',
close_fds=False)
expected_suite_perms = co.defaultdict(lambda: 0)
expected_case_perms = co.defaultdict(lambda: 0)
expected_perms = 0
total_perms = 0
pattern = re.compile(
'^(?P<id>(?P<case>(?P<suite>[^:]+):[^\s:]+)[^\s]*)\s+'
'[^\s]+\s+(?P<filtered>\d+)/(?P<perms>\d+)')
'^(?P<case>[^\s]+)'
'\s+(?P<flags>[^\s]+)'
'\s+(?P<filtered>\d+)/(?P<perms>\d+)')
# skip the first line
for line in it.islice(proc.stdout, 1, None):
m = pattern.match(line)
if m:
filtered = int(m.group('filtered'))
perms = int(m.group('perms'))
expected_suite_perms[m.group('suite')] += filtered
expected_case_perms[m.group('id')] += filtered
expected_case_perms[m.group('case')] += filtered
expected_perms += filtered
total_perms += perms
proc.wait()
Expand All @@ -569,13 +595,50 @@ def find_cases(runner_, ids=[], **args):
sys.stdout.write(line)
sys.exit(-1)

# get which suite each case belongs to via paths
cmd = runner_ + ['--list-case-paths'] + ids
if args.get('verbose'):
print(' '.join(shlex.quote(c) for c in cmd))
proc = sp.Popen(cmd,
stdout=sp.PIPE,
stderr=sp.PIPE if not args.get('verbose') else None,
universal_newlines=True,
errors='replace',
close_fds=False)
pattern = re.compile(
'^(?P<case>[^\s]+)'
'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
# skip the first line
for line in it.islice(proc.stdout, 1, None):
m = pattern.match(line)
if m:
path = m.group('path')
# strip path/suffix here
suite = os.path.basename(path)
if suite.endswith('.toml'):
suite = suite[:-len('.toml')]
case_suites[m.group('case')] = suite
proc.wait()
if proc.returncode != 0:
if not args.get('verbose'):
for line in proc.stderr:
sys.stdout.write(line)
sys.exit(-1)

# figure out expected suite perms
expected_suite_perms = co.defaultdict(lambda: 0)
for case, suite in case_suites.items():
expected_suite_perms[suite] += expected_case_perms[case]

return (
case_suites,
expected_suite_perms,
expected_case_perms,
expected_perms,
total_perms)

def find_path(runner_, id, **args):
path = None
# query from runner
cmd = runner_ + ['--list-case-paths', id]
if args.get('verbose'):
Expand All @@ -586,10 +649,9 @@ def find_path(runner_, id, **args):
universal_newlines=True,
errors='replace',
close_fds=False)
path = None
pattern = re.compile(
'^(?P<id>(?P<case>(?P<suite>[^:]+):[^\s:]+)[^\s]*)\s+'
'(?P<path>[^:]+):(?P<lineno>\d+)')
'^(?P<case>[^\s]+)'
'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
# skip the first line
for line in it.islice(proc.stdout, 1, None):
m = pattern.match(line)
Expand Down Expand Up @@ -680,8 +742,11 @@ def __init__(self, id, returncode, stdout, assert_=None):

def run_stage(name, runner_, ids, output_, **args):
# get expected suite/case/perm counts
expected_suite_perms, expected_case_perms, expected_perms, total_perms = (
find_cases(runner_, ids, **args))
(case_suites,
expected_suite_perms,
expected_case_perms,
expected_perms,
total_perms) = find_perms(runner_, ids, **args)

passed_suite_perms = co.defaultdict(lambda: 0)
passed_case_perms = co.defaultdict(lambda: 0)
Expand All @@ -692,9 +757,10 @@ def run_stage(name, runner_, ids, output_, **args):

pattern = re.compile('^(?:'
'(?P<op>running|finished|skipped|powerloss) '
'(?P<id>(?P<case>(?P<suite>[^:]+):[^\s:]+)[^\s]*)'
'(?P<id>(?P<case>[^:]+)[^\s]*)'
'|' '(?P<path>[^:]+):(?P<lineno>\d+):(?P<op_>assert):'
' *(?P<message>.*)' ')$')
' *(?P<message>.*)'
')$')
locals = th.local()
children = set()

Expand Down Expand Up @@ -759,15 +825,18 @@ def run_runner(runner_, ids=[]):
last_id = m.group('id')
powerlosses += 1
elif op == 'finished':
passed_suite_perms[m.group('suite')] += 1
passed_case_perms[m.group('case')] += 1
case = m.group('case')
suite = case_suites[case]
passed_suite_perms[suite] += 1
passed_case_perms[case] += 1
passed_perms += 1
if output_:
# get defines and write to csv
defines = find_defines(
runner_, m.group('id'), **args)
output_.writerow({
'case': m.group('case'),
'suite': suite,
'case': case,
'test_passed': '1/1',
**defines})
elif op == 'skipped':
Expand Down Expand Up @@ -818,11 +887,13 @@ def run_job(runner_, ids=[], start=None, step=None):
except TestFailure as failure:
# keep track of failures
if output_:
suite, case, _ = failure.id.split(':', 2)
case, _ = failure.id.split(':', 1)
suite = case_suites[case]
# get defines and write to csv
defines = find_defines(runner_, failure.id, **args)
output_.writerow({
'case': ':'.join([suite, case]),
'suite': suite,
'case': case,
'test_passed': '0/1',
**defines})

Expand Down Expand Up @@ -919,13 +990,16 @@ def run(runner, test_ids=[], **args):
# query runner for tests
runner_ = find_runner(runner, **args)
print('using runner: %s' % ' '.join(shlex.quote(c) for c in runner_))
expected_suite_perms, expected_case_perms, expected_perms, total_perms = (
find_cases(runner_, test_ids, **args))
print('found %d suites, %d cases, %d/%d permutations'
% (len(expected_suite_perms),
len(expected_case_perms),
expected_perms,
total_perms))
(_,
expected_suite_perms,
expected_case_perms,
expected_perms,
total_perms) = find_perms(runner_, test_ids, **args)
print('found %d suites, %d cases, %d/%d permutations' % (
len(expected_suite_perms),
len(expected_case_perms),
expected_perms,
total_perms))
print()

# truncate and open logs here so they aren't disconnected between tests
Expand All @@ -937,7 +1011,7 @@ def run(runner, test_ids=[], **args):
trace = openio(args['trace'], 'w', 1)
output = None
if args.get('output'):
output = TestOutput(args['output'], ['case'], ['test_passed'])
output = TestOutput(args['output'], ['suite', 'case'], ['test_passed'])

# measure runtime
start = time.time()
Expand All @@ -951,12 +1025,17 @@ def run(runner, test_ids=[], **args):
else expected_suite_perms.keys() if args.get('by_suites')
else [None]):
# spawn jobs for stage
expected_, passed_, powerlosses_, failures_, killed = run_stage(
by or 'tests',
runner_,
[by] if by is not None else test_ids,
output,
**args)
(expected_,
passed_,
powerlosses_,
failures_,
killed) = run_stage(
by or 'tests',
runner_,
[by] if by is not None else test_ids,
output,
**args)
# collect passes/failures
expected += expected_
passed += passed_
powerlosses += powerlosses_
Expand Down
Loading