1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright 2019 IBM Corporation
3
4 #include "extensions/openpower-pels/mtms.hpp"
5
6 #include <gtest/gtest.h>
7
8 using namespace openpower::pels;
9
TEST(MTMSTest,SizeTest)10 TEST(MTMSTest, SizeTest)
11 {
12 EXPECT_EQ(MTMS::flattenedSize(), 20);
13 }
14
TEST(MTMSTest,ConstructorTest)15 TEST(MTMSTest, ConstructorTest)
16 {
17 {
18 std::string tm{"TTTT-MMM"};
19 std::string sn{"123456789ABC"};
20
21 MTMS mtms{tm, sn};
22
23 const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
24 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
25 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
26
27 const std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
28 '7', '8', '9', 'A', 'B', 'C'};
29 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
30 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
31 }
32
33 {
34 // too long- truncate it
35 std::string tm{"TTTT-MMME"};
36 std::string sn{"123456789ABCE"};
37
38 MTMS mtms{tm, sn};
39
40 const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
41 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
42
43 const std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
44 '7', '8', '9', 'A', 'B', 'C'};
45 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
46 }
47
48 {
49 // short
50 std::string tm{"TTTT"};
51 std::string sn{"1234"};
52
53 MTMS mtms{tm, sn};
54
55 const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', 0, 0, 0, 0};
56 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
57 EXPECT_EQ("TTTT", mtms.machineTypeAndModel());
58
59 const std::array<uint8_t, 12> s{'1', '2', '3', '4', 0, 0,
60 0, 0, 0, 0, 0, 0};
61 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
62 EXPECT_EQ("1234", mtms.machineSerialNumber());
63 }
64
65 {
66 // Stream constructor
67 std::vector<uint8_t> data{'T', 'T', 'T', 'T', '-', 'M', 'M',
68 'M', '1', '2', '3', '4', '5', '6',
69 '7', '8', '9', 'A', 'B', 'C'};
70 Stream stream{data};
71
72 MTMS mtms{stream};
73
74 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
75
76 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
77 }
78 }
79
TEST(MTMSTest,OperatorExtractTest)80 TEST(MTMSTest, OperatorExtractTest)
81 {
82 std::string tm{"TTTT-MMM"};
83 std::string sn{"123456789ABC"};
84
85 MTMS mtms{tm, sn};
86
87 // Check that we can extract the same data
88 std::vector<uint8_t> data;
89 Stream stream{data};
90 stream << mtms;
91
92 std::vector<uint8_t> expected{'T', 'T', 'T', 'T', '-', 'M', 'M',
93 'M', '1', '2', '3', '4', '5', '6',
94 '7', '8', '9', 'A', 'B', 'C'};
95 EXPECT_EQ(expected, data);
96 }
97
TEST(MTMSTest,OperatorInsertTest)98 TEST(MTMSTest, OperatorInsertTest)
99 {
100 std::vector<uint8_t> data{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M', '1', '2',
101 '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'};
102 Stream stream{data};
103
104 // Check that when we insert data it is what's expected
105 MTMS mtms;
106 stream >> mtms;
107
108 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
109
110 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
111 }
112