Skip to content

Commit c0be0df

Browse files
authored
Merge pull request #3 from rems-project/prepare-litmus-toml-translator
Add litmus toml translator
2 parents 178c9a4 + 0991d77 commit c0be0df

23 files changed

+3795
-30
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- master
7+
- prepare-litmus-toml-translator
78
# pull_request: {}
89

910
# cancel in-progress job when a new push is performed
@@ -23,22 +24,64 @@ jobs:
2324

2425
timeout-minutes: 5
2526
steps:
27+
- run: mkdir -p rems-project litmus-tests
28+
2629
- uses: actions/checkout@v3
30+
with:
31+
path: rems-project/system-litmus-harness
2732

2833
- name: System dependencies (ubuntu)
2934
run: |
3035
sudo apt update
3136
sudo apt install build-essential gcc-aarch64-linux-gnu qemu-system-aarch64
3237
38+
- name: Get rust toolchain
39+
uses: actions-rs/toolchain@v1
40+
with:
41+
profile: minimal
42+
toolchain: stable
43+
44+
- name: Setup rems-project dependencies
45+
working-directory: rems-project
46+
run: |
47+
git clone https://github.com/rems-project/isla
48+
git clone https://github.com/rems-project/isla-snapshots
49+
50+
- name: Setup litmus-tests org dependencies
51+
working-directory: litmus-tests
52+
run: |
53+
git clone https://github.com/litmus-tests/litmus-tests-armv8a-system-vmsa/
54+
3355
- name: Build harness
56+
working-directory: rems-project/system-litmus-harness
3457
run: |
3558
make build
3659
3760
- name: Check for compiler warnings
61+
working-directory: rems-project/system-litmus-harness
3862
run: |
3963
make -B -s check
4064
4165
- name: Run unittests
66+
working-directory: rems-project/system-litmus-harness
4267
run: |
4368
./qemu_unittests --no-test-linear-concretization | tee log
4469
[ $(tail -c -2 log) -eq 0 ]
70+
71+
- name: Build tools
72+
working-directory: rems-project/system-litmus-harness
73+
run: |
74+
make tools
75+
76+
- name: Run TOML translator
77+
working-directory: rems-project/system-litmus-harness
78+
run: |
79+
make translate-toml-tests
80+
81+
- name: Compile translated tests
82+
working-directory: rems-project/system-litmus-harness
83+
run: |
84+
# should automatically discover and build new tests
85+
make build
86+
# validate by checking an arbitrarily-picked test was actually compiled
87+
[ -f ./bin/litmus/litmus_tests/generated/pgtable/CoWinvT+po.litmus.toml.o ]

Makefile

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
define USAGE
22
Simple Usage:
3-
make build builds qemu and kvm targets
4-
make check runs the compiler warning checks but doesn't compile
5-
make docker builds docker container and runs the unittests
6-
make clean remove built files in bin/
7-
make deepclean clean everything. No really.
8-
make publish publish doc/ folder to gh-pages
3+
make build builds qemu and kvm targets
4+
make check runs the compiler warning checks but doesn't compile
5+
make docker builds docker container and runs the unittests
6+
make clean remove built files in bin/
7+
make deepclean clean everything. No really.
8+
make publish publish doc/ folder to gh-pages
99
make hw-results collect hardware results from known sources
10-
make test run the unittests in QEMU
11-
make run run the litmus tests in QEMU
10+
make test run the unittests in QEMU
11+
make run run the litmus tests in QEMU
12+
make tools build supporting tooling
1213
endef
1314

1415
define ADV_USAGE
@@ -19,6 +20,10 @@ Advanced Usage:
1920
Runs qemu_unittests.exe in the background and attaches gdb
2021
make build-unittests
2122
Builds the unittests and generates qemu_unittests.exe
23+
make tools
24+
Builds associated tooling
25+
make translate-toml-tests
26+
Runs the automated TOML test translator
2227
make lint
2328
Runs automated linter against all litmus test C files and quits
2429
See LINTER option below
@@ -27,6 +32,8 @@ Advanced Usage:
2732
See LITMUS_TESTS and MAKE_TEST_LIST_CMD options below
2833
make cleanlibs
2934
remove built harness objects but leave compiled tests alone
35+
make cleantools
36+
remove built tool files
3037
make cleantests
3138
remove auto-generated test files in litmus/
3239
make docker-interact
@@ -112,6 +119,12 @@ OBJDUMP = $(PREFIX)objdump
112119
QEMU = qemu-system-aarch64
113120
GDB = $(PREFIX)gdb
114121

