From 0551e382b3ec064c8bbc06779713f6b9ce45c9cf Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 25 Sep 2024 08:10:05 -0400 Subject: [PATCH] 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. --- .../CHIPTests/TestHelpers/MTRTestCase.mm | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestCase.mm b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestCase.mm index ee036574734b2b..915df782be4f43 100644 --- a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestCase.mm +++ b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestCase.mm @@ -73,17 +73,28 @@ - (void)tearDown int pid = getpid(); __auto_type * cmd = [NSString stringWithFormat:@"leaks %d", pid]; int ret = system(cmd.UTF8String); - if (WIFEXITED(ret)) { - // leaks ran to completion. - XCTAssertEqual(WEXITSTATUS(ret), 0, "LEAKS DETECTED"); - } else { - // leaks failed to actually run to completion (e.g. crashed or ran - // into some other sort of failure trying to do its work). Ideally - // we would fail our tests in that case, but this seems to be - // happening a fair amount, and randomly, on the ARM GitHub runners. + if (WIFSIGNALED(ret)) { + XCTFail(@"leaks unexpectedly stopped by signal %d", WTERMSIG(ret)); + } + XCTAssertTrue(WIFEXITED(ret), "leaks did not run to completion"); + // The exit status is 0 if no leaks detected, 1 if leaks were detected, + // something else on error. + if (WEXITSTATUS(ret) == 1) { + XCTFail(@"LEAKS DETECTED"); + } else if (WEXITSTATUS(ret) != 0) { + // leaks failed to actually run correctly. Ideally we would fail + // our tests in that case, but this seems to be happening a fair + // amount, and randomly, on the ARM GitHub runners, with errors + // like: + // + // *** getStackLoggingSharedMemoryAddressFromTask: couldn't find ___mach_stack_logging_shared_memory_address in target task + // *** task_malloc_get_all_zones: error 1 reading num_zones at 0 + // *** task_malloc_get_all_zones: error 1 reading num_zones at 0 + // *** task_malloc_get_all_zones: error 1 reading num_zones at 0 + // [fatal] unable to instantiate a memory scanner. + // // Just log and ignore for now. - XCTAssertFalse(WIFSTOPPED(ret), "Not expecting a stopped leaks"); - NSLog(@"Stopped by signal %d", WTERMSIG(ret)); + NSLog(@"leaks failed to run, exit status: %d", WEXITSTATUS(ret)); } } #endif