Skip to content

Commit 85701c4

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 2e87a75 commit 85701c4

File tree

1 file changed

+32
-38
lines changed

1 file changed

+32
-38
lines changed

Makefile

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -352,54 +352,48 @@ EXPECTED_puzzle = success in 2005 trials
352352
EXPECTED_fcalc = Performed 12 tests, 0 failures, 100% success rate.
353353
EXPECTED_pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086
354354

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

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

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

394394
EXPECTED_mmu = STORE PAGE FAULT TEST PASSED!
395395
mmu-test: $(BIN)
396-
$(Q)$(PRINTF) "Running vm.elf ... "; \
397-
if [ "$(shell LC_ALL=C $(BIN) tests/system/mmu/vm.elf | tail -n 2)" = "$(strip $(EXPECTED_mmu)) inferior exit code 0" ]; then \
398-
$(call notice, [OK]); \
399-
else \
400-
$(PRINTF) "Failed.\n"; \
401-
exit 1; \
402-
fi;
396+
$(call check-test, , tests/system/mmu/vm.elf, vm.elf, tail -n 1, $(EXPECTED_mmu))
403397

404398
# Non-trivial demonstration programs
405399
ifeq ($(call has, SDL), 1)

0 commit comments

Comments
 (0)