Makefile 10.2 KiB raw
1
# Radiance build file.
2
3
# Core standard library modules.
4
STD := -pkg std $(patsubst %,-mod %,$(shell cat std.lib))
5
6
# Full standard library with test modules.
7
STD_TEST := $(STD) $(patsubst %,-mod %,$(shell cat std.lib.test))
8
9
# Source files.
10
STD_LIB := $(shell find lib -name '*.rad')
11
BIN_DIR := bin
12
RAD_BIN := $(BIN_DIR)/radiance.rv64.dev
13
14
# Emulator command used to invoke the self-hosted compiler.
15
EMU       := $(or $(RAD_EMULATOR),emulator)
16
EMU_FLAGS := -memory-size=385024 \
17
			 -data-size=348160 \
18
			 -stack-size=1024 \
19
			 -count-instructions
20
RADIANCE  := $(EMU) $(EMU_FLAGS) -run $(RAD_BIN)
21
22
# Verify the emulator binary exists.
23
EMU_PATH := $(shell command -v $(EMU) 2>/dev/null)
24
25
default: emulator $(RAD_BIN)
26
test: emulator seed-test std-test bin-test kernel-test module-test package-test native-test shared-test sync-test kernel-boot-test trap-test page-test loader-test dispatch-test smp-test termination-test runtime-test bootstrap-test mmio-test cycles-test kernel-size-check scheduling-test
27
28
seed-test:
29
	@seed/test
30
31
module-test: emulator $(RAD_BIN)
32
	@RAD_EMULATOR="$(EMU)" sh test/modules/run
33
34
# Emulator command check
35
36
emulator:
37
ifeq ($(EMU_PATH),)
38
	$(error Emulator not found. Install it or set RAD_EMULATOR to its path)
39
endif
40
41
# Compiler build
42
43
SEED      := seed/radiance.rv64
44
COMPILER_SRC := compiler/radiance.rad compiler/radiance/codegen.rad
45
SEED_OPTS := $(STD) -pkg radiance $(patsubst %,-mod %,$(COMPILER_SRC)) -entry radiance
46
47
$(RAD_BIN): $(STD_LIB) $(COMPILER_SRC) | $(BIN_DIR)
48
	@echo "radiance $(SEED) => $@"
49
	@$(EMU) $(EMU_FLAGS) -run $(SEED) $(SEED_OPTS) -o $@
50
51
$(BIN_DIR):
52
	@mkdir -p $@
53
54
# Standard Library Tests
55
56
STD_LIB_TEST := lib/std.test.rv64
57
58
std-test: $(STD_LIB_TEST)
59
	@echo
60
	@$(EMU) $(EMU_FLAGS) -run $(STD_LIB_TEST)
61
62
$(STD_LIB_TEST): $(STD_LIB) $(RAD_BIN)
63
	@echo "radiance -test $(STD_TEST) -entry std -o $@"
64
	@$(RADIANCE) -test $(STD_TEST) -entry std -o $@
65
66
clean-std-test:
67
	@rm -f lib/std.test.rv64 \
68
		lib/std.test.rv64.debug \
69
		lib/std.test.rv64.s \
70
		lib/std.test.rv64.o
71
72
# Kernel modules and tests use a separate package and test entry point.
73
KERNEL_SRC := kernel/kernel.rad $(shell find kernel/kernel -name '*.rad' ! -name 'tests.rad' ! -path '*/tests/*' 2>/dev/null)
74
KERNEL_ASM := kernel/kernel/boot.ras kernel/kernel/sync.ras kernel/kernel/trap.ras kernel/kernel/pages.ras kernel/kernel/loader.ras kernel/kernel/instances.ras kernel/kernel/domains.ras kernel/kernel/dispatch.ras kernel/kernel/calls.ras kernel/kernel/plic.ras
75
KERNEL_TEST_SRC := kernel/kernel/tests.rad $(shell find kernel/kernel/tests -name '*.rad' 2>/dev/null)
76
KERNEL := -pkg kernel $(patsubst %,-mod %,$(sort $(KERNEL_SRC)))
77
KERNEL_TEST := $(BIN_DIR)/kernel.test.rv64
78
79
kernel-test: emulator $(KERNEL_TEST)
80
	@$(EMU) $(EMU_FLAGS) -run $(KERNEL_TEST)
