Loading...
testing/lib/test_support.cpp dyld-852 dyld-832.7.3
--- dyld/dyld-852/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), pid(0), 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,10 +241,12 @@
 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() {
     dispatch_queue_t queue = dispatch_queue_create("com.apple.dyld.test.launch", NULL);
+    dispatch_block_t oneShotSemaphoreBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{});
     posix_spawn_file_actions_t fileActions = NULL;
     posix_spawnattr_t attr = NULL;
     dispatch_source_t stdoutSource = NULL;
@@ -359,6 +360,7 @@
         if (stderrSource) {
             dispatch_source_cancel(stderrSource);
         }
+        oneShotSemaphoreBlock();
         dispatch_source_cancel(exitSource);
     });
     dispatch_resume(exitSource);
@@ -376,6 +378,10 @@
     if (!suspended) {
         kill(pid, SIGCONT);
     }
+    if (!async) {
+        dispatch_block_wait(oneShotSemaphoreBlock, DISPATCH_TIME_FOREVER);
+    }
+    Block_release(oneShotSemaphoreBlock);
     dispatch_release(queue);
     return pid;
 }
@@ -492,9 +498,6 @@
             }
         }
     });
-}
-
-void TestState::emitBegin() {
     if (output == BATS) {
         printf("[BEGIN]");
         if (checkForLeaks) {
@@ -543,8 +546,6 @@
                 if(!state->compare_exchange_strong(expected, newState)) {
                     newState->~TestState();
                     free(temp);
-                } else {
-                    newState->emitBegin();
                 }
             }
             sState.store(*state);