Skip to content

Commit 37ec83f

Browse files
committed
[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
1 parent 1c80a6c commit 37ec83f

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,25 @@ def tearDown(self):
3232
@skipUnlessDarwin
3333
# This test is explicitly a dSYM test, it doesn't need to run for any other config.
3434
@skipIf(debug_info=no_match(["dsym"]))
35+
@skipIfReproducer # File synchronization is not supported during replay.
3536
def test_attach_and_check_dsyms(self):
3637
"""Test attach to binary, see if the bundle dSYM is found"""
3738
exe = self.getBuildArtifact(exe_name)
3839
self.build()
3940
os.chdir(self.getBuildDir());
40-
popen = self.spawnSubprocess(exe)
4141

42-
# Give the inferior time to start up, dlopen a bundle, remove the bundle it linked in
43-
sleep(5)
42+
# Use a file as a synchronization point between test and inferior.
43+
pid_file_path = lldbutil.append_to_process_working_directory(self,
44+
"token_pid_%d" % (int(os.getpid())))
45+
self.addTearDownHook(
46+
lambda: self.run_platform_command(
47+
"rm %s" %
48+
(pid_file_path)))
49+
50+
popen = self.spawnSubprocess(exe, [pid_file_path])
51+
52+
# Wait for the inferior to start up, dlopen a bundle, remove the bundle it linked in
53+
pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
4454

4555
# Since the library that was dlopen()'ed is now removed, lldb will need to find the
4656
# binary & dSYM via target.exec-search-paths
@@ -64,6 +74,3 @@ def test_attach_and_check_dsyms(self):
6474
self.assertTrue (dsym_name == 'com.apple.sbd', "Check that we found the dSYM for the bundle that was loaded")
6575
i=i+1
6676
os.chdir(self.getSourceDir());
67-
68-
if __name__ == '__main__':
69-
unittest.main()

lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include <dlfcn.h>
22
#include <unistd.h>
33
#include <stdlib.h>
4+
#include <stdio.h>
45

56
int setup_is_complete = 0;
67

7-
int main()
8+
int main(int argc, const char** argv)
89
{
910

1011
void *handle = dlopen ("com.apple.sbd.xpc/com.apple.sbd", RTLD_NOW);
@@ -13,6 +14,9 @@ int main()
1314
if (dlsym(handle, "foo"))
1415
{
1516
system ("/bin/rm -rf com.apple.sbd.xpc com.apple.sbd.xpc.dSYM");
17+
18+
FILE *fp = fopen (argv[1], "w");
19+
fclose (fp);
1620
setup_is_complete = 1;
1721

1822
// At this point we want lldb to attach to the process. If lldb attaches

lldb/test/API/macosx/find-dsym/deep-bundle/TestDeepBundle.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,24 @@ def tearDown(self):
3131
@skipUnlessDarwin
3232
# This test is explicitly a dSYM test, it doesn't need to run for any other config.
3333
@skipIf(debug_info=no_match(["dsym"]))
34+
@skipIfReproducer # File synchronization is not supported during replay.
3435
def test_attach_and_check_dsyms(self):
3536
"""Test attach to binary, see if the framework dSYM is found"""
3637
exe = self.getBuildArtifact(exe_name)
3738
self.build()
38-
popen = self.spawnSubprocess(exe, [self.getBuildDir()])
3939

40-
# Give the inferior time to start up, dlopen a bundle, remove the bundle it linked in
41-
sleep(5)
40+
# Use a file as a synchronization point between test and inferior.
41+
pid_file_path = lldbutil.append_to_process_working_directory(self,
42+
"token_pid_%d" % (int(os.getpid())))
43+
self.addTearDownHook(
44+
lambda: self.run_platform_command(
45+
"rm %s" %
46+
(pid_file_path)))
47+
48+
popen = self.spawnSubprocess(exe, [self.getBuildDir(), pid_file_path])
49+
50+
# Wait for the inferior to start up, dlopen a bundle, remove the bundle it linked in
51+
pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
4252

4353
# Since the library that was dlopen()'ed is now removed, lldb will need to find the
4454
# binary & dSYM via target.exec-search-paths

lldb/test/API/macosx/find-dsym/deep-bundle/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ int main(int argc, const char **argv)
1313
argv[1], argv[1], argv[1]);
1414
system (command);
1515

16+
FILE *fp = fopen (argv[2], "w");
17+
fclose (fp);
1618
setup_is_complete = 1;
1719

1820
// At this point we want lldb to attach to the process. If lldb attaches

0 commit comments

Comments
 (0)