81
	@sh test/slots/run "$(EMU)" $(STD_TEST) $(KERNEL) $(patsubst %,-mod %,$(KERNEL_TEST_SRC))
82
83
$(KERNEL_TEST): $(KERNEL_SRC) $(KERNEL_TEST_SRC) $(KERNEL_ASM) $(STD_LIB) $(RAD_BIN)
84
	@echo "radiance kernel tests => $@"
85
	@$(RADIANCE) -test $(STD_TEST) $(KERNEL) $(patsubst %,-mod %,$(KERNEL_TEST_SRC) $(KERNEL_ASM)) -entry kernel -o $@
86
87
# Native kernel image and machine boot checks.
88
kernel-boot-test: $(BIN_DIR)/kernel.rv64
89
	@RAD_EMULATOR="$(EMU)" sh test/boot/run
90
91
$(BIN_DIR)/kernel.ril $(BIN_DIR)/std.ril &: $(KERNEL_SRC) $(STD_LIB) $(RAD_BIN)
92
	@$(RADIANCE) $(STD) $(KERNEL) -entry kernel -ril $(BIN_DIR)
93
94
$(BIN_DIR)/kernel.build.rv64: kernel/tools/build.rad $(STD_LIB) $(RAD_BIN)
95
	@$(RADIANCE) $(STD) -pkg build -mod $< -entry build -o $@
96
97
# User packages share the ABI source through a staged package module tree.
98
$(BIN_DIR)/root.ril $(BIN_DIR)/scheduler.ril &: kernel/root.rad kernel/scheduler.rad kernel/mmio.rad kernel/kernel/abi.rad kernel/kernel/sys.rad $(RAD_BIN)
99
	@mkdir -p $(BIN_DIR)/user/root $(BIN_DIR)/user/scheduler
100
	@cp kernel/root.rad kernel/scheduler.rad $(BIN_DIR)/user/
101
	@cp kernel/kernel/abi.rad kernel/kernel/sys.rad $(BIN_DIR)/user/root/
102
	@cp kernel/kernel/abi.rad kernel/kernel/sys.rad kernel/mmio.rad $(BIN_DIR)/user/scheduler/
103
	@$(RADIANCE) -pkg root -mod $(BIN_DIR)/user/root.rad -mod $(BIN_DIR)/user/root/abi.rad -mod $(BIN_DIR)/user/root/sys.rad -entry root -ril $(BIN_DIR)
104
	@$(RADIANCE) -pkg scheduler -mod $(BIN_DIR)/user/scheduler.rad -mod $(BIN_DIR)/user/scheduler/abi.rad -mod $(BIN_DIR)/user/scheduler/sys.rad -mod $(BIN_DIR)/user/scheduler/mmio.rad -entry scheduler -ril $(BIN_DIR)
105
106
$(BIN_DIR)/kernel.rv64: $(BIN_DIR)/root.ril $(BIN_DIR)/scheduler.ril $(BIN_DIR)/std.ril $(BIN_DIR)/kernel.ril $(BIN_DIR)/kernel.build.rv64 $(KERNEL_ASM)
107
	@cat $(KERNEL_ASM) > $(BIN_DIR)/kernel.ras
108
	@$(EMU) $(EMU_FLAGS) -run $(BIN_DIR)/kernel.build.rv64 -- $(BIN_DIR)/std.ril $(BIN_DIR)/kernel.ril $(BIN_DIR)/kernel.ras $@ $(BIN_DIR)/root.ril $(BIN_DIR)/scheduler.ril
109
110
# Separate binary package emission and decode checks.
111
package-test: emulator $(BIN_DIR)/packages.check.rv64
112
	@sh test/packages/run
113
114
$(BIN_DIR)/packages.check.rv64: test/packages/check.rad $(STD_LIB) $(RAD_BIN)
115
	@$(RADIANCE) $(STD) -pkg check -mod $< -entry check -o $@
116
117
# Native image execution through the configured machine-capable emulator.
118
native-test: emulator $(BIN_DIR)/native.fixture.rv64
119
	@$(EMU) -machine -run $(BIN_DIR)/native.fixture.rv64
