From 94a3088479694ee1dfdd2e321a353ffcc79f4126 Mon Sep 17 00:00:00 2001 From: Narumol Prangnawarat Date: Wed, 30 Oct 2019 12:48:31 +0000 Subject: IVGCVSW-4037 Add a CreateNamedTypedChildEntity method * Added new method to the TimelineUtilityMethods class * Added unit tests * Code refactoring * Skipped the 0 when generating a dynamic GUID for testing purposes Signed-off-by: Matteo Martincigh Change-Id: Ic2c8033ad010e07b0f8b7971ce653263e21c6f97 --- src/profiling/test/TimelineUtilityMethodsTests.cpp | 101 +++++++++++++++++++-- 1 file changed, 93 insertions(+), 8 deletions(-) (limited to 'src/profiling/test/TimelineUtilityMethodsTests.cpp') diff --git a/src/profiling/test/TimelineUtilityMethodsTests.cpp b/src/profiling/test/TimelineUtilityMethodsTests.cpp index 6c5ce634a4..c2be6e5c46 100644 --- a/src/profiling/test/TimelineUtilityMethodsTests.cpp +++ b/src/profiling/test/TimelineUtilityMethodsTests.cpp @@ -231,9 +231,9 @@ void VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType relationsh offset += uint64_t_size; } -void VerifyTimelineEntityPacket(Optional guid, - const unsigned char* readableData, - unsigned int& offset) +void VerifyTimelineEntityBinaryPacket(Optional guid, + const unsigned char* readableData, + unsigned int& offset) { BOOST_ASSERT(readableData); @@ -380,7 +380,7 @@ BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest) readableData, offset); - // First "well-known" event class: END OF LIFE + // Second "well-known" event class: END OF LIFE VerifyTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, readableData, offset); @@ -389,6 +389,94 @@ BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest) mockBufferManager.MarkRead(readableBuffer); } +BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest) +{ + MockBufferManager mockBufferManager(1024); + SendTimelinePacket sendTimelinePacket(mockBufferManager); + TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); + + ProfilingGuid parentEntityGuid(123); + const std::string entityName = "some entity"; + const std::string entityType = "some type"; + + BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, "", entityType), + InvalidArgumentException); + BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, entityName, ""), + InvalidArgumentException); + + ProfilingGuid childEntityGuid(0); + BOOST_CHECK_NO_THROW(childEntityGuid = timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, + entityName, + entityType)); + BOOST_CHECK(childEntityGuid != ProfilingGuid(0)); + + // Commit all packets at once + sendTimelinePacket.Commit(); + + // Get the readable buffer + auto readableBuffer = mockBufferManager.GetReadableBuffer(); + BOOST_CHECK(readableBuffer != nullptr); + unsigned int size = readableBuffer->GetSize(); + BOOST_CHECK(size == 292); + const unsigned char* readableData = readableBuffer->GetReadableData(); + BOOST_CHECK(readableData != nullptr); + + // Utils + unsigned int offset = 0; + + // First packet sent: TimelineEntityBinaryPacket + VerifyTimelineEntityBinaryPacket(EmptyOptional(), readableData, offset); + + // Second packet sent: TimelineLabelBinaryPacket + VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); + + // Third packet sent: TimelineRelationshipBinaryPacket + VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, + EmptyOptional(), + EmptyOptional(), + EmptyOptional(), + readableData, + offset); + + // Fourth packet sent: TimelineRelationshipBinaryPacket + VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, + EmptyOptional(), + EmptyOptional(), + LabelsAndEventClasses::NAME_GUID, + readableData, + offset); + + // Fifth packet sent: TimelineLabelBinaryPacket + VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset); + + // Sixth packet sent: TimelineRelationshipBinaryPacket + VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, + EmptyOptional(), + EmptyOptional(), + EmptyOptional(), + readableData, + offset); + + // Seventh packet sent: TimelineRelationshipBinaryPacket + VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, + EmptyOptional(), + EmptyOptional(), + LabelsAndEventClasses::TYPE_GUID, + readableData, + offset); + + // Eighth packet sent: TimelineRelationshipBinaryPacket + VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, + EmptyOptional(), + parentEntityGuid, + EmptyOptional(), + readableData, + offset); + + // Mark the buffer as read + mockBufferManager.MarkRead(readableBuffer); +} + BOOST_AUTO_TEST_CASE(DeclareLabelTest) { MockBufferManager mockBufferManager(1024); @@ -439,9 +527,6 @@ BOOST_AUTO_TEST_CASE(CreateNameTypeEntitylTest) const std::string entityName = "Entity0"; const std::string entityType = "Type0"; - // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. - ProfilingService::Instance().NextGuid(); - ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType); BOOST_CHECK(guid != ProfilingGuid(0)); @@ -460,7 +545,7 @@ BOOST_AUTO_TEST_CASE(CreateNameTypeEntitylTest) unsigned int offset = 0; // First packet sent: TimelineEntityBinaryPacket - VerifyTimelineEntityPacket(guid, readableData, offset); + VerifyTimelineEntityBinaryPacket(guid, readableData, offset); // Packets for Name Entity // First packet sent: TimelineLabelBinaryPacket -- cgit v1.2.1