From 3a5ca6f8f0b4fd345cf134a04b37361f8f2f776f Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Wed, 20 Dec 2023 16:33:45 +0000 Subject: [PATCH] Small test runner improvements (#3761) * u16 for FunctionTest PARAMETRIZE * Speed up CB2_TestRunner * Use DACS to handle illegal instructions DACS is available in mgba from https://github.com/mgba-emu/mgba/commit/44e074a15e9651481f7f652ac006a7c9d58cbeb9 This is not 0.10.2, but will presumably be available in the next release. Alternatively, a GBA BIOS could be used. --------- Co-authored-by: DizzyEggg Co-authored-by: Bassoonian --- Makefile | 2 +- include/test/test.h | 4 ++-- ld_script_test.ld | 6 ++++++ test/species.c | 2 ++ test/test_runner.c | 27 +++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index db883cb60c..d899015225 100644 --- a/Makefile +++ b/Makefile @@ -495,7 +495,7 @@ $(OBJ_DIR)/ld_script_test.ld: $(LD_SCRIPT_TEST) $(LD_SCRIPT_DEPS) $(TESTELF): $(OBJ_DIR)/ld_script_test.ld $(OBJS) $(TEST_OBJS) libagbsyscall tools check-tools @echo "cd $(OBJ_DIR) && $(LD) -T ld_script_test.ld -o ../../$@ " @cd $(OBJ_DIR) && $(LD) $(TESTLDFLAGS) -T ld_script_test.ld -o ../../$@ $(OBJS_REL) $(TEST_OBJS_REL) $(LIB) - $(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent + $(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) -d0 --silent $(PATCHELF) $(TESTELF) gTestRunnerArgv "$(TESTS)\0" ifeq ($(GITHUB_REPOSITORY_OWNER),rh-hideout) diff --git a/include/test/test.h b/include/test/test.h index e9c920bd0b..918d00399b 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -59,8 +59,8 @@ extern const struct TestRunner gAssumptionsRunner; struct FunctionTestRunnerState { - u8 parameters; - u8 runParameter; + u16 parameters; + u16 runParameter; }; extern const struct TestRunner gFunctionTestRunner; diff --git a/ld_script_test.ld b/ld_script_test.ld index b86302f8cb..49a0ec35b0 100644 --- a/ld_script_test.ld +++ b/ld_script_test.ld @@ -109,6 +109,12 @@ SECTIONS { __rom_end = .; + dacs 0x9FFC000 : + ALIGN(4) + { + test/*.o(.dacs); + } > ROM =0 + /* DWARF debug sections. Symbols in the DWARF debugging sections are relative to the beginning of the section so we begin them at 0. */ diff --git a/test/species.c b/test/species.c index 9ea20638c8..d412dd005a 100644 --- a/test/species.c +++ b/test/species.c @@ -34,6 +34,8 @@ TEST("Form change tables contain only forms in the form species ID table") for (i = 0; formChangeTable[i].method != FORM_CHANGE_TERMINATOR; i++) { + if (formChangeTable[i].targetSpecies == SPECIES_NONE) + continue; for (j = 0; formSpeciesIdTable[j] != FORM_SPECIES_END; j++) { if (formChangeTable[i].targetSpecies == formSpeciesIdTable[j]) diff --git a/test/test_runner.c b/test/test_runner.c index 93d859654a..5ca397cd6c 100644 --- a/test/test_runner.c +++ b/test/test_runner.c @@ -106,6 +106,8 @@ static u32 AssignCostToRunner(void) void CB2_TestRunner(void) { +top: + switch (gTestRunnerState.state) { case STATE_INIT: @@ -361,6 +363,9 @@ void CB2_TestRunner(void) MgbaExit_(gTestRunnerState.exitCode); break; } + + if (gMain.callback2 == CB2_TestRunner) + goto top; } void Test_ExpectedResult(enum TestResult result) @@ -652,3 +657,25 @@ static s32 MgbaVPrintf_(const char *fmt, va_list va) } return i; } + +/* Entry point for the Debugging and Control System. Handles illegal + * instructions, which are typically caused by branching to an invalid + * address. */ +__attribute__((naked, section(".dacs"), target("arm"))) +void DACSEntry(void) +{ + asm(".arm\n\ + ldr r0, =(DACSHandle + 1)\n\ + bx r0\n"); +} + +#define DACS_LR (*(vu32 *)0x3007FEC) + +void DACSHandle(void) +{ + if (gTestRunnerState.state == STATE_RUN_TEST) + gTestRunnerState.state = STATE_REPORT_RESULT; + gTestRunnerState.result = TEST_RESULT_CRASH; + ReinitCallbacks(); + DACS_LR = ((uintptr_t)JumpToAgbMainLoop & ~1) + 4; +}