120
121
$(BIN_DIR)/native.build.rv64: test/native/build.rad $(STD_LIB) $(RAD_BIN)
122
	@$(RADIANCE) $(STD) -pkg build -mod $< -entry build -o $@
123
124
$(BIN_DIR)/native.fixture.rv64: $(BIN_DIR)/native.build.rv64
125
	@$(EMU) -run $< -- $@
126
127
# Shared package execution
128
129
shared-test: $(BIN_DIR)/shared.build.rv64
130
	@RAD_EMULATOR="$(EMU)" test/shared/run
131
132
$(BIN_DIR)/shared.build.rv64: test/shared/build.rad $(STD_LIB) $(RAD_BIN)
133
	@$(RADIANCE) $(STD) -pkg build -mod $< -entry build -o $@
134
135
# Kernel synchronization machine tests
136
137
sync-test: $(BIN_DIR)/sync.build.rv64
138
	@RAD_EMULATOR="$(EMU)" test/sync/run
139
140
$(BIN_DIR)/sync.build.rv64: test/sync/build.rad $(STD_LIB) $(RAD_BIN)
141
	@$(RADIANCE) $(STD) -pkg build -mod $< -entry build -o $@
142
143
# Binary Tests
144
145
BIN_TEST_DIR := test/tests
146
# Only tests with `//! returns:` are compiled to binaries and executed.
147
BIN_TEST_EXE_SRC := $(shell grep -rl '^//! returns:' $(BIN_TEST_DIR))
148
BIN_TEST_RAD_EXE_SRC := $(filter %.rad,$(BIN_TEST_EXE_SRC))
149
BIN_TEST_RAS_EXE_SRC := $(filter %.ras,$(BIN_TEST_EXE_SRC))
150
BIN_TEST_RAD_ASM_SRC := $(wildcard $(BIN_TEST_RAD_EXE_SRC:.rad=.ras))
151
BIN_TEST_RAD_START_SRC := $(wildcard $(BIN_TEST_RAD_EXE_SRC:.rad=.start.ras))
152
BIN_TEST_EXE_BIN := $(patsubst %.rad,%.rv64,$(BIN_TEST_RAD_EXE_SRC)) \
153
	$(patsubst %.ras,%.rv64,$(BIN_TEST_RAS_EXE_SRC))
154
BIN_RUNNER   := test/runner.rv64
155
BIN_TEST_RUN := test/run
156
157
bin-test: $(BIN_RUNNER) $(BIN_TEST_EXE_BIN)
158
	@echo
159
	@$(BIN_TEST_RUN)
160
161
# Runner binary: the lowering IL checker.
162
$(BIN_RUNNER): test/runner.rad $(STD_LIB) $(RAD_BIN)
163
	@echo "radiance test/runner.rad => $@"
164
	@$(RADIANCE) $(STD) -pkg runner -mod test/runner.rad -entry runner -o $@
165
166
# A `.rad` executable test can have a same-basename `.ras` module.
167
$(patsubst %.ras,%.rv64,$(BIN_TEST_RAD_ASM_SRC)): %.rv64: %.ras
168
$(patsubst %.start.ras,%.rv64,$(BIN_TEST_RAD_START_SRC)): %.rv64: %.start.ras
169
170
# Compile each executable test to a binary.
171
$(BIN_TEST_DIR)/%.rv64: $(BIN_TEST_DIR)/%.rad $(RAD_BIN)
172
	@echo "radiance $< => $@"
