Loading...
testing/lib/test_support.cpp dyld-955 dyld-832.7.3
--- dyld/dyld-955/testing/lib/test_support.cpp
+++ dyld/dyld-832.7.3/testing/lib/test_support.cpp
@@ -138,7 +138,6 @@
         Console,
         XCTest
     };
-    void emitBegin();
     void runLeaks();
     void dumpLogs();
     void getLogsString(char** buffer);
@@ -226,7 +225,7 @@
 }
 
 _process::_process() :  executablePath(nullptr), args(nullptr), env(nullptr), stdoutHandler(nullptr), stderrHandler(nullptr),
-                        crashHandler(nullptr), exitHandler(nullptr), arch(currentArch), suspended(false) {}
+                        crashHandler(nullptr), exitHandler(nullptr), pid(0), arch(currentArch), suspended(false), async(false) {}
 _process::~_process() {
     if (stdoutHandler) { Block_release(stdoutHandler);}
     if (stderrHandler) { Block_release(stderrHandler);}
@@ -242,6 +241,7 @@
 void _process::set_exit_handler(_dyld_test_exit_handler_t EH) { exitHandler = Block_copy(EH); }
 void _process::set_crash_handler(_dyld_test_crash_handler_t CH) { crashHandler = Block_copy(CH); }
 void _process::set_launch_suspended(bool S) { suspended = S; }
+void _process::set_launch_async(bool S) { async = S; }
 void _process::set_launch_arch(cpu_type_t A) { arch = A; }
 
 pid_t _process::launch() {
@@ -377,6 +377,9 @@
     posix_spawnattr_destroy(&attr);
     if (!suspended) {
         kill(pid, SIGCONT);
+    }
+    if (!async) {
+        dispatch_block_wait(oneShotSemaphoreBlock, DISPATCH_TIME_FOREVER);
     }
     Block_release(oneShotSemaphoreBlock);
     dispatch_release(queue);
@@ -495,15 +498,12 @@
             }
         }
     });
-}
-
-void TestState::emitBegin() {
     if (output == BATS) {
         printf("[BEGIN]");
         if (checkForLeaks) {
             printf(" MallocStackLogging=1 MallocDebugReport=none");
         }
-        forEachEnvVar(environ, [](const char* env, const char* val) {
+        forEachEnvVar(environ, [this](const char* env, const char* val) {
             if ((strncmp(env, "DYLD_", 5) == 0) || (strncmp(env, "TEST_", 5) == 0)) {
                 printf(" %s=%s", env, val);
             }
@@ -546,23 +546,21 @@
                 if(!state->compare_exchange_strong(expected, newState)) {
                     newState->~TestState();
                     free(temp);
-                } else {
-                    newState->emitBegin();
                 }
             }
             sState.store(*state);
-            break; // don't print [BEGIN] if a second main executeable is dlopen()ed
         }
     }
     assert(sState != nullptr);
     return sState;
 }
+
 __attribute__((noreturn))
 void TestState::runLeaks(void) {
     auto testState = TestState::getState();
-    pid_t currentPid = getpid();
+    pid_t pid = getpid();
     char pidString[32];
-    sprintf(&pidString[0], "%d", currentPid);
+    sprintf(&pidString[0], "%d", pid);
     if (getuid() != 0) {
         printf("Insufficient priviledges, skipping Leak check: %s\n", testState->testName);
         exit(0);
@@ -616,7 +614,7 @@
     if (checkForLeaks) {
         runLeaks();
     } else {
-        _IOlock.withLock([this,&format,&args](){
+        _IOlock.withLock([this,&format,&args,&file,&line](){
             if (output == Console) {
                 printf("[\033[0;32mPASS\033[0m] %s: ", testName);
                 vprintf(format, args);