122+
# dependency roots
123+
# by default we assume rems-project/ repos are siblings to this one
124+
# and litmus-tests/ org repos are a sibling to rems-project
125+
REMSORGDIR = ../
126+
LITMUSORGDIR = ../../litmus-tests/
127+
115128
# use `taskset` to force QEMU to exist only on some cores
116129
# e.g. for big.LITTLE implementations
117130
#
@@ -189,7 +202,7 @@ CFLAGS = -O0 -nostdlib \
189202
$(CFLAGS_DEPS) \
190203
-ffreestanding -fno-omit-frame-pointer -fno-pie -fno-pic \
191204
-mstrict-align \
192-
-march=armv8-a+nofp \
205+
-march=armv8.5-a+nofp \
193206
-Wall $(addprefix -Wno-,$(CCNOWARN)) $(addprefix -Werror=,$(CCERRORS)) \
194207
-Wextra -Wno-unused-parameter -Wno-sign-compare \
195208
-Wshadow \
@@ -215,6 +228,16 @@ LINTER_ARGS = $(foreach e,$(LINTER_EXCLUDES),-e $(e))
215228

216229
NO_LINT = 0
217230

231+
# toml-translator arguments:
232+
# TOML_TESTS: list of tests or @all file to translate.
233+
# TOML_TRANSLATOR_ISLA_CONFIG: isla architecture config toml file.
234+
# TOML_TRANSLATOR_ISLA_ARCH: isla architecture ir (or irx) file.
235+
# TOML_TRANSLATOR_IGNORE_LIST: txt file with list of toml tests to ignore.
236+
TOML_TESTS = $(LITMUSORGDIR)/litmus-tests-armv8a-system-vmsa/tests/@all
237+
TOML_TRANSLATOR_ISLA_CONFIG = $(REMSORGDIR)/isla/configs/armv8p5.toml
238+
TOML_TRANSLATOR_ISLA_ARCH = $(REMSORGDIR)/isla-snapshots/armv8p5.ir
239+
TOML_TRANSLATOR_IGNORE_LIST = ./tools/litmus-toml-translator/toml-tests-ignore.txt
240+
218241
ifneq ($(findstring help,$(filter-out --%,$(MAKECMDGOALS))),)
219242
TARGET_HELP = 1
220243
endif
@@ -231,6 +254,7 @@ include mk/docs.mk
231254
include mk/qemu.mk
232255
include mk/build.mk
233256
include mk/docker.mk
257+
include mk/tools.mk
234258

