D55859 and D63339 prevented needless dependencies on system symbol
files. This testcase was checked-in afterwards and it brings back one
such unwanted dependency. Under some circumstances it may cause false
FAILs and/or excessive resource usage to run the testcase.
clang-format does not support .py so I have formatted it as I found most
compatible.
Also this is not a full testcase-style initialization, for example
--no-lldbinit ignores env("NO_LLDBINIT") setting which lldbtest.py does
implement:
# If we spawn an lldb process for test (via pexpect), do not load the
# init file unless told otherwise.
if os.environ.get("NO_LLDBINIT") != "NO":
self.lldbOption += " --no-lldbinit"
But this is what lldbpexpect.py does - it also ignores
env("NO_LLDBINIT"). Sure one could also fix lldbpexpect.py to unify the
initialization more with lldbtest.py but I find that outside of the
scope of this patch.
Differential Revision: https://reviews.llvm.org/D79649
76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
"""
|
|
Test reproducer attach.
|
|
"""
|
|
|
|
import lldb
|
|
import tempfile
|
|
from lldbsuite.test import lldbtest_config
|
|
from lldbsuite.test.decorators import *
|
|
from lldbsuite.test.lldbtest import *
|
|
from lldbsuite.test import lldbutil
|
|
|
|
|
|
class ReproducerAttachTestCase(TestBase):
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
NO_DEBUG_INFO_TESTCASE = True
|
|
|
|
@skipIfFreeBSD
|
|
@skipIfNetBSD
|
|
@skipIfWindows
|
|
@skipIfRemote
|
|
@skipIfiOSSimulator
|
|
@skipIfReproducer
|
|
def test_reproducer_attach(self):
|
|
"""Test thread creation after process attach."""
|
|
exe = '%s_%d' % (self.testMethodName, os.getpid())
|
|
|
|
token = self.getBuildArtifact(exe + '.token')
|
|
if os.path.exists(token):
|
|
os.remove(token)
|
|
|
|
reproducer = self.getBuildArtifact(exe + '.reproducer')
|
|
if os.path.exists(reproducer):
|
|
try:
|
|
shutil.rmtree(reproducer)
|
|
except OSError:
|
|
pass
|
|
|
|
self.build(dictionary={'EXE': exe})
|
|
self.addTearDownHook(self.cleanupSubprocesses)
|
|
|
|
inferior = self.spawnSubprocess(self.getBuildArtifact(exe), [token])
|
|
pid = inferior.pid
|
|
|
|
lldbutil.wait_for_file_on_target(self, token)
|
|
|
|
# Use Popen because pexpect is overkill and spawnSubprocess is
|
|
# asynchronous.
|
|
capture = subprocess.Popen([
|
|
lldbtest_config.lldbExec, '-b', '--no-lldbinit', '--no-use-colors']
|
|
+ sum(map(lambda x: ['-O', x], self.setUpCommands()), [])
|
|
+ ['--capture', '--capture-path', reproducer,
|
|
'-o', 'proc att -n {}'.format(exe), '-o', 'reproducer generate'
|
|
],
|
|
stdin=subprocess.PIPE,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE)
|
|
outs, _ = capture.communicate()
|
|
outs = outs.decode('utf-8')
|
|
self.assertIn('Process {} stopped'.format(pid), outs)
|
|
self.assertIn('Reproducer written', outs)
|
|
|
|
# Check that replay works.
|
|
replay = subprocess.Popen(
|
|
[lldbtest_config.lldbExec, '-replay', reproducer],
|
|
stdin=subprocess.PIPE,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE)
|
|
outs, _ = replay.communicate()
|
|
outs = outs.decode('utf-8')
|
|
self.assertIn('Process {} stopped'.format(pid), outs)
|
|
|
|
# We can dump the reproducer in the current context.
|
|
self.expect('reproducer dump -f {} -p process'.format(reproducer),
|
|
substrs=['pid = {}'.format(pid), 'name = {}'.format(exe)])
|