[Lldb-commits] [lldb] 37ec83f - [lldb] Use file to synchronize TestDeepBundle and TestBundleWithDotInFilename

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 14 08:32:58 PDT 2020


Author: Jonas Devlieghere
Date: 2020-08-14T08:32:21-07:00
New Revision: 37ec83fcfc6c7915c51268f578b8e0dadb54c1cf

URL: https://github.com/llvm/llvm-project/commit/37ec83fcfc6c7915c51268f578b8e0dadb54c1cf
DIFF: https://github.com/llvm/llvm-project/commit/37ec83fcfc6c7915c51268f578b8e0dadb54c1cf.diff

LOG: [lldb] Use file to synchronize TestDeepBundle and TestBundleWithDotInFilename

Currently these two tests use an arbitrary wait of 5 seconds for the
inferior to finish setting up. When the test machine is under heavy load
this sometimes is insufficient leading to spurious test failures. This
patch adds synchronization trough a token on the file system. In
addition to making the test more reliable it also makes it much faster
because we no longer have to wait the full 5 seconds if the setup was
completed faster than that.

Differential revision: https://reviews.llvm.org/D85915

Added: 
    

Modified: 
    lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
    lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/main.c
    lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
    lldb/test/API/macosx/find-dsym/deep-bundle/main.c

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py b/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
index 2572600a1829..e12a638f9c03 100644
--- a/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
+++ b/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py
@@ -32,15 +32,25 @@ def tearDown(self):
     @skipUnlessDarwin
     # This test is explicitly a dSYM test, it doesn't need to run for any other config.
     @skipIf(debug_info=no_match(["dsym"]))
+    @skipIfReproducer # File synchronization is not supported during replay.
     def test_attach_and_check_dsyms(self):
         """Test attach to binary, see if the bundle dSYM is found"""
         exe = self.getBuildArtifact(exe_name)
         self.build()
         os.chdir(self.getBuildDir());
-        popen = self.spawnSubprocess(exe)
 
-        # Give the inferior time to start up, dlopen a bundle, remove the bundle it linked in
-        sleep(5)
+        # Use a file as a synchronization point between test and inferior.
+        pid_file_path = lldbutil.append_to_process_working_directory(self,
+            "token_pid_%d" % (int(os.getpid())))
+        self.addTearDownHook(
+            lambda: self.run_platform_command(
+                "rm %s" %
+                (pid_file_path)))
+
+        popen = self.spawnSubprocess(exe, [pid_file_path])
+
+        # Wait for the inferior to start up, dlopen a bundle, remove the bundle it linked in
+        pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
 
         # Since the library that was dlopen()'ed is now removed, lldb will need to find the
         # binary & dSYM via target.exec-search-paths
@@ -64,6 +74,3 @@ def test_attach_and_check_dsyms(self):
                 self.assertTrue (dsym_name == 'com.apple.sbd', "Check that we found the dSYM for the bundle that was loaded")
             i=i+1
         os.chdir(self.getSourceDir());
-
-if __name__ == '__main__':
-    unittest.main()

diff  --git a/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/main.c b/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/main.c
index 30761eb1b409..a4cffc840731 100644
--- a/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/main.c
+++ b/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/main.c
@@ -1,10 +1,11 @@
 #include <dlfcn.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 int setup_is_complete = 0;
 
-int main()
+int main(int argc, const char** argv)
 {
 
     void *handle = dlopen ("com.apple.sbd.xpc/com.apple.sbd", RTLD_NOW);
@@ -13,6 +14,9 @@ int main()
         if (dlsym(handle, "foo"))
         {
             system ("/bin/rm -rf com.apple.sbd.xpc com.apple.sbd.xpc.dSYM");
+
+            FILE *fp = fopen (argv[1], "w");
+            fclose (fp);
             setup_is_complete = 1;
 
             // At this point we want lldb to attach to the process.  If lldb attaches

diff  --git a/lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py b/lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
index a486c5159f01..358a4b70d2f5 100644
--- a/lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
+++ b/lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py
@@ -31,14 +31,24 @@ def tearDown(self):
     @skipUnlessDarwin
     # This test is explicitly a dSYM test, it doesn't need to run for any other config.
     @skipIf(debug_info=no_match(["dsym"]))
+    @skipIfReproducer # File synchronization is not supported during replay.
     def test_attach_and_check_dsyms(self):
         """Test attach to binary, see if the framework dSYM is found"""
         exe = self.getBuildArtifact(exe_name)
         self.build()
-        popen = self.spawnSubprocess(exe, [self.getBuildDir()])
 
-        # Give the inferior time to start up, dlopen a bundle, remove the bundle it linked in
-        sleep(5)
+        # Use a file as a synchronization point between test and inferior.
+        pid_file_path = lldbutil.append_to_process_working_directory(self,
+            "token_pid_%d" % (int(os.getpid())))
+        self.addTearDownHook(
+            lambda: self.run_platform_command(
+                "rm %s" %
+                (pid_file_path)))
+
+        popen = self.spawnSubprocess(exe, [self.getBuildDir(),  pid_file_path])
+
+        # Wait for the inferior to start up, dlopen a bundle, remove the bundle it linked in
+        pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
 
         # Since the library that was dlopen()'ed is now removed, lldb will need to find the
         # binary & dSYM via target.exec-search-paths

diff  --git a/lldb/test/API/macosx/find-dsym/deep-bundle/main.c b/lldb/test/API/macosx/find-dsym/deep-bundle/main.c
index b5ef5cff74a3..0a44b96068c2 100644
--- a/lldb/test/API/macosx/find-dsym/deep-bundle/main.c
+++ b/lldb/test/API/macosx/find-dsym/deep-bundle/main.c
@@ -13,6 +13,8 @@ int main(int argc, const char **argv)
              argv[1], argv[1], argv[1]);
     system (command);
 
+    FILE *fp = fopen (argv[2], "w");
+    fclose (fp);
     setup_is_complete = 1;
 
     // At this point we want lldb to attach to the process.  If lldb attaches


        


More information about the lldb-commits mailing list