diff options
author | Pavel Labath <labath@google.com> | 2018-02-08 10:37:23 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2018-02-08 10:37:23 +0000 |
commit | 014e4654d496a7c6dfeb28903079bd324c16fc2b (patch) | |
tree | 54a8332cad068222adf099b668df5e3d528f2b59 /lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client | |
parent | c8016e7a65ffc6f0266845c4674f7a08dffff3ea (diff) | |
download | bcm5719-llvm-014e4654d496a7c6dfeb28903079bd324c16fc2b.tar.gz bcm5719-llvm-014e4654d496a7c6dfeb28903079bd324c16fc2b.zip |
Rewrite the flaky test_restart_bug test in a more deterministic way
Summary:
The test was trying to reproduce a bug in handling of two concurrent
events, which was impossible to do reliably in a black-box style test.
In practice, this meant the test was only ever failing on remote
targets, as these were slow enough to trigger this.
Fortunately, we now have the ability to mock the server side of the
connection, which means we can simulate the failure deterministically,
so I rewrite the test to use the new gdb-client framework.
I've needed to add a couple of new packets to the mock server to be able
to do this. Instead of trying to guess how a "typical" gdb-client test
will want to handle this, I throw an exception in the implementation to
force the user to override them (the packets are only sent if the test
explicitly performs some action which will trigger them, so a basic test
which e.g. does not need the "continue" functionality will not need to
implement them).
Reviewers: owenpshaw
Subscribers: srhines, lldb-commits
Differential Revision: https://reviews.llvm.org/D42959
llvm-svn: 324590
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestRestartBug.py | 62 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py | 33 |
2 files changed, 93 insertions, 2 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestRestartBug.py b/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestRestartBug.py new file mode 100644 index 00000000000..142861a37df --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestRestartBug.py @@ -0,0 +1,62 @@ +from __future__ import print_function +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +from gdbclientutils import * + + +class TestRestartBug(GDBRemoteTestBase): + + @expectedFailureAll(bugnumber="llvm.org/pr24530") + def test(self): + """ + Test auto-continue behavior when a process is interrupted to deliver + an "asynchronous" packet. This simulates the situation when a process + stops on its own just as lldb client is about to interrupt it. The + client should not auto-continue in this case, unless the user has + explicitly requested that we ignore signals of this type. + """ + class MyResponder(MockGDBServerResponder): + continueCount = 0 + + def setBreakpoint(self, packet): + return "OK" + + def interrupt(self): + # Simulate process stopping due to a raise(SIGINT) just as lldb + # is about to interrupt it. + return "T02reason:signal" + + def cont(self): + self.continueCount += 1 + if self.continueCount == 1: + # No response, wait for the client to interrupt us. + return None + return "W00" # Exit + + self.server.responder = MyResponder() + target = self.createTarget("a.yaml") + process = self.connect(target) + self.dbg.SetAsync(True) + process.Continue() + + # resume the process and immediately try to set another breakpoint. When using the remote + # stub, this will trigger a request to stop the process. Make sure we + # do not lose this signal. + bkpt = target.BreakpointCreateByAddress(0x1234) + self.assertTrue(bkpt.IsValid()) + self.assertEqual(bkpt.GetNumLocations(), 1) + + event = lldb.SBEvent() + while self.dbg.GetListener().WaitForEvent(2, event): + if self.TraceOn(): + print("Process changing state to:", + self.dbg.StateAsCString(process.GetStateFromEvent(event))) + if process.GetStateFromEvent(event) == lldb.eStateExited: + break + + # We should get only one continue packet as the client should not + # auto-continue after setting the breakpoint. + self.assertEqual(self.server.responder.continueCount, 1) + # And the process should end up in the stopped state. + self.assertEqual(process.GetState(), lldb.eStateStopped) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py b/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py index 5293a32e7d1..9e175010a20 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py @@ -98,6 +98,10 @@ class MockGDBServerResponder: to the given packet received from the client. """ self.packetLog.append(packet) + if packet is MockGDBServer.PACKET_INTERRUPT: + return self.interrupt() + if packet == "c": + return self.cont() if packet == "g": return self.readRegisters() if packet[0] == "G": @@ -133,8 +137,16 @@ class MockGDBServerResponder: if data is not None: return self._qXferResponse(data, has_more) return "" + if packet[0] == "Z": + return self.setBreakpoint(packet) return self.other(packet) + def interrupt(self): + raise self.UnexpectedPacketException() + + def cont(self): + raise self.UnexpectedPacketException() + def readRegisters(self): return "00000000" * self.registerCount @@ -178,10 +190,21 @@ class MockGDBServerResponder: def selectThread(self, op, thread_id): return "OK" + def setBreakpoint(self, packet): + raise self.UnexpectedPacketException() + def other(self, packet): # empty string means unsupported return "" + """ + Raised when we receive a packet for which there is no default action. + Override the responder class to implement behavior suitable for the test at + hand. + """ + class UnexpectedPacketException(Exception): + pass + class MockGDBServer: """ @@ -288,6 +311,9 @@ class MockGDBServer: if data[0] == '+': self._receivedData = data[1:] return self.PACKET_ACK + if ord(data[0]) == 3: + self._receivedData = data[1:] + return self.PACKET_INTERRUPT if data[0] == '$': i += 1 else: @@ -343,10 +369,12 @@ class MockGDBServer: # Delegate everything else to our responder response = self.responder.respond(packet) # Handle packet framing since we don't want to bother tests with it. - framed = frame_packet(response) - self._client.sendall(framed) + if response is not None: + framed = frame_packet(response) + self._client.sendall(framed) PACKET_ACK = object() + PACKET_INTERRUPT = object() class InvalidPacketException(Exception): pass @@ -410,6 +438,7 @@ class GDBRemoteTestBase(TestBase): process = target.ConnectRemote(listener, url, "gdb-remote", error) self.assertTrue(error.Success(), error.description) self.assertTrue(process, PROCESS_IS_VALID) + return process def assertPacketLogContains(self, packets): """ |