Files
Raphael Isemann a84d94802d [lldb] Add a packet-test-delay setting for testing slow connections (#195440)
[lldb] Add a packet-test-delay setting for testing slow connections

Sending/receiving packets to/from a non-host devices adds latency to
the gdb-remote communication that induces substantial slowdown into the
debugging experience.

This patch adds an artificial delay before sending a packet to
simulate this latency without requiring an emulated/physical device.

The test checks only checks that there is a delay when this setting is
activated, but not that there is no delay when the setting is not
activated. The reason for this is that this negative test would either
require a large delay (which further slows down the test suite) or be
prone to accidential failures on overloaded test bots.

There is also the question whether we should have dynamic delays that
depend on the number of transferred bytes. From talking to Felipe it
seems the real bottleneck is really just the latency and not the
transfer speed. From my own testing, it seems that a simple fixed array
mostly simulated the remote debugging performance, and the delays I can
see on my own machine seem to mostly resemble the delays we can see
when debugging on a remote device.

This patch also required wrapping `SendPacketAndWaitForResponse` so we
can sync this setting on a per-packet basis for the
GDBRemoteCommunication class. Without this, we could only set the delay
before connecting and then never change afterwards which would make
this feature less useful and writing a simple test impossible.
2026-05-19 13:29:52 +01:00

40 lines
1.3 KiB
Python

import time
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
from lldbsuite.test.gdbclientutils import *
from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase
class TestPacketTestDelay(GDBRemoteTestBase):
NO_DEBUG_INFO_TESTCASE = True
def test_packet_test_delay(self):
"""Verify that packet-test-delay inserts a delay before each sent packet."""
# 1000ms should be long enough that this test doesn't pass by
# accident even on slow machines, but not too long to waste test
# suite time.
DELAY_MS = 1000
class MyResponder(MockGDBServerResponder):
def x(self, addr, length):
return "foobar"
self.server.responder = MyResponder()
target = self.dbg.CreateTargetWithFileAndTargetTriple("", "x86_64-pc-linux")
process = self.connect(target)
error = lldb.SBError()
start = time.time()
self.runCmd(
"settings set plugin.process.gdb-remote.packet-test-delay %d" % DELAY_MS
)
# Send a single dummy packet so we can observe the delay.
process.ReadMemory(0x1000, 10, error)
elapsed_ms = (time.time() - start) * 1000
self.assertGreaterEqual(
elapsed_ms, DELAY_MS, "Packet was sent faster than the set test delay?"
)