aboutsummaryrefslogtreecommitdiff
path: root/tests/profiling/gatordmock/tests/GatordMockTests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/profiling/gatordmock/tests/GatordMockTests.cpp')
-rw-r--r--tests/profiling/gatordmock/tests/GatordMockTests.cpp167
1 files changed, 134 insertions, 33 deletions
diff --git a/tests/profiling/gatordmock/tests/GatordMockTests.cpp b/tests/profiling/gatordmock/tests/GatordMockTests.cpp
index f5e60f83b2..eb827bec69 100644
--- a/tests/profiling/gatordmock/tests/GatordMockTests.cpp
+++ b/tests/profiling/gatordmock/tests/GatordMockTests.cpp
@@ -5,6 +5,7 @@
#include "../GatordMockService.hpp"
#include "../PeriodicCounterCaptureCommandHandler.hpp"
+#include "../DirectoryCaptureCommandHandler.hpp"
#include <CommandHandlerRegistry.hpp>
#include <ProfilingService.hpp>
@@ -21,28 +22,11 @@ using namespace armnn;
using namespace std::this_thread; // sleep_for, sleep_until
using namespace std::chrono_literals;
-// Required so build succeeds when local variable used only in assert
-#define _unused(x) ((void)(x))
-
-uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType)
-{
- return ((packetFamily & 0x3F) << 26) | ((packetClass & 0x3FF) << 19) | ((packetType & 0x3FFF) << 16);
-}
-
-uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId)
-{
- return ((packetFamily & 0x3F) << 26) | ((packetId & 0x3FF) << 16);
-}
-
BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest)
{
using boost::numeric_cast;
- // Initialise functors and register into the CommandHandlerRegistry
- uint32_t headerWord1 = ConstructHeader(1, 0, 0);
-
- // Create the Command Handler Registry
- profiling::CommandHandlerRegistry registry;
+ profiling::PacketVersionResolver packetVersionResolver;
// Data with timestamp, counter idx & counter values
std::vector<std::pair<uint16_t, uint32_t>> indexValuePairs;
@@ -98,18 +82,19 @@ BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest)
offset += sizeOfUint32;
}
+ uint32_t headerWord1 = packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue();
// Create packet to send through to the command functor
profiling::Packet packet1(headerWord1, dataLength, uniqueData1);
profiling::Packet packet2(headerWord1, dataLength, uniqueData2);
- uint32_t version = 1;
- gatordmock::PeriodicCounterCaptureCommandHandler commandHandler(0, 4, version, true);
+ gatordmock::PeriodicCounterCaptureCommandHandler commandHandler
+ (0, 4, headerWord1, true);
// Simulate two separate packets coming in to calculate period
commandHandler(packet1);
commandHandler(packet2);
- BOOST_ASSERT(4500 < commandHandler.m_CurrentPeriodValue && 5500 > commandHandler.m_CurrentPeriodValue);
+ BOOST_ASSERT(commandHandler.m_CurrentPeriodValue == 5000);
for (size_t i = 0; i < commandHandler.m_CounterCaptureValues.m_Uids.size(); ++i)
{
@@ -122,18 +107,26 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd)
// The purpose of this test is to setup both sides of the profiling service and get to the point of receiving
// performance data.
- // Initialise functors and register into the CommandHandlerRegistry
- uint32_t version = 1;
+ //These variables are used to wait for the profiling service
+ u_int32_t timeout = 2000;
+ u_int32_t sleepTime = 50;
+ u_int32_t timeSlept = 0;
+
+ profiling::PacketVersionResolver packetVersionResolver;
// Create the Command Handler Registry
profiling::CommandHandlerRegistry registry;
// Update with derived functors
- gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler(0, 4, version, true);
+ gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler
+ (0, 4, packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), true);
+
+ gatordmock::DirectoryCaptureCommandHandler directoryCaptureCommandHandler
+ (0, 2, packetVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue(), true);
// Register different derived functors
registry.RegisterFunctor(&counterCaptureCommandHandler);
-
+ registry.RegisterFunctor(&directoryCaptureCommandHandler);
// Setup the mock service to bind to the UDS.
std::string udsNamespace = "gatord_namespace";
gatordmock::GatordMockService mockService(registry, false);
@@ -157,10 +150,18 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd)
{
BOOST_FAIL("Failed to connect client");
}
+
// Give the profiling service sending thread time start executing and send the stream metadata.
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- // We should now be in WaitingForAck state.
- BOOST_CHECK(profilingService.GetCurrentState() == profiling::ProfilingState::WaitingForAck);
+ while (profilingService.GetCurrentState() != profiling::ProfilingState::WaitingForAck)
+ {
+ if (timeSlept >= timeout)
+ {
+ BOOST_FAIL("Timeout: Profiling service did not switch to WaitingForAck state");
+ }
+ std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
+ timeSlept += sleepTime;
+ }
+
profilingService.Update();
// Read the stream metadata on the mock side.
if (!mockService.WaitForStreamMetaData())
@@ -169,15 +170,115 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd)
}
// Send Ack from GatorD
mockService.SendConnectionAck();
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- // At this point the service should be in active state.
- BOOST_ASSERT(profilingService.GetCurrentState() == profiling::ProfilingState::Active);
- // Future tests here will add counters to the ProfilingService, increment values and examine
- // PeriodicCounterCapture data received. These are yet to be integrated.
+ timeSlept = 0;
+ while (profilingService.GetCurrentState() != profiling::ProfilingState::Active)
+ {
+ if (timeSlept >= timeout)
+ {
+ BOOST_FAIL("Timeout: Profiling service did not switch to Active state");
+ }
+ std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
+ timeSlept += sleepTime;
+ }
+
+ mockService.LaunchReceivingThread();
+ mockService.SendRequestCounterDir();
+
+ timeSlept = 0;
+ while (directoryCaptureCommandHandler.GetCounterDirectoryCount() == 0)
+ {
+ if (timeSlept >= timeout)
+ {
+ BOOST_FAIL("Timeout: MockGatord did not receive counter directory packet");
+ }
+ std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
+ timeSlept += sleepTime;
+ }
+ const profiling::ICounterDirectory& serviceCounterDirectory = profilingService.GetCounterDirectory();
+ gatordmock::CounterDirectory mockCounterDirectory = directoryCaptureCommandHandler.GetCounterDirectory();
+
+ BOOST_ASSERT(serviceCounterDirectory.GetDeviceCount() == mockCounterDirectory.m_DeviceRecords.size());
+ BOOST_ASSERT(serviceCounterDirectory.GetCounterSetCount() == mockCounterDirectory.m_CounterSets.size());
+ BOOST_ASSERT(serviceCounterDirectory.GetCategoryCount() == mockCounterDirectory.m_Categories.size());
+
+ const profiling::Devices& serviceDevices = serviceCounterDirectory.GetDevices();
+
+ uint32_t deviceIndex = 0;
+ for (auto& device : serviceDevices)
+ {
+ BOOST_ASSERT(device.second->m_Name.size() ==
+ mockCounterDirectory.m_DeviceRecords[deviceIndex].m_DeviceName.size());
+
+ BOOST_CHECK(device.second->m_Name == mockCounterDirectory.m_DeviceRecords[deviceIndex].m_DeviceName);
+ BOOST_CHECK(device.second->m_Uid == mockCounterDirectory.m_DeviceRecords[deviceIndex].m_DeviceUid);
+ BOOST_CHECK(device.second->m_Cores == mockCounterDirectory.m_DeviceRecords[deviceIndex].m_DeviceCores);
+ deviceIndex++;
+ }
+
+ const profiling::CounterSets & serviceCounterSets = serviceCounterDirectory.GetCounterSets();
+ uint32_t counterSetIndex = 0;
+ for (auto& counterSet : serviceCounterSets)
+ {
+ BOOST_ASSERT(counterSet.second->m_Name.size() ==
+ mockCounterDirectory.m_CounterSets[counterSetIndex].m_CounterSetName.size());
+
+ BOOST_CHECK(counterSet.second->m_Name == mockCounterDirectory.m_CounterSets[counterSetIndex].m_CounterSetName);
+ BOOST_CHECK(counterSet.second->m_Uid == mockCounterDirectory.m_CounterSets[counterSetIndex].m_CounterSetUid);
+ BOOST_CHECK(counterSet.second->m_Count ==
+ mockCounterDirectory.m_CounterSets[counterSetIndex].m_CounterSetCount);
+ counterSetIndex++;
+ }
+
+ const profiling::Categories& serviceCategories = serviceCounterDirectory.GetCategories();
+ const std::vector<gatordmock::CategoryRecord> mockCategories = mockCounterDirectory.m_Categories;
+
+ uint32_t categoryIndex = 0;
+ for (auto& category : serviceCategories)
+ {
+ BOOST_ASSERT(category->m_Name.size() == mockCategories[categoryIndex].m_CategoryName.size());
+
+ BOOST_CHECK(category->m_Name == mockCategories[categoryIndex].m_CategoryName);
+ BOOST_CHECK(category->m_CounterSetUid == mockCategories[categoryIndex].m_CounterSet);
+ BOOST_CHECK(category->m_DeviceUid == mockCategories[categoryIndex].m_DeviceUid);
+
+ const std::vector<gatordmock::EventRecord> events = mockCategories[categoryIndex].m_EventRecords;
+ uint32_t eventIndex = 0;
+ for (uint16_t counterUid : category->m_Counters)
+ {
+ const profiling::Counter* counter = serviceCounterDirectory.GetCounter(counterUid);
+
+ BOOST_CHECK(counterUid == events[eventIndex].m_CounterUid);
+
+ BOOST_ASSERT(counter->m_Name.size() == events[eventIndex].m_CounterName.size());
+ BOOST_ASSERT(counter->m_Units.size() == events[eventIndex].m_CounterUnits.size());
+ BOOST_ASSERT(counter->m_Description.size() == events[eventIndex].m_CounterDescription.size());
+
+ BOOST_CHECK(counter->m_Name == events[eventIndex].m_CounterName);
+ BOOST_CHECK(counter->m_Units == events[eventIndex].m_CounterUnits);
+ BOOST_CHECK(counter->m_Description == events[eventIndex].m_CounterDescription);
+
+ BOOST_CHECK(counter->m_CounterSetUid == events[eventIndex].m_CounterSetUid);
+ BOOST_CHECK(counter->m_DeviceUid == events[eventIndex].m_DeviceUid);
+ BOOST_CHECK(counter->m_Uid == events[eventIndex].m_CounterUid);
+
+ BOOST_CHECK(counter->m_Multiplier == events[eventIndex].m_CounterMultiplier);
+ BOOST_CHECK(counter->m_MaxCounterUid == events[eventIndex].m_MaxCounterUid);
+ BOOST_CHECK(counter->m_Interpolation == events[eventIndex].m_CounterInterpolation);
+ BOOST_CHECK(counter->m_Class == events[eventIndex].m_CounterClass);
+
+ eventIndex++;
+ }
+ categoryIndex++;
+ }
+
+ mockService.WaitForReceivingThread();
options.m_EnableProfiling = false;
profilingService.ResetExternalProfilingOptions(options, true);
+
+ // Future tests here will add counters to the ProfilingService, increment values and examine
+ // PeriodicCounterCapture data received. These are yet to be integrated.
}
BOOST_AUTO_TEST_SUITE_END()