ArmNN
 20.02
ProfilingGuidTest.cpp File Reference
#include <armnn/Types.hpp>
#include "LabelsAndEventClasses.hpp"
#include "ProfilingGuidGenerator.hpp"
#include <set>
#include <boost/test/unit_test.hpp>
#include <boost/format.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (GuidTest)
 
 BOOST_AUTO_TEST_CASE (StaticGuidTest)
 
 BOOST_AUTO_TEST_CASE (DynamicGuidTest)
 
void CheckStaticGuid (uint64_t guid, uint64_t expectedGuid)
 
void CheckDynamicGuid (uint64_t guid, uint64_t expectedGuid)
 
 BOOST_AUTO_TEST_CASE (StaticGuidGeneratorCollisionTest)
 
 BOOST_AUTO_TEST_CASE (StaticGuidGeneratorTest)
 
 BOOST_AUTO_TEST_CASE (DynamicGuidGeneratorTest)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/6]

BOOST_AUTO_TEST_CASE ( GuidTest  )

Definition at line 20 of file ProfilingGuidTest.cpp.

21 {
22  ProfilingGuid guid0(0);
23  ProfilingGuid guid1(1);
24  ProfilingGuid guid2(1);
25 
26  BOOST_TEST(guid0 != guid1);
27  BOOST_TEST(guid1 == guid2);
28  BOOST_TEST(guid0 < guid1);
29  BOOST_TEST(guid0 <= guid1);
30  BOOST_TEST(guid1 <= guid2);
31  BOOST_TEST(guid1 > guid0);
32  BOOST_TEST(guid1 >= guid0);
33  BOOST_TEST(guid1 >= guid2);
34 }

◆ BOOST_AUTO_TEST_CASE() [2/6]

BOOST_AUTO_TEST_CASE ( StaticGuidTest  )

Definition at line 36 of file ProfilingGuidTest.cpp.

37 {
38  ProfilingStaticGuid guid0(0);
39  ProfilingStaticGuid guid1(1);
40  ProfilingStaticGuid guid2(1);
41 
42  BOOST_TEST(guid0 != guid1);
43  BOOST_TEST(guid1 == guid2);
44  BOOST_TEST(guid0 < guid1);
45  BOOST_TEST(guid0 <= guid1);
46  BOOST_TEST(guid1 <= guid2);
47  BOOST_TEST(guid1 > guid0);
48  BOOST_TEST(guid1 >= guid0);
49  BOOST_TEST(guid1 >= guid2);
50 }

◆ BOOST_AUTO_TEST_CASE() [3/6]

BOOST_AUTO_TEST_CASE ( DynamicGuidTest  )

Definition at line 52 of file ProfilingGuidTest.cpp.

53 {
54  ProfilingDynamicGuid guid0(0);
55  ProfilingDynamicGuid guid1(1);
56  ProfilingDynamicGuid guid2(1);
57 
58  BOOST_TEST(guid0 != guid1);
59  BOOST_TEST(guid1 == guid2);
60  BOOST_TEST(guid0 < guid1);
61  BOOST_TEST(guid0 <= guid1);
62  BOOST_TEST(guid1 <= guid2);
63  BOOST_TEST(guid1 > guid0);
64  BOOST_TEST(guid1 >= guid0);
65  BOOST_TEST(guid1 >= guid2);
66 }
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:294

◆ BOOST_AUTO_TEST_CASE() [4/6]

BOOST_AUTO_TEST_CASE ( StaticGuidGeneratorCollisionTest  )

Definition at line 80 of file ProfilingGuidTest.cpp.

References ProfilingGuidGenerator::GenerateStaticId().

81 {
82  ProfilingGuidGenerator generator;
83  std::set<uint64_t> guids;
84  for ( int i = 0; i < 100000; ++i )
85  {
86  std::stringstream ss;
87  ss << i;
88  std::string str = ss.str();
89  ProfilingStaticGuid guid = generator.GenerateStaticId(str.c_str());
90  if (guids.find(guid) != guids.end())
91  {
92  BOOST_ERROR(boost::str(boost::format("GUID collision occurred: %1% -> %2%") % str % guid));
93  break;
94  }
95  guids.insert(guid);
96  }
97 }
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.

◆ BOOST_AUTO_TEST_CASE() [5/6]

BOOST_AUTO_TEST_CASE ( StaticGuidGeneratorTest  )

Definition at line 99 of file ProfilingGuidTest.cpp.

References CheckStaticGuid(), ProfilingGuidGenerator::GenerateStaticId(), LabelsAndEventClasses::INDEX_GUID, LabelsAndEventClasses::NAME_GUID, and LabelsAndEventClasses::TYPE_GUID.

100 {
101  ProfilingGuidGenerator generator;
102 
103  ProfilingStaticGuid staticGuid0 = generator.GenerateStaticId("name");
104  CheckStaticGuid(staticGuid0, LabelsAndEventClasses::NAME_GUID);
105  BOOST_TEST(staticGuid0 != generator.GenerateStaticId("Name"));
106 
107  ProfilingStaticGuid staticGuid1 = generator.GenerateStaticId("type");
108  CheckStaticGuid(staticGuid1, LabelsAndEventClasses::TYPE_GUID);
109  BOOST_TEST(staticGuid1 != generator.GenerateStaticId("Type"));
110 
111  ProfilingStaticGuid staticGuid2 = generator.GenerateStaticId("index");
112  CheckStaticGuid(staticGuid2, LabelsAndEventClasses::INDEX_GUID);
113  BOOST_TEST(staticGuid2 != generator.GenerateStaticId("Index"));
114 }
void CheckStaticGuid(uint64_t guid, uint64_t expectedGuid)
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.

◆ BOOST_AUTO_TEST_CASE() [6/6]

BOOST_AUTO_TEST_CASE ( DynamicGuidGeneratorTest  )

Definition at line 116 of file ProfilingGuidTest.cpp.

References BOOST_AUTO_TEST_SUITE_END(), CheckDynamicGuid(), and ProfilingGuidGenerator::NextGuid().

117 {
118  ProfilingGuidGenerator generator;
119 
120  for (unsigned int i = 0; i < 100; ++i)
121  {
122  ProfilingDynamicGuid guid = generator.NextGuid();
123  CheckDynamicGuid(guid, i);
124  }
125 }
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:294
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.
void CheckDynamicGuid(uint64_t guid, uint64_t expectedGuid)

◆ CheckDynamicGuid()

void CheckDynamicGuid ( uint64_t  guid,
uint64_t  expectedGuid 
)

Definition at line 74 of file ProfilingGuidTest.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

75 {
76  BOOST_TEST(guid == expectedGuid);
77  BOOST_TEST(guid < MIN_STATIC_GUID);
78 }

◆ CheckStaticGuid()

void CheckStaticGuid ( uint64_t  guid,
uint64_t  expectedGuid 
)

Definition at line 68 of file ProfilingGuidTest.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

69 {
70  BOOST_TEST(guid == expectedGuid);
71  BOOST_TEST(guid >= MIN_STATIC_GUID);
72 }