235259
define INSTALL
236260
$(call run_cmd,INSTALL,./$(2),\
@@ -267,6 +291,7 @@ cleantests:
267291
$(call CLEAN,-f,litmus/test_list.txt)
268292
$(call CLEAN,-f,litmus/group_list.txt)
269293
$(call CLEAN,-f,litmus/linter.log)
294+
$(call CLEAN,-rf,litmus/litmus_tests/generated)
270295

271296
# list of PHONY targets that will need
272297
# files in the litmus/litmus_tests/ dir
@@ -434,6 +459,10 @@ LITMUS_TARGETS += run
434459
include mk/litmus.mk
435460
include mk/unittests.mk
436461

462+
# target populated by mk/tools.mk
463+
.PHONY: tools
464+
tools:
465+
437466
# provide a list of all the potential build- targets
438467
.PHONY: list
439468
list:

inc/litmus/litmus_asm_in_macros.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@
4545
#define STRINGIFY_4(a, ...) STRINGIFY_1(a), STRINGIFY_3(__VA_ARGS__)
4646
#define STRINGIFY_5(a, ...) STRINGIFY_1(a), STRINGIFY_4(__VA_ARGS__)
4747
#define STRINGIFY_6(a, ...) STRINGIFY_1(a), STRINGIFY_5(__VA_ARGS__)
48-
#define STRINGIFY_N(a, b, c, d, e, f, n, ...) STRINGIFY_##n(a, b, c, d, e, f)
49-
#define STRINGIFY(...) STRINGIFY_N(__VA_ARGS__, 6, 5, 4, 3, 2, 1)
48+
#define STRINGIFY_7(a, ...) STRINGIFY_1(a), STRINGIFY_6(__VA_ARGS__)
49+
#define STRINGIFY_8(a, ...) STRINGIFY_1(a), STRINGIFY_7(__VA_ARGS__)
50+
#define STRINGIFY_9(a, ...) STRINGIFY_1(a), STRINGIFY_8(__VA_ARGS__)
51+
#define STRINGIFY_10(a, ...) STRINGIFY_1(a), STRINGIFY_9(__VA_ARGS__)
52+
#define STRINGIFY_11(a, ...) STRINGIFY_1(a), STRINGIFY_10(__VA_ARGS__)
53+
#define STRINGIFY_12(a, ...) STRINGIFY_1(a), STRINGIFY_11(__VA_ARGS__)
54+
#define STRINGIFY_N(a, b, c, d, e, f, g, h, i, j, k, l, n, ...) STRINGIFY_##n(a, b, c, d, e, f, g, h, i, j, k, l)
55+
#define STRINGIFY(...) STRINGIFY_N(__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
5056

5157
#define HUMANIZE_1(a, ...) HUMAN(a)
5258
#define HUMANIZE_2(a, ...) HUMANIZE_1(a), HUMANIZE_1(__VA_ARGS__)

litmus/linter.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
r"litmus_test_t\s+(?P<cname>.+?)\s*=\s*\{"
2929
r"\s*\"(?P<human_name>.+?)\"\s*,"
3030
r'\s*MAKE_THREADS\((?P<no_threads>\d+)\)\s*?,'
31-
r'\s*MAKE_VARS\(VARS\)\s*?,'
31+
r'\s*MAKE_VARS\(VARS(\s*,\s*pa\d+)*\)\s*?,'
3232
r'\s*MAKE_REGS\(REGS\)\s*?,'
3333
r'(?P<fields>[\s\S]*?)'
3434
r'\s*\}\s*;'
@@ -58,7 +58,7 @@
5858
C_FUN_PAT = (
5959
r"void (?P<fname>.+)\(.+\)\s*\{"
6060
r"(?P<body>[\s\S]*?)"
61-
r"\s*\}"
61+
r"^}"
6262
)
6363

6464
C_INIT_ST = (
@@ -73,7 +73,7 @@
7373
def get_reg_names(asm):
7474
if not asm:
7575
return []
76-
return ['x{}'.format(i) for i in re.findall(r'(?<=(?<!\%\[)[xw])\d+', asm['code'])]
76+
return ['x{}'.format(i) for i in re.findall(r'(?<=(?<!.0|\%\[)[xwXW])\d+', asm['code'])]
7777

7878
def parse_litmus_code(path, c_code):
7979
match = re.search(LITMUS_TEST_T_PAT_NEW, c_code, re.MULTILINE)
@@ -155,7 +155,13 @@ def check_uniq_names(litmuses):
155155

156156
def check_human_match_path(l):
157157
p = pathlib.Path(l['path']).stem
158-
if l['human_name'] != str(p):
158+
159+
# for toml-translator generated names, strip the .toml.c
160+
if p.endswith(".litmus.toml"):
161+
p = p[:-len(".litmus.toml")]
162+
pass
163+
164+
if l['human_name'] != p:
159165
warn(l, "File name and Litmus name mismatch.")
160166

161167

litmus/main_match_and_run.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ static u8 __match_and_run_test(const litmus_test_group* grp, re_t* arg) {
7373
void match_and_run(const litmus_test_group* grp, re_t* arg) {
7474
u8 found = 0;
7575

76-
if (*arg->original_expr == '@') {
76+
found = __match_and_run_test(grp, arg);
77+
78+
if (!found) {
7779
found = __match_and_run_group(grp, arg);
78-
} else {
79-
found = __match_and_run_test(grp, arg);
8080
}
8181

8282
if (!found) {

litmus/makegroups.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def __init__(self, root, force, includes):
8383
self.force = force
8484
self.includes = includes
8585

86-
self.all_tests = GroupMap("all")
87-
self.already_seen = GroupMap("all")
88-
self.matching_tests = GroupMap("all")
89-
self.updated_tests = GroupMap("all")
86+
self.all_tests = GroupMap()
87+
self.already_seen = GroupMap()
88+
self.matching_tests = GroupMap()
89+
self.updated_tests = GroupMap()
9090

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

182182
group_template = """
183183
const litmus_test_group grp_%s = {
184-
.name="@%s",
184+
.name="%s",
185185
.tests = (const litmus_test_t*[]){
186186
%s
187187
},
@@ -191,17 +191,37 @@ def get_tests(self, d, extra_includes=[], groups=[]):
191191
};\
192192
"""
193193

194+
def build_at_name(g, prefix):
195+
# special case: top-level is called just @all
196+
if g.name == "":
197+
assert not prefix
198+
return "@all"
199+
200+
return "/".join(prefix + (g.name,)) + "/@all"
201+
202+
def build_c_name(g, prefix):
203+
# special case: top-level is called just all
204+
if g.name == "":
205+
assert not prefix
206+
return "all"
207+
208+
return build_at_name(g, prefix).replace("/", "_").replace("_@all", "")
209+
210+
def build_group_defs(matching, prefix=()):
211+
if matching.name:
212+
next_prefix = prefix + (matching.name,)
213+
else:
214+
# Ugh! top-level group is "" so the prefix actually starts here.
215+
next_prefix = prefix
194216

195-
def build_group_defs(matching):
196217
for g in matching.groups.values():
197-
yield from build_group_defs(g)
218+
yield from build_group_defs(g, next_prefix)
198219

199-
name = matching.name
200220
test_refs = ['&{}'.format(t.test.ident) for t in sorted(matching.tests, key=lambda t: t.test.name)]
201-
grp_refs = sorted('&grp_{}'.format(grp_name) for grp_name in matching.groups)
221+
grp_refs = sorted('&grp_{}'.format(build_c_name(g, next_prefix)) for g in matching.groups.values())
202222
test_refs.append('NULL')
203223
grp_refs.append('NULL')
204-
yield group_template % (name, name, ',\n '.join(test_refs), ',\n '.join(grp_refs))
224+
yield group_template % (build_c_name(matching, prefix), build_at_name(matching, prefix), ',\n '.join(test_refs), ',\n '.join(grp_refs))
205225

206226

207227
def build_externs(matching):

mk/deepclean.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.PHONY: deepclean
2-
deepclean: clean cleanlibs cleantests
2+
deepclean: clean cleanlibs cleantests cleantools

mk/litmus.mk

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.PHONY: debug-litmus
44
.PHONY: collect-litmus
55
.PHONY: count-litmus-tests
6+
.PHONY: translate-toml-tests
67

78
LITMUS_TARGETS += lint collect-litmus debug-litmus count-litmus-tests check
89

@@ -141,4 +142,19 @@ debug-litmus: qemu_litmus
141142

142143
count-litmus-tests:
143144
@echo Found `cat litmus/test_list.txt | wc -l` tests
144-
@echo With `cat litmus/test_list.txt | awk '{print gensub(/^(.+\/)+(.+)\+(.+)$$/,"\\\\2","g",$$2)}' | sort | uniq | wc -l` unique shapes
145+
@echo With `cat litmus/test_list.txt | awk '{print gensub(/^(.+\/)+(.+)\+(.+)$$/,"\\\\2","g",$$2)}' | sort | uniq | wc -l` unique shapes
146+
147+
TOML_TRANSLATOR_ARGS = \
148+
-A $(TOML_TRANSLATOR_ISLA_ARCH) \
149+
-C $(TOML_TRANSLATOR_ISLA_CONFIG) \
150+
-o litmus/litmus_tests/generated
151+
152+
ifneq ($(TOML_TRANSLATOR_IGNORE_LIST),)
153+
TOML_TRANSLATOR_ARGS += -x $(TOML_TRANSLATOR_IGNORE_LIST)
154+
endif
155+
156+
translate-toml-tests: $(TOML_TRANSLATOR)
157+
@mkdir -p litmus/litmus_tests/generated
158+
$(call run_cmd,TOML_TRANSLATE,$(TOML_TESTS),\
159+
$(TOML_TRANSLATOR) $(TOML_TRANSLATOR_ARGS) $(TOML_TESTS) \
160+
)

mk/tools.mk

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: cleantools
2+
3+
TOOLS_DIR = tools/
4+
5+
TOML_TRANSLATOR_ROOT = ./tools/litmus-toml-translator
6+
TOML_TRANSLATOR = $(TOML_TRANSLATOR_ROOT)/target/release/litmus-toml-translator
7+
8+
$(TOML_TRANSLATOR):
9+
$(call run_cmd,CARGO,tools/litmus-toml-translator,cd tools/litmus-toml-translator && cargo build --profile=release)
10+
TOOLS += $(TOML_TRANSLATOR)
11+
.PHONY: $(TOML_TRANSLATOR)
12+
13+
cleantools:
14+
$(call run_cmd,CLEAN,tools/litmus-toml-translator,cd tools/litmus-toml-translator && cargo clean)
15+
16+
tools: $(TOOLS)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
*.irx

0 commit comments

Comments
 (0)