Skip to content

Commit

Permalink
(litmus) nest group names
Browse files Browse the repository at this point in the history
Now groups have names structured the same as the directory structure that
they came from. e.g. if there was a foo/bar/baz.c then there are groups:
> \@ALL         - runs them all
> foo/\@ALL     - runs all the foo's
> foo/bar/\@ALL - runs all the foo/bar's

This means we can put generated and hand-written tests in separate directories,
without same-named sub-directories causing overlapping group names.
  • Loading branch information
bensimner committed May 19, 2024
1 parent d652cae commit 5985d74
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
6 changes: 3 additions & 3 deletions litmus/main_match_and_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ static u8 __match_and_run_test(const litmus_test_group* grp, re_t* arg) {
void match_and_run(const litmus_test_group* grp, re_t* arg) {
u8 found = 0;

if (*arg->original_expr == '@') {
found = __match_and_run_test(grp, arg);

if (!found) {
found = __match_and_run_group(grp, arg);
} else {
found = __match_and_run_test(grp, arg);
}

if (!found) {
Expand Down
40 changes: 30 additions & 10 deletions litmus/makegroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def __init__(self, root, force, includes):
self.force = force
self.includes = includes

self.all_tests = GroupMap("all")
self.already_seen = GroupMap("all")
self.matching_tests = GroupMap("all")
self.updated_tests = GroupMap("all")
self.all_tests = GroupMap()
self.already_seen = GroupMap()
self.matching_tests = GroupMap()
self.updated_tests = GroupMap()

def updated_groups(self):
return not self.updated_tests.is_empty() or self.force or not (root / 'groups.c').exists()
Expand Down Expand Up @@ -181,7 +181,7 @@ def get_tests(self, d, extra_includes=[], groups=[]):

group_template = """
const litmus_test_group grp_%s = {
.name="@%s",
.name="%s",
.tests = (const litmus_test_t*[]){
%s
},
Expand All @@ -191,17 +191,37 @@ def get_tests(self, d, extra_includes=[], groups=[]):
};\
"""

def build_at_name(g, prefix):
# special case: top-level is called just @all
if g.name == "":
assert not prefix
return "@all"

return "/".join(prefix + (g.name,)) + "/@all"

def build_c_name(g, prefix):
# special case: top-level is called just all
if g.name == "":
assert not prefix
return "all"

return build_at_name(g, prefix).replace("/", "_").replace("_@all", "")

def build_group_defs(matching, prefix=()):
if matching.name:
next_prefix = prefix + (matching.name,)
else:
# Ugh! top-level group is "" so the prefix actually starts here.
next_prefix = prefix

def build_group_defs(matching):
for g in matching.groups.values():
yield from build_group_defs(g)
yield from build_group_defs(g, next_prefix)

name = matching.name
test_refs = ['&{}'.format(t.test.ident) for t in sorted(matching.tests, key=lambda t: t.test.name)]
grp_refs = sorted('&grp_{}'.format(grp_name) for grp_name in matching.groups)
grp_refs = sorted('&grp_{}'.format(build_c_name(g, next_prefix)) for g in matching.groups.values())
test_refs.append('NULL')
grp_refs.append('NULL')
yield group_template % (name, name, ',\n '.join(test_refs), ',\n '.join(grp_refs))
yield group_template % (build_c_name(matching, prefix), build_at_name(matching, prefix), ',\n '.join(test_refs), ',\n '.join(grp_refs))


def build_externs(matching):
Expand Down

0 comments on commit 5985d74

Please sign in to comment.