From 61d6f7305b02e025ee10aa07e5499993a0e77cc1 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Thu, 3 Oct 2019 11:21:18 +0100 Subject: IVGCVSW-3440 Fix intermittently failing send thread test * Simplified the implementation of the MockStreamCounterBuffer * Minor refactoring Signed-off-by: Matteo Martincigh Change-Id: I3aed97daee0ac32d384e1f830e8cc57aae84950b --- src/profiling/test/SendCounterPacketTests.cpp | 38 +++++++++++++-------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src/profiling/test/SendCounterPacketTests.cpp') diff --git a/src/profiling/test/SendCounterPacketTests.cpp b/src/profiling/test/SendCounterPacketTests.cpp index 96596066c1..ba1d470a50 100644 --- a/src/profiling/test/SendCounterPacketTests.cpp +++ b/src/profiling/test/SendCounterPacketTests.cpp @@ -1694,7 +1694,7 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest7) BOOST_AUTO_TEST_CASE(SendThreadTest0) { MockProfilingConnection mockProfilingConnection; - MockStreamCounterBuffer mockStreamCounterBuffer(1, 0); + MockStreamCounterBuffer mockStreamCounterBuffer(0); SendCounterPacket sendCounterPacket(mockProfilingConnection, mockStreamCounterBuffer); // Try to start the send thread many times, it must only start once @@ -1718,7 +1718,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest1) unsigned int totalWrittenSize = 0; MockProfilingConnection mockProfilingConnection; - MockStreamCounterBuffer mockStreamCounterBuffer(5,1024); + MockStreamCounterBuffer mockStreamCounterBuffer(1024); SendCounterPacket sendCounterPacket(mockProfilingConnection, mockStreamCounterBuffer); sendCounterPacket.Start(); @@ -1732,8 +1732,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest1) // Get the size of the Stream Metadata Packet std::string processName = GetProcessName().substr(0, 60); - unsigned int processNameSize = boost::numeric_cast(processName.size()) > 0 ? - boost::numeric_cast(processName.size()) + 1 : 0; + unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast(processName.size()) + 1; unsigned int streamMetadataPacketsize = 118 + processNameSize; totalWrittenSize += streamMetadataPacketsize; @@ -1811,15 +1810,15 @@ BOOST_AUTO_TEST_CASE(SendThreadTest1) sendCounterPacket.SetReadyToRead(); - // To test an exact value of the "read size" in the mock buffer, wait a second to allow the send thread to + // To test an exact value of the "read size" in the mock buffer, wait two seconds to allow the send thread to // read all what's remaining in the buffer std::this_thread::sleep_for(std::chrono::seconds(2)); sendCounterPacket.Stop(); - BOOST_CHECK(mockStreamCounterBuffer.GetReadableBufferSize() == totalWrittenSize); BOOST_CHECK(mockStreamCounterBuffer.GetCommittedSize() == totalWrittenSize); - BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() == totalWrittenSize); + BOOST_CHECK(mockStreamCounterBuffer.GetReadableSize() == totalWrittenSize); + BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() == totalWrittenSize); } BOOST_AUTO_TEST_CASE(SendThreadTest2) @@ -1827,7 +1826,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest2) unsigned int totalWrittenSize = 0; MockProfilingConnection mockProfilingConnection; - MockStreamCounterBuffer mockStreamCounterBuffer(5, 1024); + MockStreamCounterBuffer mockStreamCounterBuffer(1024); SendCounterPacket sendCounterPacket(mockProfilingConnection, mockStreamCounterBuffer); sendCounterPacket.Start(); @@ -1843,8 +1842,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest2) // Get the size of the Stream Metadata Packet std::string processName = GetProcessName().substr(0, 60); - unsigned int processNameSize = boost::numeric_cast(processName.size()) > 0 ? - boost::numeric_cast(processName.size()) + 1 : 0; + unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast(processName.size()) + 1; unsigned int streamMetadataPacketsize = 118 + processNameSize; totalWrittenSize += streamMetadataPacketsize; @@ -1932,15 +1930,15 @@ BOOST_AUTO_TEST_CASE(SendThreadTest2) sendCounterPacket.SetReadyToRead(); - // To test an exact value of the "read size" in the mock buffer, wait a second to allow the send thread to + // To test an exact value of the "read size" in the mock buffer, wait two seconds to allow the send thread to // read all what's remaining in the buffer std::this_thread::sleep_for(std::chrono::seconds(2)); sendCounterPacket.Stop(); - BOOST_CHECK(mockStreamCounterBuffer.GetReadableBufferSize() == totalWrittenSize); BOOST_CHECK(mockStreamCounterBuffer.GetCommittedSize() == totalWrittenSize); - BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() == totalWrittenSize); + BOOST_CHECK(mockStreamCounterBuffer.GetReadableSize() == totalWrittenSize); + BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() == totalWrittenSize); } BOOST_AUTO_TEST_CASE(SendThreadTest3) @@ -1948,7 +1946,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest3) unsigned int totalWrittenSize = 0; MockProfilingConnection mockProfilingConnection; - MockStreamCounterBuffer mockStreamCounterBuffer(10, 1024); + MockStreamCounterBuffer mockStreamCounterBuffer(1024); SendCounterPacket sendCounterPacket(mockProfilingConnection, mockStreamCounterBuffer); sendCounterPacket.Start(); @@ -1961,8 +1959,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest3) // Get the size of the Stream Metadata Packet std::string processName = GetProcessName().substr(0, 60); - unsigned int processNameSize = boost::numeric_cast(processName.size()) > 0 ? - boost::numeric_cast(processName.size()) + 1 : 0; + unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast(processName.size()) + 1; unsigned int streamMetadataPacketsize = 118 + processNameSize; totalWrittenSize += streamMetadataPacketsize; @@ -2040,10 +2037,11 @@ BOOST_AUTO_TEST_CASE(SendThreadTest3) // thread is not guaranteed to flush the buffer) sendCounterPacket.Stop(); - BOOST_CHECK(mockStreamCounterBuffer.GetReadableBufferSize() <= totalWrittenSize); - BOOST_CHECK(mockStreamCounterBuffer.GetCommittedSize() <= totalWrittenSize); - BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() <= totalWrittenSize); - BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() <= mockStreamCounterBuffer.GetCommittedSize()); + BOOST_CHECK(mockStreamCounterBuffer.GetCommittedSize() == totalWrittenSize); + BOOST_CHECK(mockStreamCounterBuffer.GetReadableSize() <= totalWrittenSize); + BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() <= totalWrittenSize); + BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() <= mockStreamCounterBuffer.GetReadableSize()); + BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() <= mockStreamCounterBuffer.GetCommittedSize()); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1