aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/test/ProfilingTests.cpp
diff options
context:
space:
mode:
authorJim Flynn <jim.flynn@arm.com>2019-10-14 12:31:10 +0100
committerJim Flynn <jim.flynn@arm.com>2019-10-14 14:59:07 +0100
commit53e469915bc6552c0d79cb6461512c7c1168ee2d (patch)
tree5c160326845c1e294ce88a30e0ffbb33436a3593 /src/profiling/test/ProfilingTests.cpp
parent262578500338274b5fa0bcfeb2d72c13e717f4ff (diff)
downloadarmnn-53e469915bc6552c0d79cb6461512c7c1168ee2d.tar.gz
IVGCVSW-3972 Implement the Disconnect functionality
* Added Disconnect method to the ProfilingService class * Added unit test Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com> Signed-off-by: Jim Flynn <jim.flynn@arm.com> Change-Id: I5cc57abd3e1239cdf8afe21ee4883c1f73cd0e80
Diffstat (limited to 'src/profiling/test/ProfilingTests.cpp')
-rw-r--r--src/profiling/test/ProfilingTests.cpp64
1 files changed, 62 insertions, 2 deletions
diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp
index 554b7e1936..446c6096ed 100644
--- a/src/profiling/test/ProfilingTests.cpp
+++ b/src/profiling/test/ProfilingTests.cpp
@@ -424,8 +424,8 @@ BOOST_AUTO_TEST_CASE(CheckProfilingStateMachine)
armnn::Exception);
ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck);
- BOOST_CHECK_THROW(profilingState14.TransitionToState(ProfilingState::NotConnected),
- armnn::Exception);
+ profilingState14.TransitionToState(ProfilingState::NotConnected);
+ BOOST_CHECK(profilingState14.GetCurrentState() == ProfilingState::NotConnected);
ProfilingStateMachine profilingState15(ProfilingState::Active);
BOOST_CHECK_THROW(profilingState15.TransitionToState(ProfilingState::Uninitialised),
@@ -2281,6 +2281,7 @@ BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadConnectionAcknowledgedPacket)
unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast<unsigned int>(processName.size()) + 1;
unsigned int streamMetadataPacketsize = 118 + processNameSize;
+ // Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
ProfilingService& profilingService = ProfilingService::Instance();
@@ -2354,6 +2355,7 @@ BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodConnectionAcknowledgedPacket)
unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast<unsigned int>(processName.size()) + 1;
unsigned int streamMetadataPacketsize = 118 + processNameSize;
+ // Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
ProfilingService& profilingService = ProfilingService::Instance();
@@ -3012,4 +3014,62 @@ BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketMult
profilingService.ResetExternalProfilingOptions(options, true);
}
+BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisconnect)
+{
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper;
+
+ // Reset the profiling service to the uninitialized state
+ armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
+ options.m_EnableProfiling = true;
+ ProfilingService& profilingService = ProfilingService::Instance();
+ profilingService.ResetExternalProfilingOptions(options, true);
+
+ // Try to disconnect the profiling service while in the "Uninitialised" state
+ BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
+ profilingService.Disconnect();
+ BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); // The state should not change
+
+ // Try to disconnect the profiling service while in the "NotConnected" state
+ profilingService.Update(); // Initialize the counter directory
+ BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
+ profilingService.Disconnect();
+ BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should not change
+
+ // Try to disconnect the profiling service while in the "WaitingForAck" state
+ profilingService.Update(); // Create the profiling connection
+ BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
+ profilingService.Disconnect();
+ BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); // The state should not change
+
+ // Try to disconnect the profiling service while in the "Active" state
+ profilingService.Update(); // Start the command handler and the send thread
+
+ // Wait for the Stream Metadata packet the be sent
+ // (we are not testing the connection acknowledgement here so it will be ignored by this test)
+ helper.WaitForProfilingPacketsSent();
+
+ // Force the profiling service to the "Active" state
+ helper.ForceTransitionToState(ProfilingState::Active);
+ BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
+
+ // Get the mock profiling connection
+ MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
+ BOOST_CHECK(mockProfilingConnection);
+
+ // Check that the profiling connection is open
+ BOOST_CHECK(mockProfilingConnection->IsOpen());
+
+ profilingService.Disconnect();
+ BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should have changed
+
+ // Check that the profiling connection has been reset
+ mockProfilingConnection = helper.GetMockProfilingConnection();
+ BOOST_CHECK(mockProfilingConnection == nullptr);
+
+ // Reset the profiling service to stop any running thread
+ options.m_EnableProfiling = false;
+ profilingService.ResetExternalProfilingOptions(options, true);
+}
+
BOOST_AUTO_TEST_SUITE_END()