IVGCVSW-3415 Create the Packet Class
[platform/upstream/armnn.git] / src / profiling / test / ProfilingTests.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "../CommandHandlerKey.hpp"
7 #include "../Packet.hpp"
8
9 #include <cstdint>
10 #include <cstring>
11 #include <boost/test/unit_test.hpp>
12
13 BOOST_AUTO_TEST_SUITE(ExternalProfiling)
14
15 BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons)
16 {
17     CommandHandlerKey testKey0(1, 1);
18     CommandHandlerKey testKey1(1, 1);
19     CommandHandlerKey testKey2(1, 1);
20     CommandHandlerKey testKey3(0, 0);
21     CommandHandlerKey testKey4(2, 2);
22     CommandHandlerKey testKey5(0, 2);
23
24     BOOST_CHECK(testKey1<testKey4);
25     BOOST_CHECK(testKey1>testKey3);
26     BOOST_CHECK(testKey1<=testKey4);
27     BOOST_CHECK(testKey1>=testKey3);
28     BOOST_CHECK(testKey1<=testKey2);
29     BOOST_CHECK(testKey1>=testKey2);
30     BOOST_CHECK(testKey1==testKey2);
31     BOOST_CHECK(testKey1==testKey1);
32
33     BOOST_CHECK(!(testKey1==testKey5));
34     BOOST_CHECK(!(testKey1!=testKey1));
35     BOOST_CHECK(testKey1!=testKey5);
36
37     BOOST_CHECK(testKey1==testKey2 && testKey2==testKey1);
38     BOOST_CHECK(testKey0==testKey1 && testKey1==testKey2 && testKey0==testKey2);
39
40     BOOST_CHECK(testKey1.GetPacketId()==1);
41     BOOST_CHECK(testKey1.GetVersion()==1);
42
43     std::vector<CommandHandlerKey> vect =
44         {
45             CommandHandlerKey(0,1), CommandHandlerKey(2,0), CommandHandlerKey(1,0),
46             CommandHandlerKey(2,1), CommandHandlerKey(1,1), CommandHandlerKey(0,1),
47             CommandHandlerKey(2,0), CommandHandlerKey(0,0)
48         };
49
50     std::sort(vect.begin(), vect.end());
51
52     std::vector<CommandHandlerKey> expectedVect =
53         {
54             CommandHandlerKey(0,0), CommandHandlerKey(0,1), CommandHandlerKey(0,1),
55             CommandHandlerKey(1,0), CommandHandlerKey(1,1), CommandHandlerKey(2,0),
56             CommandHandlerKey(2,0), CommandHandlerKey(2,1)
57         };
58
59     BOOST_CHECK(vect == expectedVect);
60 }
61
62 BOOST_AUTO_TEST_CASE(CheckPacketClass)
63 {
64     const char* data = "test";
65     unsigned int length = static_cast<unsigned int>(std::strlen(data));
66
67     Packet packetTest1(472580096,length,data);
68     BOOST_CHECK_THROW(Packet packetTest2(472580096,0,""), armnn::Exception);
69
70     Packet packetTest3(472580096,0, nullptr);
71
72     BOOST_CHECK(packetTest1.GetLength() == length);
73     BOOST_CHECK(packetTest1.GetData() == data);
74
75     BOOST_CHECK(packetTest1.GetPacketFamily() == 7);
76     BOOST_CHECK(packetTest1.GetPacketId() == 43);
77     BOOST_CHECK(packetTest1.GetPacketType() == 3);
78     BOOST_CHECK(packetTest1.GetPacketClass() == 5);
79 }
80
81 BOOST_AUTO_TEST_SUITE_END()