blob: b0f01300029564306b526b4b567662e9520da1f4 [file] [log] [blame]
Matt Spinler97f7abc2019-11-06 09:40:23 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinlerb6664332019-09-10 15:24:10 -050016#include "extensions/openpower-pels/mtms.hpp"
17
18#include <gtest/gtest.h>
19
20using namespace openpower::pels;
21
22TEST(MTMSTest, SizeTest)
23{
24 EXPECT_EQ(MTMS::flattenedSize(), 20);
25}
26
27TEST(MTMSTest, ConstructorTest)
28{
29 {
30 std::string tm{"TTTT-MMM"};
31 std::string sn{"123456789ABC"};
32
33 MTMS mtms{tm, sn};
34
Matt Spinlerbe952d22022-07-01 11:30:11 -050035 const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050036 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
37 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -050038
Matt Spinlerbe952d22022-07-01 11:30:11 -050039 const std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
40 '7', '8', '9', 'A', 'B', 'C'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050041 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
42 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -050043 }
44
45 {
46 // too long- truncate it
47 std::string tm{"TTTT-MMME"};
48 std::string sn{"123456789ABCE"};
49
50 MTMS mtms{tm, sn};
51
Matt Spinlerbe952d22022-07-01 11:30:11 -050052 const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050053 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
Matt Spinlerb6664332019-09-10 15:24:10 -050054
Matt Spinlerbe952d22022-07-01 11:30:11 -050055 const std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
56 '7', '8', '9', 'A', 'B', 'C'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050057 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
Matt Spinlerb6664332019-09-10 15:24:10 -050058 }
59
60 {
61 // short
62 std::string tm{"TTTT"};
63 std::string sn{"1234"};
64
65 MTMS mtms{tm, sn};
66
Matt Spinlerbe952d22022-07-01 11:30:11 -050067 const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', 0, 0, 0, 0};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050068 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
69 EXPECT_EQ("TTTT", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -050070
Matt Spinlerbe952d22022-07-01 11:30:11 -050071 const std::array<uint8_t, 12> s{'1', '2', '3', '4', 0, 0,
72 0, 0, 0, 0, 0, 0};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050073 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
74 EXPECT_EQ("1234", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -050075 }
76
77 {
78 // Stream constructor
79 std::vector<uint8_t> data{'T', 'T', 'T', 'T', '-', 'M', 'M',
80 'M', '1', '2', '3', '4', '5', '6',
81 '7', '8', '9', 'A', 'B', 'C'};
82 Stream stream{data};
83
84 MTMS mtms{stream};
85
Matt Spinler4b59f7a2019-10-08 13:55:17 -050086 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -050087
Matt Spinler4b59f7a2019-10-08 13:55:17 -050088 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -050089 }
90}
91
92TEST(MTMSTest, OperatorExtractTest)
93{
94 std::string tm{"TTTT-MMM"};
95 std::string sn{"123456789ABC"};
96
97 MTMS mtms{tm, sn};
98
99 // Check that we can extract the same data
100 std::vector<uint8_t> data;
101 Stream stream{data};
102 stream << mtms;
103
104 std::vector<uint8_t> expected{'T', 'T', 'T', 'T', '-', 'M', 'M',
105 'M', '1', '2', '3', '4', '5', '6',
106 '7', '8', '9', 'A', 'B', 'C'};
107 EXPECT_EQ(expected, data);
108}
109
110TEST(MTMSTest, OperatorInsertTest)
111{
112 std::vector<uint8_t> data{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M', '1', '2',
113 '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'};
114 Stream stream{data};
115
116 // Check that when we insert data it is what's expected
117 MTMS mtms;
118 stream >> mtms;
119
Matt Spinler4b59f7a2019-10-08 13:55:17 -0500120 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -0500121
Matt Spinler4b59f7a2019-10-08 13:55:17 -0500122 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -0500123}