Skip to content

Commit 0551e38

Browse files
Fix "leaks" return status checking.
Looks like when "leaks" hits the CI failures it actually runs to completion but returns an error status that is not 1, instead of being signaled. Adjust the workaround logic to account for this.
1 parent 34c0fe1 commit 0551e38

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/darwin/Framework/CHIPTests/TestHelpers/MTRTestCase.mm

+21-10
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,28 @@ - (void)tearDown
7373
int pid = getpid();
7474
__auto_type * cmd = [NSString stringWithFormat:@"leaks %d", pid];
7575
int ret = system(cmd.UTF8String);
76-
if (WIFEXITED(ret)) {
77-
// leaks ran to completion.
78-
XCTAssertEqual(WEXITSTATUS(ret), 0, "LEAKS DETECTED");
79-
} else {
80-
// leaks failed to actually run to completion (e.g. crashed or ran
81-
// into some other sort of failure trying to do its work). Ideally
82-
// we would fail our tests in that case, but this seems to be
83-
// happening a fair amount, and randomly, on the ARM GitHub runners.
76+
if (WIFSIGNALED(ret)) {
77+
XCTFail(@"leaks unexpectedly stopped by signal %d", WTERMSIG(ret));
78+
}
79+
XCTAssertTrue(WIFEXITED(ret), "leaks did not run to completion");
80+
// The exit status is 0 if no leaks detected, 1 if leaks were detected,
81+
// something else on error.
82+
if (WEXITSTATUS(ret) == 1) {
83+
XCTFail(@"LEAKS DETECTED");
84+
} else if (WEXITSTATUS(ret) != 0) {
85+
// leaks failed to actually run correctly. Ideally we would fail
86+
// our tests in that case, but this seems to be happening a fair
87+
// amount, and randomly, on the ARM GitHub runners, with errors
88+
// like:
89+
//
90+
// *** getStackLoggingSharedMemoryAddressFromTask: couldn't find ___mach_stack_logging_shared_memory_address in target task
91+
// *** task_malloc_get_all_zones: error 1 reading num_zones at 0
92+
// *** task_malloc_get_all_zones: error 1 reading num_zones at 0
93+
// *** task_malloc_get_all_zones: error 1 reading num_zones at 0
94+
// [fatal] unable to instantiate a memory scanner.
95+
//
8496
// Just log and ignore for now.
85-
XCTAssertFalse(WIFSTOPPED(ret), "Not expecting a stopped leaks");
86-
NSLog(@"Stopped by signal %d", WTERMSIG(ret));
97+
NSLog(@"leaks failed to run, exit status: %d", WEXITSTATUS(ret));
8798
}
8899
}
89100
#endif

0 commit comments

Comments
 (0)