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

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)
 
 BOOST_AUTO_TEST_CASE (ProfilingGuidThreadTest)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/7]

BOOST_AUTO_TEST_CASE ( GuidTest  )

Definition at line 21 of file ProfilingGuidTest.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [2/7]

BOOST_AUTO_TEST_CASE ( StaticGuidTest  )

Definition at line 37 of file ProfilingGuidTest.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [3/7]

BOOST_AUTO_TEST_CASE ( DynamicGuidTest  )

Definition at line 53 of file ProfilingGuidTest.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [4/7]

BOOST_AUTO_TEST_CASE ( StaticGuidGeneratorCollisionTest  )

Definition at line 81 of file ProfilingGuidTest.cpp.

References ProfilingGuidGenerator::GenerateStaticId().

82 {
83  ProfilingGuidGenerator generator;
84  std::set<uint64_t> guids;
85  for ( int i = 0; i < 100000; ++i )
86  {
87  std::stringstream ss;
88  ss << i;
89  std::string str = ss.str();
90  ProfilingStaticGuid guid = generator.GenerateStaticId(str.c_str());
91  if (guids.find(guid) != guids.end())
92  {
93  // If we're running on a 32bit system it is more likely to get a GUID clash over 1 million executions.
94  // We can generally detect this when the GUID turns out to be MIN_STATIC_GUID. Output a warning
95  // message rather than error in this case.
96  if (guid == ProfilingGuid(armnn::profiling::MIN_STATIC_GUID))
97  {
98  BOOST_WARN("MIN_STATIC_GUID returned more than once from GenerateStaticId.");
99  }
100  else
101  {
102  BOOST_ERROR(fmt::format("GUID collision occurred: {} -> {}", str, guid));
103  }
104  break;
105  }
106  guids.insert(guid);
107  }
108 }
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.

◆ BOOST_AUTO_TEST_CASE() [5/7]

BOOST_AUTO_TEST_CASE ( StaticGuidGeneratorTest  )

Definition at line 110 of file ProfilingGuidTest.cpp.

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

111 {
112  ProfilingGuidGenerator generator;
113 
114  ProfilingStaticGuid staticGuid0 = generator.GenerateStaticId("name");
115  CheckStaticGuid(staticGuid0, LabelsAndEventClasses::NAME_GUID);
116  BOOST_TEST(staticGuid0 != generator.GenerateStaticId("Name"));
117 
118  ProfilingStaticGuid staticGuid1 = generator.GenerateStaticId("type");
119  CheckStaticGuid(staticGuid1, LabelsAndEventClasses::TYPE_GUID);
120  BOOST_TEST(staticGuid1 != generator.GenerateStaticId("Type"));
121 
122  ProfilingStaticGuid staticGuid2 = generator.GenerateStaticId("index");
123  CheckStaticGuid(staticGuid2, LabelsAndEventClasses::INDEX_GUID);
124  BOOST_TEST(staticGuid2 != generator.GenerateStaticId("Index"));
125 }
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/7]

BOOST_AUTO_TEST_CASE ( DynamicGuidGeneratorTest  )

Definition at line 127 of file ProfilingGuidTest.cpp.

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

128 {
129  ProfilingGuidGenerator generator;
130 
131  for (unsigned int i = 0; i < 100; ++i)
132  {
133  ProfilingDynamicGuid guid = generator.NextGuid();
134  CheckDynamicGuid(guid, i);
135  }
136 }
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:371
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.
void CheckDynamicGuid(uint64_t guid, uint64_t expectedGuid)

◆ BOOST_AUTO_TEST_CASE() [7/7]

BOOST_AUTO_TEST_CASE ( ProfilingGuidThreadTest  )

Definition at line 138 of file ProfilingGuidTest.cpp.

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

139 {
140  ProfilingGuidGenerator profilingGuidGenerator;
141 
142  auto guidGenerator = [&profilingGuidGenerator]()
143  {
144  for (int i = 0; i < 1000; ++i)
145  {
146  profilingGuidGenerator.NextGuid();
147  }
148  };
149 
150  std::thread t1(guidGenerator);
151  std::thread t2(guidGenerator);
152  std::thread t3(guidGenerator);
153 
154  t1.join();
155  t2.join();
156  t3.join();
157 
158  uint64_t guid = profilingGuidGenerator.NextGuid();
159  BOOST_CHECK(guid == 3000u);
160 }
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.

◆ CheckDynamicGuid()

void CheckDynamicGuid ( uint64_t  guid,
uint64_t  expectedGuid 
)

Definition at line 75 of file ProfilingGuidTest.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

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

◆ CheckStaticGuid()

void CheckStaticGuid ( uint64_t  guid,
uint64_t  expectedGuid 
)

Definition at line 69 of file ProfilingGuidTest.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

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