173
	@$(RADIANCE) -pkg test -mod $< $(patsubst %,-mod %,$(wildcard $(@:.rv64=)/*.rad)) $(patsubst %,-start %,$(wildcard $(@:.rv64=.start.ras))) $(patsubst %,-mod %,$(wildcard $(@:.rv64=.ras))) -o $@
174
175
$(BIN_TEST_DIR)/%.rv64: $(BIN_TEST_DIR)/%.ras $(BIN_RUNNER)
176
	@echo "asm $< => $@"
177
	@$(EMU) $(EMU_FLAGS) -run $(BIN_RUNNER) -- assemble $< $@
178
179
clean-bin-test:
180
	@rm -f $(BIN_RUNNER) \
181
		$(BIN_RUNNER:.rv64=.rv64.debug) \
182
		$(BIN_RUNNER:.rv64=.rv64.s) \
183
		$(BIN_RUNNER:.rv64=.rv64.o) \
184
		$(BIN_TEST_EXE_BIN) \
185
		$(wildcard $(BIN_TEST_DIR)/*.rv64.debug) \
186
		$(wildcard $(BIN_TEST_DIR)/*.rv64.s)
187
188
seed:
189
	seed/update
190
191
clean-rad:
192
	rm -rf bin/*
193
	rm -f seed/radiance.rv64.s[0-9]*
194
195
clean: clean-std-test clean-bin-test clean-rad
196
197
t: test
198
c: clean
199
200
.PHONY: test clean default seed-test std-test bin-test kernel-test package-test native-test shared-test sync-test seed \
201
	clean-std-test clean-bin-test clean-rad emulator
202
.SUFFIXES:
203
.DELETE_ON_ERROR:
204
.SILENT:
205
206
# Integer trap contexts and nested machine interrupts.
207
trap-test: $(BIN_DIR)/sync.build.rv64
208
	@RAD_EMULATOR="$(EMU)" sh test/trap/run
209
210
# Physical frame zeroing at native addresses.
211
page-test: $(BIN_DIR)/sync.build.rv64
212
	@RAD_EMULATOR="$(EMU)" sh test/pages/run
213
214
# Runtime package compilation and execution through the production kernel.
215
.PHONY: loader-test
216
loader-test: $(RAD_BIN) $(BIN_DIR)/kernel.build.rv64
217
	@RAD_EMULATOR="$(EMU)" sh test/loader/run
218
219
# Native preemption across user code, idle, and retained machine work.
220
.PHONY: dispatch-test
221
dispatch-test: $(RAD_BIN) $(BIN_DIR)/kernel.build.rv64
222
	@RAD_EMULATOR="$(EMU)" sh test/dispatch/run
223
224
# Concurrent user contexts and metadata transactions on every online hart.
225
.PHONY: smp-test
226
smp-test: $(RAD_BIN) $(BIN_DIR)/kernel.build.rv64
227
	@RAD_EMULATOR="$(EMU)" sh test/dispatch/run smp "1 2 8" 7
228
229
# User exit, abort, and CPU faults preserve the surviving parent's execution.
230
termination-test: emulator $(RAD_BIN) $(BIN_DIR)/kernel.build.rv64
231
	@RAD_EMULATOR="$(EMU)" sh test/dispatch/run termination
232
233
.PHONY: termination-test
234
235
# Scheduled compilation, cancellation, retry, and shared executable publication.
236
runtime-test: emulator $(RAD_BIN) $(BIN_DIR)/kernel.build.rv64
237
	@RAD_EMULATOR="$(EMU)" sh test/runtime/run
238
239
.PHONY: runtime-test
240
241
# Root lifetime and resource authority across the boot-package handoff.
242
bootstrap-test: emulator $(RAD_BIN) $(BIN_DIR)/kernel.build.rv64
243
	@RAD_EMULATOR="$(EMU)" sh test/bootstrap/run
244
245
.PHONY: bootstrap-test
246
247
# Production root and scheduler packages execute all authority changes in user mode.
248
.PHONY: scheduling-test
249
scheduling-test: $(BIN_DIR)/kernel.rv64
250
	@RAD_EMULATOR="$(EMU)" sh test/scheduling/run
251
252
# Checked user-mode register access, including rejection before device effects.
253
.PHONY: mmio-test
254
mmio-test: $(RAD_BIN) $(BIN_DIR)/kernel.build.rv64
255
	@RAD_EMULATOR="$(EMU)" sh test/dispatch/run mmio
256
257
# Physical source-line limits and fixed native image memory.
258
.PHONY: kernel-size-check
259
kernel-size-check: $(BIN_DIR)/kernel.rv64
260
	@python3 test/acceptance/sizes
261
262
# Full sibling-emulator and kernel validation with retained acceptance reports.
263
.PHONY: kernel-acceptance
264
kernel-acceptance:
265
	@sh test/acceptance/run
266
267
.PHONY: cycles-test
268
cycles-test: $(RAD_BIN) $(BIN_DIR)/kernel.build.rv64
269
	@RAD_EMULATOR="$(EMU)" sh test/cycles/run