summaryrefslogtreecommitdiff
path: root/tools/slang-test/slang-test-main.cpp
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2025-05-06 12:49:27 +0000
committerGitHub <noreply@github.com>2025-05-06 05:49:27 -0700
commitb0187cdb13ebbf1eaaf101cbfe8860a73280d644 (patch)
tree75eb5fbaa14726089540ebac1c8c3241b1d11a1e /tools/slang-test/slang-test-main.cpp
parent91425ccb6ff0a416b67ef21eb3ecebb49ba3e748 (diff)
Retry when a few unit tests failed. (#6912)
This PR allows the failed unit-tests to be retried at the end as in a single threaded manner. The purpose of the retry is to increase the stability of CI.
Diffstat (limited to 'tools/slang-test/slang-test-main.cpp')
-rw-r--r--tools/slang-test/slang-test-main.cpp59
1 files changed, 43 insertions, 16 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 1fb70ed03..42432e328 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -4452,7 +4452,7 @@ static SlangResult _runTestsOnFile(TestContext* context, String filePath)
fileTestInfo->outputStem = outputStem;
fileTestInfo->options = testDetails.options;
- std::lock_guard lock(context->mutexFailedFileTests);
+ std::lock_guard lock(context->mutexFailedTests);
context->failedFileTests.add(fileTestInfo);
}
else
@@ -4747,17 +4747,28 @@ static SlangResult runUnitTestModule(
TestServerProtocol::ExecuteUnitTestArgs::g_methodName,
&args,
exeRes);
- const auto testResult = _asTestResult(ToolReturnCode(exeRes.resultCode));
+ auto testResult = _asTestResult(ToolReturnCode(exeRes.resultCode));
+
+ bool isFailed = (SLANG_FAILED(rpcRes) || testResult == TestResult::Fail);
// If the test fails, output any output - which might give information about
// individual tests that have failed.
- if (SLANG_FAILED(rpcRes) || testResult == TestResult::Fail)
+ if (isFailed)
{
String output = getOutput(exeRes);
reporter->message(TestMessageType::TestFailure, output.getBuffer());
}
- reporter->addResult(testResult);
+ if (isFailed && !context->isRetry &&
+ !context->getTestReporter()->m_expectedFailureList.contains(test.testName))
+ {
+ std::lock_guard lock(context->mutexFailedTests);
+ context->failedUnitTests.add(test.command);
+ }
+ else
+ {
+ reporter->addResult(testResult);
+ }
}
}
else
@@ -5031,20 +5042,36 @@ SlangResult innerMain(int argc, char** argv)
TestReporter::SuiteScope suiteScope(&reporter, "unit tests");
TestReporter::set(&reporter);
- const auto spawnType = context.getFinalSpawnType();
-
- // Run the unit tests
+ for (bool isRetry : {false, true})
{
- TestOptions testOptions;
- testOptions.categories.add(unitTestCategory);
- testOptions.categories.add(smokeTestCategory);
- runUnitTestModule(&context, testOptions, spawnType, "slang-unit-test-tool");
- }
+ auto spawnType = context.getFinalSpawnType();
- {
- TestOptions testOptions;
- testOptions.categories.add(unitTestCategory);
- runUnitTestModule(&context, testOptions, spawnType, "gfx-unit-test-tool");
+ context.isRetry = false;
+ if (isRetry)
+ {
+ if (context.failedUnitTests.getCount() == 0)
+ break;
+
+ printf("Retrying unit tests...\n");
+ context.isRetry = true;
+ context.options.testPrefixes = context.failedUnitTests;
+ context.failedUnitTests.clear();
+ spawnType = SpawnType::Default;
+ }
+
+ // Run the unit tests
+ {
+ TestOptions testOptions;
+ testOptions.categories.add(unitTestCategory);
+ testOptions.categories.add(smokeTestCategory);
+ runUnitTestModule(&context, testOptions, spawnType, "slang-unit-test-tool");
+ }
+
+ {
+ TestOptions testOptions;
+ testOptions.categories.add(unitTestCategory);
+ runUnitTestModule(&context, testOptions, spawnType, "gfx-unit-test-tool");
+ }
}
TestReporter::set(nullptr);