Matt Spinler | 97f7abc | 2019-11-06 09:40:23 -0600 | [diff] [blame] | 1 | /** |
| 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 Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 16 | #include "extensions/openpower-pels/mtms.hpp" |
| 17 | |
| 18 | #include <gtest/gtest.h> |
| 19 | |
| 20 | using namespace openpower::pels; |
| 21 | |
| 22 | TEST(MTMSTest, SizeTest) |
| 23 | { |
| 24 | EXPECT_EQ(MTMS::flattenedSize(), 20); |
| 25 | } |
| 26 | |
| 27 | TEST(MTMSTest, ConstructorTest) |
| 28 | { |
| 29 | { |
| 30 | std::string tm{"TTTT-MMM"}; |
| 31 | std::string sn{"123456789ABC"}; |
| 32 | |
| 33 | MTMS mtms{tm, sn}; |
| 34 | |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 35 | const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'}; |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 36 | EXPECT_EQ(t, mtms.machineTypeAndModelRaw()); |
| 37 | EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 38 | |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 39 | const std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6', |
| 40 | '7', '8', '9', 'A', 'B', 'C'}; |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 41 | EXPECT_EQ(s, mtms.machineSerialNumberRaw()); |
| 42 | EXPECT_EQ("123456789ABC", mtms.machineSerialNumber()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 43 | } |
| 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 Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 52 | const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'}; |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 53 | EXPECT_EQ(t, mtms.machineTypeAndModelRaw()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 54 | |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 55 | const std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6', |
| 56 | '7', '8', '9', 'A', 'B', 'C'}; |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 57 | EXPECT_EQ(s, mtms.machineSerialNumberRaw()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | { |
| 61 | // short |
| 62 | std::string tm{"TTTT"}; |
| 63 | std::string sn{"1234"}; |
| 64 | |
| 65 | MTMS mtms{tm, sn}; |
| 66 | |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 67 | const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', 0, 0, 0, 0}; |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 68 | EXPECT_EQ(t, mtms.machineTypeAndModelRaw()); |
| 69 | EXPECT_EQ("TTTT", mtms.machineTypeAndModel()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 70 | |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 71 | const std::array<uint8_t, 12> s{'1', '2', '3', '4', 0, 0, |
| 72 | 0, 0, 0, 0, 0, 0}; |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 73 | EXPECT_EQ(s, mtms.machineSerialNumberRaw()); |
| 74 | EXPECT_EQ("1234", mtms.machineSerialNumber()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 75 | } |
| 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 Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 86 | EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 87 | |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 88 | EXPECT_EQ("123456789ABC", mtms.machineSerialNumber()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | TEST(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 | |
| 110 | TEST(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 Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 120 | EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 121 | |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 122 | EXPECT_EQ("123456789ABC", mtms.machineSerialNumber()); |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 123 | } |