[Lldb-commits] [lldb] r349397 - Remove sleep() synchronisation from teststcase and

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 18 00:11:17 PST 2018


Not that I want to defend the use of sleep, but my expectation  is that 
this will the test even more flaky.

The only thing that test does after attaching is verifying the process 
backtrace to check that it contains the "main" function. If the test 
doesn't sleep, it increases the likelyhood that you will attach before 
it even enters the main function. This may be particularly true on 
linux, where the process needs to invoke a special api (PR_SET_TRACER) 
before we can attach to it, and so the even the attach will fail if it's 
done too early.

One of the patterns for synchronization we have in other tests is to 
have the inferior create a file when it reaches the "safe to attach" 
point. The test then waits for this file to appear 
(lldbutil.wait_for_file_on_target) before proceeding. This still uses 
sleep() under the hood, but only because we don't have/don't want to 
implement a wait_for_file blocking api. In the end it still provides a 
more predictable state of the process we attach to.

On 17/12/2018 22:18, Adrian Prantl via lldb-commits wrote:
> Author: adrian
> Date: Mon Dec 17 13:18:11 2018
> New Revision: 349397
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=349397&view=rev
> Log:
> Remove sleep() synchronisation from teststcase and
> make the executable name more unique.
> 
> This test is failing sporadically on some bots. By removing the sleep
> synchronisation, I'm hoping to get it to fail more reproducibly so I
> can investigate what is going on.
> 
> Modified:
>      lldb/trunk/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
> 
> Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py?rev=349397&r1=349396&r2=349397&view=diff
> ==============================================================================
> --- lldb/trunk/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py (original)
> +++ lldb/trunk/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py Mon Dec 17 13:18:11 2018
> @@ -35,7 +35,7 @@ class HelloWorldTestCase(TestBase):
>       def test_with_process_launch_api(self):
>           """Create target, breakpoint, launch a process, and then kill it."""
>           # Get the full path to our executable to be attached/debugged.
> -        exe = self.getBuildArtifact(self.testMethodName)
> +        exe = '%s_%d'%(self.getBuildArtifact(self.testMethodName), os.getpid())
>           d = {'EXE': exe}
>           self.build(dictionary=d)
>           self.setTearDownCleanup(dictionary=d)
> @@ -82,7 +82,7 @@ class HelloWorldTestCase(TestBase):
>       @expectedFailureAll(oslist=['ios', 'watchos', 'tvos', 'bridgeos'], bugnumber="<rdar://problem/34538611>") # old lldb-server has race condition, launching an inferior and then launching debugserver in quick succession sometimes fails
>       def test_with_attach_to_process_with_id_api(self):
>           """Create target, spawn a process, and attach to it with process id."""
> -        exe = self.getBuildArtifact(self.testMethodName)
> +        exe = '%s_%d'%(self.getBuildArtifact(self.testMethodName), os.getpid())
>           d = {'EXE': exe}
>           self.build(dictionary=d)
>           self.setTearDownCleanup(dictionary=d)
> @@ -92,9 +92,6 @@ class HelloWorldTestCase(TestBase):
>           popen = self.spawnSubprocess(exe, ["abc", "xyz"])
>           self.addTearDownHook(self.cleanupSubprocesses)
>   
> -        # Give the subprocess time to start and wait for user input
> -        time.sleep(0.25)
> -
>           listener = lldb.SBListener("my.attach.listener")
>           error = lldb.SBError()
>           process = target.AttachToProcessWithID(listener, popen.pid, error)
> @@ -114,7 +111,7 @@ class HelloWorldTestCase(TestBase):
>       @expectedFailureAll(oslist=['ios', 'watchos', 'tvos', 'bridgeos'], bugnumber="<rdar://problem/34538611>") # old lldb-server has race condition, launching an inferior and then launching debugserver in quick succession sometimes fails
>       def test_with_attach_to_process_with_name_api(self):
>           """Create target, spawn a process, and attach to it with process name."""
> -        exe = self.getBuildArtifact(self.testMethodName)
> +        exe = '%s_%d'%(self.getBuildArtifact(self.testMethodName), os.getpid())
>           d = {'EXE': exe}
>           self.build(dictionary=d)
>           self.setTearDownCleanup(dictionary=d)
> @@ -124,9 +121,6 @@ class HelloWorldTestCase(TestBase):
>           popen = self.spawnSubprocess(exe, ["abc", "xyz"])
>           self.addTearDownHook(self.cleanupSubprocesses)
>   
> -        # Give the subprocess time to start and wait for user input
> -        time.sleep(0.25)
> -
>           listener = lldb.SBListener("my.attach.listener")
>           error = lldb.SBError()
>           # Pass 'False' since we don't want to wait for new instance of
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
> 



More information about the lldb-commits mailing list