[Testing] Make sure tests clean up shm resources on exit

This commit is contained in:
Herman S.
2025-11-25 13:17:30 +09:00
parent 532418eed4
commit 435ea98a5a

View File

@@ -431,15 +431,20 @@ TestResult RunTestInChildProcess(TestSuite& test_suite, TestCase& test_case) {
if (pid == 0) {
// Child process - create a fresh TestRunner to avoid inherited state issues
TestRunner child_runner;
if (!child_runner.Setup(test_suite)) {
_exit(2); // Setup failure
}
if (child_runner.Run(test_case)) {
_exit(0); // Test passed
} else {
_exit(1); // Test failed
}
// Use a scope block to ensure destructors run before _exit(),
// otherwise shared memory objects in /dev/shm are never cleaned up.
int exit_code;
{
TestRunner child_runner;
if (!child_runner.Setup(test_suite)) {
exit_code = 2; // Setup failure
} else if (child_runner.Run(test_case)) {
exit_code = 0; // Test passed
} else {
exit_code = 1; // Test failed
}
} // child_runner destructor runs here, cleaning up shm
_exit(exit_code);
}
// Parent process - wait for child