Author: labath Date: Fri Nov 4 06:49:06 2016 New Revision: 285992 URL: http://llvm.org/viewvc/llvm-project?rev=285992&view=rev Log: 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. Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=285992&r1=285991&r2=285992&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Fri Nov 4 06:49:06 2016 @@ -2148,8 +2148,9 @@ std::chrono::duration<float> calculate_s 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::TestP } } - 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::TestP 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::TestP } 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 = Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h?rev=285992&r1=285991&r2=285992&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Fri Nov 4 06:49:06 2016 @@ -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 Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=285992&r1=285991&r2=285992&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Nov 4 06:49:06 2016 @@ -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; } Modified: lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp?rev=285992&r1=285991&r2=285992&view=diff ============================================================================== --- lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp (original) +++ lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp Fri Nov 4 06:49:06 2016 @@ -270,21 +270,23 @@ TEST_F(GDBRemoteCommunicationClientTest, 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(); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits