Skip to content

Commit d8912c4

Browse files
committed
Refine check recipe in Makefile
Since the newly introduced logging APIs generate logs during runtime, the check recipe must filter out this log information before validation. Additionally, refine the check recipe into a new target, check-test, which serves as a template to enhance readability.
1 parent a841b40 commit d8912c4

File tree

1 file changed

+33
-38
lines changed

1 file changed

+33
-38
lines changed

Makefile

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ OBJS := \
293293
syscall.o \
294294
emulate.o \
295295
riscv.o \
296+
log.o \
296297
elf.o \
297298
cache.o \
298299
mpool.o \
@@ -347,54 +348,48 @@ EXPECTED_puzzle = success in 2005 trials
347348
EXPECTED_fcalc = Performed 12 tests, 0 failures, 100% success rate.
348349
EXPECTED_pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086
349350

351+
LOG_FILTER=sed -E '/^[0-9]{2}:[0-9]{2}:[0-9]{2} /d'
352+
353+
define exec
354+
$(eval OUTPUT_FILE := $(shell mktemp))
355+
$(eval _ := $(shell LC_ALL=C $(BIN) $(1) $(2) > $(OUTPUT_FILE)))
356+
$(eval RC := $(.SHELLSTATUS))
357+
endef
358+
359+
# $(1): rv32emu's extra CLI parameter
360+
# $(2): ELF executable
361+
# $(3): ELF executable name
362+
# $(4): extra command in the pipeline
363+
# $(5): expected output
364+
define check-test
365+
$(call exec, $(1), $(2))
366+
$(Q)$(PRINTF) "Running $(3) ... "; \
367+
if [ 0 -eq $(RC) ] && [ "$(strip $(shell cat $(OUTPUT_FILE) | $(LOG_FILTER) | $(4)))" = "$(strip $(5))" ]; then \
368+
$(call notice, [OK]); \
369+
else \
370+
$(PRINTF) "Failed.\n"; \
371+
exit 1; \
372+
fi; \
373+
$(RM) $(OUTPUT_FILE)
374+
endef
375+
350376
check-hello: $(BIN)
351-
$(Q)$(PRINTF) "Running hello.elf ... "; \
352-
if [ "$(shell LC_ALL=C $(BIN) $(OUT)/hello.elf | uniq)" = "$(strip $(EXPECTED_hello)) inferior exit code 0" ]; then \
353-
$(call notice, [OK]); \
354-
else \
355-
$(PRINTF) "Failed.\n"; \
356-
exit 1; \
357-
fi;
377+
$(call check-test, , $(OUT)/hello.elf, hello.elf, uniq, $(EXPECTED_hello))
358378

359379
check: $(BIN) check-hello artifact
360-
$(Q)$(foreach e,$(CHECK_ELF_FILES),\
361-
$(PRINTF) "Running $(e) ... "; \
362-
if [ "$(shell LC_ALL=C $(BIN) $(OUT)/riscv32/$(e) | uniq)" = "$(strip $(EXPECTED_$(e))) inferior exit code 0" ]; then \
363-
$(call notice, [OK]); \
364-
else \
365-
$(PRINTF) "Failed.\n"; \
366-
exit 1; \
367-
fi; \
368-
)
369-
370-
EXPECTED_aes_sha1 = 1242a6757c8aef23e50b5264f5941a2f4b4a347e -
380+
$(Q)$(foreach e, $(CHECK_ELF_FILES), $(call check-test, , $(OUT)/riscv32/$(e), $(e), uniq, $(EXPECTED_$(e))))
381+
382+
EXPECTED_aes_sha1 = 89169ec034bec1c6bb2c556b26728a736d350ca3 -
371383
misalign: $(BIN) artifact
372-
$(Q)$(PRINTF) "Running uaes ... ";
373-
$(Q)if [ "$(shell LC_ALL=C $(BIN) -m $(OUT)/riscv32/uaes | $(SHA1SUM))" = "$(EXPECTED_aes_sha1)" ]; then \
374-
$(call notice, [OK]); \
375-
else \
376-
$(PRINTF) "Failed.\n"; \
377-
fi
384+
$(call check-test, -m, $(OUT)/riscv32/uaes, uaes.elf, $(SHA1SUM), $(EXPECTED_aes_sha1))
378385

379386
EXPECTED_misalign = MISALIGNED INSTRUCTION FETCH TEST PASSED!
380387
misalign-in-blk-emu: $(BIN)
381-
$(Q)$(PRINTF) "Running misalign.elf ... "; \
382-
if [ "$(shell LC_ALL=C $(BIN) tests/system/alignment/misalign.elf | tail -n 2)" = "$(strip $(EXPECTED_misalign)) inferior exit code 0" ]; then \
383-
$(call notice, [OK]); \
384-
else \
385-
$(PRINTF) "Failed.\n"; \
386-
exit 1; \
387-
fi;
388+
$(call check-test, , tests/system/alignment/misalign.elf, misalign.elf, tail -n 1, $(EXPECTED_misalign))
388389

389390
EXPECTED_mmu = STORE PAGE FAULT TEST PASSED!
390391
mmu-test: $(BIN)
391-
$(Q)$(PRINTF) "Running vm.elf ... "; \
392-
if [ "$(shell LC_ALL=C $(BIN) tests/system/mmu/vm.elf | tail -n 2)" = "$(strip $(EXPECTED_mmu)) inferior exit code 0" ]; then \
393-
$(call notice, [OK]); \
394-
else \
395-
$(PRINTF) "Failed.\n"; \
396-
exit 1; \
397-
fi;
392+
$(call check-test, , tests/system/mmu/vm.elf, vm.elf, tail -n 1, $(EXPECTED_mmu))
398393

399394
# Non-trivial demonstration programs
400395
ifeq ($(call has, SDL), 1)

0 commit comments

Comments
 (0)