TestHelloWorld: Use a file on the target platform for synchronisation.

Thanks to Pavel Labath for the idea!

git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@349550 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py b/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
index 543299e..0f14b10 100644
--- a/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
+++ b/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
@@ -10,8 +10,7 @@
 import lldb
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-
+import lldbsuite.test.lldbutil as lldbutil
 
 class HelloWorldTestCase(TestBase):
     NO_DEBUG_INFO_TESTCASE = True
@@ -88,8 +87,12 @@
         target = self.dbg.CreateTarget(exe)
 
         # Spawn a new process
-        popen = self.spawnSubprocess(exe, ["abc", "xyz"])
+        token = exe+'.token'
+        if os.path.exists(token):
+            os.remove(token)
+        popen = self.spawnSubprocess(exe, [token])
         self.addTearDownHook(self.cleanupSubprocesses)
+        lldbutil.wait_for_file_on_target(self, token)
 
         listener = lldb.SBListener("my.attach.listener")
         error = lldb.SBError()
@@ -98,11 +101,10 @@
         self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
 
         # Let's check the stack traces of the attached process.
-        import lldbsuite.test.lldbutil as lldbutil
         stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
         self.expect(stacktraces, exe=False,
                     substrs=['main.c:%d' % self.line2,
-                             '(int)argc=3'])
+                             '(int)argc=2'])
 
     @add_test_categories(['pyapi'])
     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24600")
@@ -115,9 +117,13 @@
         self.setTearDownCleanup(dictionary=d)
         target = self.dbg.CreateTarget(exe)
 
-        # Spawn a new process
-        popen = self.spawnSubprocess(exe, ["abc", "xyz"])
+        # Spawn a new process.
+        token = exe+'.token'
+        if os.path.exists(token):
+            os.remove(token)
+        popen = self.spawnSubprocess(exe, [token])
         self.addTearDownHook(self.cleanupSubprocesses)
+        lldbutil.wait_for_file_on_target(self, token)
 
         listener = lldb.SBListener("my.attach.listener")
         error = lldb.SBError()
@@ -132,7 +138,6 @@
         target.ConnectRemote(listener, None, None, error)
 
         process = target.AttachToProcessWithName(listener, name, False, error)
-
         self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
 
         # Verify that after attach, our selected target indeed matches name.
@@ -142,8 +147,7 @@
             startstr=name)
 
         # Let's check the stack traces of the attached process.
-        import lldbsuite.test.lldbutil as lldbutil
         stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
         self.expect(stacktraces, exe=False,
                     substrs=['main.c:%d' % self.line2,
-                             '(int)argc=3'])
+                             '(int)argc=2'])
diff --git a/packages/Python/lldbsuite/test/python_api/hello_world/main.c b/packages/Python/lldbsuite/test/python_api/hello_world/main.c
index 32b0446..c516f92 100644
--- a/packages/Python/lldbsuite/test/python_api/hello_world/main.c
+++ b/packages/Python/lldbsuite/test/python_api/hello_world/main.c
@@ -8,16 +8,22 @@
 
 int main(int argc, char const *argv[])
 {
-    lldb_enable_attach();
+  lldb_enable_attach();
 
-    printf("Hello world.\n"); // Set break point at this line.
-    if (argc == 1)
-        return 0;
+  printf("Hello world.\n"); // Set break point at this line.
+  if (argc == 1)
+    return 1;
 
-    // Waiting to be attached by the debugger, otherwise.
-    char line[100];
-    while (1) 
-        sleep (1); // Waiting to be attached...
+  // Create the synchronization token.
+  FILE *f;
+  if (f = fopen(argv[1], "wx")) {
+    fputs("\n", f);
+    fflush(f);
+    fclose(f);
+  } else
+    return 1;
 
-    printf("Exiting now\n");
+  // Waiting to be attached by the debugger, otherwise.
+  while (1)
+    sleep(1); // Waiting to be attached...
 }