Separate ASSIGN_TEST from NEXT_TEST

Silences a warning about an invalid pointer when building with modern.
This commit is contained in:
Martin Griffin 2023-10-23 06:57:57 +01:00
parent 6e7e7fdafa
commit b0b6e16042
2 changed files with 22 additions and 7 deletions

View File

@ -47,6 +47,7 @@ struct TestRunnerState
u8 expectedResult;
bool8 expectLeaks:1;
bool8 inBenchmark:1;
bool8 tearDown:1;
u32 timeoutSeconds;
};

View File

@ -56,9 +56,10 @@ static bool32 PrefixMatch(const char *pattern, const char *string)
enum
{
STATE_INIT,
STATE_NEXT_TEST,
STATE_ASSIGN_TEST,
STATE_RUN_TEST,
STATE_REPORT_RESULT,
STATE_NEXT_TEST,
STATE_EXIT,
};
@ -152,17 +153,15 @@ void CB2_TestRunner(void)
}
else
{
gTestRunnerState.state = STATE_NEXT_TEST;
gTestRunnerState.test = __start_tests - 1;
gTestRunnerState.state = STATE_ASSIGN_TEST;
gTestRunnerState.test = __start_tests;
}
gTestRunnerState.exitCode = 0;
gTestRunnerState.skipFilename = NULL;
break;
case STATE_NEXT_TEST:
gTestRunnerState.test++;
case STATE_ASSIGN_TEST:
if (gTestRunnerState.test == __stop_tests)
{
gTestRunnerState.state = STATE_EXIT;
@ -172,6 +171,7 @@ void CB2_TestRunner(void)
if (gTestRunnerState.test->runner != &gAssumptionsRunner
&& !PrefixMatch(gTestRunnerArgv, gTestRunnerState.test->name))
{
gTestRunnerState.state = STATE_NEXT_TEST;
return;
}
@ -191,6 +191,8 @@ void CB2_TestRunner(void)
sCurrentTest.address = (uintptr_t)gTestRunnerState.test;
sCurrentTest.state = CURRENT_TEST_STATE_ESTIMATE;
// If AssignCostToRunner fails, we want to report the failure.
gTestRunnerState.state = STATE_REPORT_RESULT;
if (AssignCostToRunner() == gTestRunnerI)
gTestRunnerState.state = STATE_RUN_TEST;
else
@ -204,7 +206,10 @@ void CB2_TestRunner(void)
SeedRng(0);
SeedRng2(0);
if (gTestRunnerState.test->runner->setUp)
{
gTestRunnerState.test->runner->setUp(gTestRunnerState.test->data);
gTestRunnerState.tearDown = TRUE;
}
// NOTE: Assumes that the compiler interns __FILE__.
if (gTestRunnerState.skipFilename == gTestRunnerState.test->filename) // Assumption fails for tests in this file.
{
@ -216,13 +221,17 @@ void CB2_TestRunner(void)
gTestRunnerState.test->runner->run(gTestRunnerState.test->data);
}
break;
case STATE_REPORT_RESULT:
REG_TM2CNT_H = 0;
gTestRunnerState.state = STATE_NEXT_TEST;
if (gTestRunnerState.test->runner->tearDown)
if (gTestRunnerState.tearDown && gTestRunnerState.test->runner->tearDown)
{
gTestRunnerState.test->runner->tearDown(gTestRunnerState.test->data);
gTestRunnerState.tearDown = FALSE;
}
if (gTestRunnerState.result == TEST_RESULT_PASS
&& !gTestRunnerState.expectLeaks)
@ -342,6 +351,11 @@ void CB2_TestRunner(void)
break;
case STATE_NEXT_TEST:
gTestRunnerState.state = STATE_ASSIGN_TEST;
gTestRunnerState.test++;
break;
case STATE_EXIT:
MgbaExit_(gTestRunnerState.exitCode);
break;