From 7f52fca8fe6dd376c5b1b08298570883377156d0 Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Thu, 31 Oct 2024 12:56:06 +0000 Subject: [PATCH] Hydra: Support %p in test summaries (#5626) --- test/test_runner_battle.c | 12 ++++++------ tools/mgba-rom-test-hydra/main.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/test_runner_battle.c b/test/test_runner_battle.c index b3f88b84a3..ae86f87ab4 100644 --- a/test/test_runner_battle.c +++ b/test/test_runner_battle.c @@ -379,7 +379,7 @@ u32 RandomUniform(enum RandomTag tag, u32 lo, u32 hi) } else if (STATE->trials != n) { - Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomUniform called with inconsistent trials %d and %d", STATE->trials, n); + Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomUniform called from %p with tag %d and inconsistent trials %d and %d", __builtin_extract_return_addr(__builtin_return_address(0)), tag, STATE->trials, n); } STATE->trialRatio = Q_4_12(1) / STATE->trials; return STATE->runTrial + lo; @@ -421,7 +421,7 @@ u32 RandomUniformExcept(enum RandomTag tag, u32 lo, u32 hi, bool32 (*reject)(u32 while (reject(STATE->runTrial + lo + STATE->rngTrialOffset)) { if (STATE->runTrial + lo + STATE->rngTrialOffset > hi) - Test_ExitWithResult(TEST_RESULT_INVALID, SourceLine(0), ":LRandomUniformExcept called with inconsistent reject"); + Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomUniformExcept called from %p with tag %d and inconsistent reject", __builtin_extract_return_addr(__builtin_return_address(0)), tag); STATE->rngTrialOffset++; } @@ -432,7 +432,7 @@ u32 RandomUniformExcept(enum RandomTag tag, u32 lo, u32 hi, bool32 (*reject)(u32 while (reject(default_)) { if (default_ == lo) - Test_ExitWithResult(TEST_RESULT_INVALID, SourceLine(0), ":LRandomUniformExcept rejected all values"); + Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomUniformExcept called from %p with tag %d rejected all values", __builtin_extract_return_addr(__builtin_return_address(0)), tag); default_--; } return default_; @@ -462,7 +462,7 @@ u32 RandomWeightedArray(enum RandomTag tag, u32 sum, u32 n, const u8 *weights) } else if (STATE->trials != n) { - Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomWeighted called with inconsistent trials %d and %d", STATE->trials, n); + Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomWeighted called from %p with tag %d and inconsistent trials %d and %d", __builtin_extract_return_addr(__builtin_return_address(0)), tag, STATE->trials, n); } // TODO: Detect inconsistent sum. STATE->trialRatio = Q_4_12(weights[STATE->runTrial]) / sum; @@ -496,7 +496,7 @@ u32 RandomWeightedArray(enum RandomTag tag, u32 sum, u32 n, const u8 *weights) while (weights[n-1] == 0) { if (n == 1) - Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomWeightedArray called with all zero weights"); + Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomWeightedArray called from %p with tag %d and all zero weights", __builtin_extract_return_addr(__builtin_return_address(0)), tag); n--; } return n-1; @@ -535,7 +535,7 @@ const void *RandomElementArray(enum RandomTag tag, const void *array, size_t siz } else if (STATE->trials != count) { - Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomElement called with inconsistent trials %d and %d", STATE->trials, count); + Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":LRandomElement called from %p with tag %d and inconsistent trials %d and %d", __builtin_extract_return_addr(__builtin_return_address(0)), tag, STATE->trials, count); } STATE->trialRatio = Q_4_12(1) / count; return (const u8 *)array + size * STATE->runTrial; diff --git a/tools/mgba-rom-test-hydra/main.c b/tools/mgba-rom-test-hydra/main.c index d4c0f4e080..55ba664e75 100644 --- a/tools/mgba-rom-test-hydra/main.c +++ b/tools/mgba-rom-test-hydra/main.c @@ -812,7 +812,9 @@ int main(int argc, char *argv[]) fprintf(stdout, " - \e[31mand %d more...\e[0m\n", fails - MAX_SUMMARY_TESTS_TO_LIST); break; } - fprintf(stdout, " - \e[31m%s\e[0m - %s.\n", failed_TestFilenameLine[i], failed_TestNames[i]); + fprintf(stdout, " - \e[31m"); + fprint_buffer(stdout, failed_TestFilenameLine[i], strlen(failed_TestFilenameLine[i])); + fprintf(stdout, "\e[0m - %s.\n", failed_TestNames[i]); } } @@ -826,7 +828,9 @@ int main(int argc, char *argv[]) fprintf(stdout, " - \e[33mand %d more...\e[0m\n", assumptionFails - MAX_SUMMARY_TESTS_TO_LIST); break; } - fprintf(stdout, " - \e[33m%s\e[0m - %s.\n", assumeFailed_FilenameLine[i], assumeFailed_TestNames[i]); + fprintf(stdout, " - \e[33m"); + fprint_buffer(stdout, assumeFailed_FilenameLine[i], strlen(assumeFailed_FilenameLine[i])); + fprintf(stdout, "\e[0m - %s.\n", assumeFailed_TestNames[i]); } } @@ -840,7 +844,9 @@ int main(int argc, char *argv[]) fprintf(stdout, " - \e[32mand %d more...\e[0m\n", knownFailsPassing - MAX_SUMMARY_TESTS_TO_LIST); break; } - fprintf(stdout, " - \e[32m%s\e[0m - %s.\n", knownFailingPassed_FilenameLine[i], knownFailingPassed_TestNames[i]); + fprintf(stdout, " - \e[32m"); + fprint_buffer(stdout, knownFailingPassed_FilenameLine[i], strlen(knownFailingPassed_FilenameLine[i])); + fprintf(stdout, "\e[0m - %s.\n", knownFailingPassed_TestNames[i]); } }