ArmNN
 20.02
ProfilingGuidTest.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <armnn/Types.hpp>
7 
10 
11 #include <set>
12 
13 #include <boost/test/unit_test.hpp>
14 #include <boost/format.hpp>
15 
16 using namespace armnn::profiling;
17 
18 BOOST_AUTO_TEST_SUITE(ProfilingGuidTests)
19 
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 }
35 
36 BOOST_AUTO_TEST_CASE(StaticGuidTest)
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 }
51 
52 BOOST_AUTO_TEST_CASE(DynamicGuidTest)
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 }
67 
68 void CheckStaticGuid(uint64_t guid, uint64_t expectedGuid)
69 {
70  BOOST_TEST(guid == expectedGuid);
71  BOOST_TEST(guid >= MIN_STATIC_GUID);
72 }
73 
74 void CheckDynamicGuid(uint64_t guid, uint64_t expectedGuid)
75 {
76  BOOST_TEST(guid == expectedGuid);
77  BOOST_TEST(guid < MIN_STATIC_GUID);
78 }
79 
80 BOOST_AUTO_TEST_CASE(StaticGuidGeneratorCollisionTest)
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 }
98 
99 BOOST_AUTO_TEST_CASE(StaticGuidGeneratorTest)
100 {
101  ProfilingGuidGenerator generator;
102 
103  ProfilingStaticGuid staticGuid0 = generator.GenerateStaticId("name");
105  BOOST_TEST(staticGuid0 != generator.GenerateStaticId("Name"));
106 
107  ProfilingStaticGuid staticGuid1 = generator.GenerateStaticId("type");
109  BOOST_TEST(staticGuid1 != generator.GenerateStaticId("Type"));
110 
111  ProfilingStaticGuid staticGuid2 = generator.GenerateStaticId("index");
113  BOOST_TEST(staticGuid2 != generator.GenerateStaticId("Index"));
114 }
115 
116 BOOST_AUTO_TEST_CASE(DynamicGuidGeneratorTest)
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 }
126 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
void CheckStaticGuid(uint64_t guid, uint64_t expectedGuid)
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:294
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.
static ARMNN_DLLEXPORT ProfilingStaticGuid NAME_GUID
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
BOOST_AUTO_TEST_SUITE_END()
static ARMNN_DLLEXPORT ProfilingStaticGuid INDEX_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid TYPE_GUID
void CheckDynamicGuid(uint64_t guid, uint64_t expectedGuid)