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 | 6c9662c | 2019-10-09 11:27:20 -0500 | [diff] [blame] | 16 | #include "extensions/openpower-pels/callout.hpp" |
| 17 | #include "pel_utils.hpp" |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | using namespace openpower::pels; |
| 22 | using namespace openpower::pels::src; |
| 23 | |
| 24 | // Unflatten the callout section with all three substructures |
| 25 | TEST(CalloutTest, TestUnflattenAllSubstructures) |
| 26 | { |
| 27 | // The base data. |
| 28 | std::vector<uint8_t> data{ |
| 29 | 0xFF, 0x2F, 'H', 8, // size, flags, priority, LC length |
| 30 | 'U', '1', '2', '-', 'P', '1', 0x00, 0x00 // LC |
| 31 | }; |
| 32 | |
| 33 | auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure); |
| 34 | auto pceIdentity = srcDataFactory(TestSRCType::pceIdentityStructure); |
| 35 | auto mrus = srcDataFactory(TestSRCType::mruStructure); |
| 36 | |
| 37 | // Add all 3 substructures |
| 38 | data.insert(data.end(), fruIdentity.begin(), fruIdentity.end()); |
| 39 | data.insert(data.end(), pceIdentity.begin(), pceIdentity.end()); |
| 40 | data.insert(data.end(), mrus.begin(), mrus.end()); |
| 41 | |
| 42 | // The final size |
| 43 | data[0] = data.size(); |
| 44 | |
| 45 | Stream stream{data}; |
| 46 | Callout callout{stream}; |
| 47 | |
| 48 | EXPECT_EQ(callout.flattenedSize(), data.size()); |
| 49 | EXPECT_EQ(callout.priority(), 'H'); |
| 50 | EXPECT_EQ(callout.locationCode(), "U12-P1"); |
| 51 | |
| 52 | // Spot check the 3 substructures |
| 53 | EXPECT_TRUE(callout.fruIdentity()); |
| 54 | EXPECT_EQ(callout.fruIdentity()->getSN(), "123456789ABC"); |
| 55 | |
| 56 | EXPECT_TRUE(callout.pceIdentity()); |
| 57 | EXPECT_EQ(callout.pceIdentity()->enclosureName(), "PCENAME12"); |
| 58 | |
| 59 | EXPECT_TRUE(callout.mru()); |
| 60 | EXPECT_EQ(callout.mru()->mrus().size(), 4); |
| 61 | EXPECT_EQ(callout.mru()->mrus().at(3).id, 0x04040404); |
| 62 | |
| 63 | // Now flatten |
| 64 | std::vector<uint8_t> newData; |
| 65 | Stream newStream{newData}; |
| 66 | |
| 67 | callout.flatten(newStream); |
| 68 | EXPECT_EQ(data, newData); |
| 69 | } |
| 70 | |
| 71 | TEST(CalloutTest, TestUnflattenOneSubstructure) |
| 72 | { |
| 73 | std::vector<uint8_t> data{ |
| 74 | 0xFF, 0x28, 'H', 0x08, // size, flags, priority, LC length |
| 75 | 'U', '1', '2', '-', 'P', '1', 0x00, 0x00 // LC |
| 76 | }; |
| 77 | |
| 78 | auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure); |
| 79 | |
| 80 | data.insert(data.end(), fruIdentity.begin(), fruIdentity.end()); |
| 81 | |
| 82 | // The final size |
| 83 | data[0] = data.size(); |
| 84 | |
| 85 | Stream stream{data}; |
| 86 | Callout callout{stream}; |
| 87 | |
| 88 | EXPECT_EQ(callout.flattenedSize(), data.size()); |
| 89 | |
| 90 | // Spot check the substructure |
| 91 | EXPECT_TRUE(callout.fruIdentity()); |
| 92 | EXPECT_EQ(callout.fruIdentity()->getSN(), "123456789ABC"); |
| 93 | |
| 94 | // Not present |
| 95 | EXPECT_FALSE(callout.pceIdentity()); |
| 96 | EXPECT_FALSE(callout.mru()); |
| 97 | |
| 98 | // Now flatten |
| 99 | std::vector<uint8_t> newData; |
| 100 | Stream newStream{newData}; |
| 101 | |
| 102 | callout.flatten(newStream); |
| 103 | EXPECT_EQ(data, newData); |
| 104 | } |
| 105 | |
| 106 | TEST(CalloutTest, TestUnflattenTwoSubstructures) |
| 107 | { |
| 108 | std::vector<uint8_t> data{ |
| 109 | 0xFF, 0x2B, 'H', 0x08, // size, flags, priority, LC length |
| 110 | 'U', '1', '2', '-', 'P', '1', 0x00, 0x00 // LC |
| 111 | }; |
| 112 | |
| 113 | auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure); |
| 114 | auto pceIdentity = srcDataFactory(TestSRCType::pceIdentityStructure); |
| 115 | |
| 116 | data.insert(data.end(), fruIdentity.begin(), fruIdentity.end()); |
| 117 | data.insert(data.end(), pceIdentity.begin(), pceIdentity.end()); |
| 118 | |
| 119 | // The final size |
| 120 | data[0] = data.size(); |
| 121 | |
| 122 | Stream stream{data}; |
| 123 | Callout callout{stream}; |
| 124 | |
| 125 | EXPECT_EQ(callout.flattenedSize(), data.size()); |
| 126 | |
| 127 | // Spot check the 2 substructures |
| 128 | EXPECT_TRUE(callout.fruIdentity()); |
| 129 | EXPECT_EQ(callout.fruIdentity()->getSN(), "123456789ABC"); |
| 130 | |
| 131 | EXPECT_TRUE(callout.pceIdentity()); |
| 132 | EXPECT_EQ(callout.pceIdentity()->enclosureName(), "PCENAME12"); |
| 133 | |
| 134 | // Not present |
| 135 | EXPECT_FALSE(callout.mru()); |
| 136 | |
| 137 | // Now flatten |
| 138 | std::vector<uint8_t> newData; |
| 139 | Stream newStream{newData}; |
| 140 | |
| 141 | callout.flatten(newStream); |
| 142 | EXPECT_EQ(data, newData); |
| 143 | } |
| 144 | |
| 145 | TEST(CalloutTest, TestNoLocationCode) |
| 146 | { |
| 147 | std::vector<uint8_t> data{ |
| 148 | 0xFF, 0x2B, 'H', 0x00 // size, flags, priority, LC length |
| 149 | }; |
| 150 | |
| 151 | auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure); |
| 152 | data.insert(data.end(), fruIdentity.begin(), fruIdentity.end()); |
| 153 | |
| 154 | // The final size |
| 155 | data[0] = data.size(); |
| 156 | |
| 157 | Stream stream{data}; |
| 158 | Callout callout{stream}; |
| 159 | |
| 160 | EXPECT_TRUE(callout.locationCode().empty()); |
| 161 | } |