Fix GDBRemoteCommunicationClientTest.TestPacketSpeedJSON
The mock server was listening for only one packet (I forgot to put a loop around it), which caused the client to stall in debug builds, as the timeout there is 1000 seconds. In case of a release builds the test would just silently succeed as the tested function does not check or report errors (which should be fixed). This fixes the test by adding the server loop. Since the test was taking quite a long time now (8s), I have added a parameter to control the amount of data sent (default 4MB), and call it with a smaller value in the test, to make the test run faster. llvm-svn: 285992
This commit is contained in:
parent
baeb402014
commit
2fd9a1e0d9
|
@ -2148,8 +2148,9 @@ std::chrono::duration<float> calculate_standard_deviation(
|
|||
|
||||
void GDBRemoteCommunicationClient::TestPacketSpeed(const uint32_t num_packets,
|
||||
uint32_t max_send,
|
||||
uint32_t max_recv, bool json,
|
||||
Stream &strm) {
|
||||
uint32_t max_recv,
|
||||
uint64_t recv_amount,
|
||||
bool json, Stream &strm) {
|
||||
using namespace std::chrono;
|
||||
|
||||
uint32_t i;
|
||||
|
@ -2215,13 +2216,11 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const uint32_t num_packets,
|
|||
}
|
||||
}
|
||||
|
||||
const uint64_t k_recv_amount = 4 * 1024 * 1024; // Receive amount in bytes
|
||||
|
||||
const float k_recv_amount_mb = (float)k_recv_amount / (1024.0f * 1024.0f);
|
||||
const float k_recv_amount_mb = (float)recv_amount / (1024.0f * 1024.0f);
|
||||
if (json)
|
||||
strm.Printf("\n ]\n },\n \"download_speed\" : {\n \"byte_size\" "
|
||||
": %" PRIu64 ",\n \"results\" : [",
|
||||
k_recv_amount);
|
||||
recv_amount);
|
||||
else
|
||||
strm.Printf("Testing receiving %2.1fMB of data using varying receive "
|
||||
"packet sizes:\n",
|
||||
|
@ -2238,7 +2237,7 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const uint32_t num_packets,
|
|||
const auto start_time = steady_clock::now();
|
||||
uint32_t bytes_read = 0;
|
||||
uint32_t packet_count = 0;
|
||||
while (bytes_read < k_recv_amount) {
|
||||
while (bytes_read < recv_amount) {
|
||||
StringExtractorGDBRemote response;
|
||||
SendPacketAndWaitForResponse(packet.GetString(), response, false);
|
||||
bytes_read += recv_size;
|
||||
|
@ -2246,7 +2245,7 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const uint32_t num_packets,
|
|||
}
|
||||
const auto end_time = steady_clock::now();
|
||||
const auto total_time = end_time - start_time;
|
||||
float mb_second = ((float)k_recv_amount) /
|
||||
float mb_second = ((float)recv_amount) /
|
||||
duration<float>(total_time).count() /
|
||||
(1024.0 * 1024.0);
|
||||
float packets_per_second =
|
||||
|
|
|
@ -323,7 +323,8 @@ public:
|
|||
bool SetNonStopMode(const bool enable);
|
||||
|
||||
void TestPacketSpeed(const uint32_t num_packets, uint32_t max_send,
|
||||
uint32_t max_recv, bool json, Stream &strm);
|
||||
uint32_t max_recv, uint64_t recv_amount, bool json,
|
||||
Stream &strm);
|
||||
|
||||
// This packet is for testing the speed of the interface only. Both
|
||||
// the client and server need to support it, but this allows us to
|
||||
|
|
|
@ -4905,13 +4905,11 @@ public:
|
|||
const uint64_t max_send = m_max_send.GetOptionValue().GetCurrentValue();
|
||||
const uint64_t max_recv = m_max_recv.GetOptionValue().GetCurrentValue();
|
||||
const bool json = m_json.GetOptionValue().GetCurrentValue();
|
||||
if (output_stream_sp)
|
||||
process->GetGDBRemote().TestPacketSpeed(
|
||||
num_packets, max_send, max_recv, json, *output_stream_sp);
|
||||
else {
|
||||
process->GetGDBRemote().TestPacketSpeed(
|
||||
num_packets, max_send, max_recv, json, result.GetOutputStream());
|
||||
}
|
||||
const uint64_t k_recv_amount =
|
||||
4 * 1024 * 1024; // Receive amount in bytes
|
||||
process->GetGDBRemote().TestPacketSpeed(
|
||||
num_packets, max_send, max_recv, k_recv_amount, json,
|
||||
output_stream_sp ? *output_stream_sp : result.GetOutputStream());
|
||||
result.SetStatus(eReturnStatusSuccessFinishResult);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -270,21 +270,23 @@ TEST_F(GDBRemoteCommunicationClientTest, TestPacketSpeedJSON) {
|
|||
return;
|
||||
|
||||
std::thread server_thread([&server] {
|
||||
StringExtractorGDBRemote request;
|
||||
PacketResult result = server.GetPacket(request);
|
||||
if (result == PacketResult::ErrorDisconnected)
|
||||
return;
|
||||
ASSERT_EQ(PacketResult::Success, result);
|
||||
StringRef ref = request.GetStringRef();
|
||||
ASSERT_TRUE(ref.consume_front("qSpeedTest:response_size:"));
|
||||
int size;
|
||||
ASSERT_FALSE(ref.consumeInteger(10, size)) << "ref: " << ref;
|
||||
std::string response(size, 'X');
|
||||
ASSERT_EQ(PacketResult::Success, server.SendPacket(response));
|
||||
for (;;) {
|
||||
StringExtractorGDBRemote request;
|
||||
PacketResult result = server.GetPacket(request);
|
||||
if (result == PacketResult::ErrorDisconnected)
|
||||
return;
|
||||
ASSERT_EQ(PacketResult::Success, result);
|
||||
StringRef ref = request.GetStringRef();
|
||||
ASSERT_TRUE(ref.consume_front("qSpeedTest:response_size:"));
|
||||
int size;
|
||||
ASSERT_FALSE(ref.consumeInteger(10, size)) << "ref: " << ref;
|
||||
std::string response(size, 'X');
|
||||
ASSERT_EQ(PacketResult::Success, server.SendPacket(response));
|
||||
}
|
||||
});
|
||||
|
||||
StreamString ss;
|
||||
client.TestPacketSpeed(10, 32, 32, true, ss);
|
||||
client.TestPacketSpeed(10, 32, 32, 4096, true, ss);
|
||||
client.Disconnect();
|
||||
server_thread.join();
|
||||
|
||||
|
|
Loading…
Reference in New Issue