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 | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 16 | #include "extensions/openpower-pels/src.hpp" |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 17 | #include "mocks.hpp" |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 18 | #include "pel_utils.hpp" |
| 19 | |
Harisuddin Mohamed Isa | 6fd0c1e | 2020-02-06 14:25:57 +0800 | [diff] [blame] | 20 | #include <fstream> |
| 21 | |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 22 | #include <gtest/gtest.h> |
| 23 | |
| 24 | using namespace openpower::pels; |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 25 | using ::testing::_; |
| 26 | using ::testing::InvokeWithoutArgs; |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 27 | using ::testing::NiceMock; |
| 28 | using ::testing::Return; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 29 | using ::testing::ReturnRef; |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 30 | using ::testing::SetArgReferee; |
Harisuddin Mohamed Isa | 6fd0c1e | 2020-02-06 14:25:57 +0800 | [diff] [blame] | 31 | namespace fs = std::filesystem; |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 32 | |
Harisuddin Mohamed Isa | 6fd0c1e | 2020-02-06 14:25:57 +0800 | [diff] [blame] | 33 | const auto testRegistry = R"( |
| 34 | { |
| 35 | "PELs": |
| 36 | [ |
| 37 | { |
| 38 | "Name": "xyz.openbmc_project.Error.Test", |
| 39 | "Subsystem": "bmc_firmware", |
| 40 | "SRC": |
| 41 | { |
| 42 | "ReasonCode": "0xABCD", |
| 43 | "Words6To9": |
| 44 | { |
| 45 | "6": |
| 46 | { |
| 47 | "Description": "Component ID", |
| 48 | "AdditionalDataPropSource": "COMPID" |
| 49 | }, |
| 50 | "7": |
| 51 | { |
| 52 | "Description": "Failure count", |
| 53 | "AdditionalDataPropSource": "FREQUENCY" |
| 54 | }, |
| 55 | "8": |
| 56 | { |
| 57 | "Description": "Time period", |
| 58 | "AdditionalDataPropSource": "DURATION" |
| 59 | }, |
| 60 | "9": |
| 61 | { |
| 62 | "Description": "Error code", |
| 63 | "AdditionalDataPropSource": "ERRORCODE" |
| 64 | } |
| 65 | } |
| 66 | }, |
| 67 | "Documentation": |
| 68 | { |
| 69 | "Description": "A Component Fault", |
| 70 | "Message": "Comp %1 failed %2 times over %3 secs with ErrorCode %4", |
| 71 | "MessageArgSources": |
| 72 | [ |
| 73 | "SRCWord6", "SRCWord7", "SRCWord8", "SRCWord9" |
| 74 | ] |
| 75 | } |
| 76 | } |
| 77 | ] |
| 78 | } |
| 79 | )"; |
| 80 | |
| 81 | class SRCTest : public ::testing::Test |
| 82 | { |
| 83 | protected: |
| 84 | static void SetUpTestCase() |
| 85 | { |
| 86 | char path[] = "/tmp/srctestXXXXXX"; |
| 87 | regDir = mkdtemp(path); |
| 88 | } |
| 89 | |
| 90 | static void TearDownTestCase() |
| 91 | { |
| 92 | fs::remove_all(regDir); |
| 93 | } |
| 94 | |
| 95 | static std::string writeData(const char* data) |
| 96 | { |
| 97 | fs::path path = regDir / "registry.json"; |
| 98 | std::ofstream stream{path}; |
| 99 | stream << data; |
| 100 | return path; |
| 101 | } |
| 102 | |
| 103 | static fs::path regDir; |
| 104 | }; |
| 105 | |
| 106 | fs::path SRCTest::regDir{}; |
| 107 | |
| 108 | TEST_F(SRCTest, UnflattenFlattenTestNoCallouts) |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 109 | { |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 110 | auto data = pelDataFactory(TestPELType::primarySRCSection); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 111 | |
| 112 | Stream stream{data}; |
| 113 | SRC src{stream}; |
| 114 | |
| 115 | EXPECT_TRUE(src.valid()); |
| 116 | |
| 117 | EXPECT_EQ(src.header().id, 0x5053); |
Matt Spinler | f1b46ff | 2020-01-22 14:10:04 -0600 | [diff] [blame] | 118 | EXPECT_EQ(src.header().size, 0x50); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 119 | EXPECT_EQ(src.header().version, 0x01); |
| 120 | EXPECT_EQ(src.header().subType, 0x01); |
| 121 | EXPECT_EQ(src.header().componentID, 0x0202); |
| 122 | |
| 123 | EXPECT_EQ(src.version(), 0x02); |
| 124 | EXPECT_EQ(src.flags(), 0x00); |
| 125 | EXPECT_EQ(src.hexWordCount(), 9); |
| 126 | EXPECT_EQ(src.size(), 0x48); |
| 127 | |
| 128 | const auto& hexwords = src.hexwordData(); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 129 | EXPECT_EQ(0x02020255, hexwords[0]); |
| 130 | EXPECT_EQ(0x03030310, hexwords[1]); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 131 | EXPECT_EQ(0x04040404, hexwords[2]); |
| 132 | EXPECT_EQ(0x05050505, hexwords[3]); |
| 133 | EXPECT_EQ(0x06060606, hexwords[4]); |
| 134 | EXPECT_EQ(0x07070707, hexwords[5]); |
| 135 | EXPECT_EQ(0x08080808, hexwords[6]); |
| 136 | EXPECT_EQ(0x09090909, hexwords[7]); |
| 137 | |
| 138 | EXPECT_EQ(src.asciiString(), "BD8D5678 "); |
| 139 | EXPECT_FALSE(src.callouts()); |
| 140 | |
| 141 | // Flatten |
| 142 | std::vector<uint8_t> newData; |
| 143 | Stream newStream{newData}; |
| 144 | |
| 145 | src.flatten(newStream); |
| 146 | EXPECT_EQ(data, newData); |
| 147 | } |
| 148 | |
Harisuddin Mohamed Isa | 6fd0c1e | 2020-02-06 14:25:57 +0800 | [diff] [blame] | 149 | TEST_F(SRCTest, UnflattenFlattenTest2Callouts) |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 150 | { |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 151 | auto data = pelDataFactory(TestPELType::primarySRCSection2Callouts); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 152 | |
| 153 | Stream stream{data}; |
| 154 | SRC src{stream}; |
| 155 | |
| 156 | EXPECT_TRUE(src.valid()); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 157 | EXPECT_EQ(src.flags(), 0x01); // Additional sections within the SRC. |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 158 | |
| 159 | // Spot check the SRC fields, but they're the same as above |
| 160 | EXPECT_EQ(src.asciiString(), "BD8D5678 "); |
| 161 | |
| 162 | // There should be 2 callouts |
| 163 | const auto& calloutsSection = src.callouts(); |
| 164 | ASSERT_TRUE(calloutsSection); |
| 165 | const auto& callouts = calloutsSection->callouts(); |
| 166 | EXPECT_EQ(callouts.size(), 2); |
| 167 | |
| 168 | // spot check that each callout has the right substructures |
| 169 | EXPECT_TRUE(callouts.front()->fruIdentity()); |
| 170 | EXPECT_FALSE(callouts.front()->pceIdentity()); |
| 171 | EXPECT_FALSE(callouts.front()->mru()); |
| 172 | |
| 173 | EXPECT_TRUE(callouts.back()->fruIdentity()); |
| 174 | EXPECT_TRUE(callouts.back()->pceIdentity()); |
| 175 | EXPECT_TRUE(callouts.back()->mru()); |
| 176 | |
| 177 | // Flatten |
| 178 | std::vector<uint8_t> newData; |
| 179 | Stream newStream{newData}; |
| 180 | |
| 181 | src.flatten(newStream); |
| 182 | EXPECT_EQ(data, newData); |
| 183 | } |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 184 | |
| 185 | // Create an SRC from the message registry |
Harisuddin Mohamed Isa | 6fd0c1e | 2020-02-06 14:25:57 +0800 | [diff] [blame] | 186 | TEST_F(SRCTest, CreateTestNoCallouts) |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 187 | { |
| 188 | message::Entry entry; |
| 189 | entry.src.type = 0xBD; |
| 190 | entry.src.reasonCode = 0xABCD; |
| 191 | entry.subsystem = 0x42; |
| 192 | entry.src.powerFault = true; |
| 193 | entry.src.hexwordADFields = {{5, "TEST1"}, // Not a user defined word |
| 194 | {6, "TEST1"}, |
| 195 | {7, "TEST2"}, |
| 196 | {8, "TEST3"}, |
| 197 | {9, "TEST4"}}; |
| 198 | |
| 199 | // Values for the SRC words pointed to above |
| 200 | std::vector<std::string> adData{"TEST1=0x12345678", "TEST2=12345678", |
| 201 | "TEST3=0XDEF", "TEST4=Z"}; |
| 202 | AdditionalData ad{adData}; |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 203 | NiceMock<MockDataInterface> dataIface; |
| 204 | |
| 205 | EXPECT_CALL(dataIface, getMotherboardCCIN).WillOnce(Return("ABCD")); |
| 206 | |
| 207 | SRC src{entry, ad, dataIface}; |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 208 | |
| 209 | EXPECT_TRUE(src.valid()); |
| 210 | EXPECT_TRUE(src.isPowerFaultEvent()); |
| 211 | EXPECT_EQ(src.size(), baseSRCSize); |
| 212 | |
| 213 | const auto& hexwords = src.hexwordData(); |
| 214 | |
| 215 | // The spec always refers to SRC words 2 - 9, and as the hexwordData() |
| 216 | // array index starts at 0 use the math in the [] below to make it easier |
| 217 | // to tell what is being accessed. |
| 218 | EXPECT_EQ(hexwords[2 - 2] & 0xF0000000, 0); // Partition dump status |
| 219 | EXPECT_EQ(hexwords[2 - 2] & 0x00F00000, 0); // Partition boot type |
| 220 | EXPECT_EQ(hexwords[2 - 2] & 0x000000FF, 0x55); // SRC format |
| 221 | EXPECT_EQ(hexwords[3 - 2] & 0x000000FF, 0x10); // BMC position |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 222 | EXPECT_EQ(hexwords[3 - 2] & 0xFFFF0000, 0xABCD0000); // Motherboard CCIN |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 223 | |
| 224 | // Validate more fields here as the code starts filling them in. |
| 225 | |
| 226 | // Ensure hex word 5 wasn't allowed to be set to TEST1's contents |
| 227 | EXPECT_EQ(hexwords[5 - 2], 0); |
| 228 | |
| 229 | // The user defined hex word fields specifed in the additional data. |
| 230 | EXPECT_EQ(hexwords[6 - 2], 0x12345678); // TEST1 |
| 231 | EXPECT_EQ(hexwords[7 - 2], 12345678); // TEST2 |
| 232 | EXPECT_EQ(hexwords[8 - 2], 0xdef); // TEST3 |
| 233 | EXPECT_EQ(hexwords[9 - 2], 0); // TEST4, but can't convert a 'Z' |
| 234 | |
| 235 | EXPECT_EQ(src.asciiString(), "BD42ABCD "); |
| 236 | |
| 237 | // No callouts |
| 238 | EXPECT_FALSE(src.callouts()); |
| 239 | |
| 240 | // May as well spot check the flatten/unflatten |
| 241 | std::vector<uint8_t> data; |
| 242 | Stream stream{data}; |
| 243 | src.flatten(stream); |
| 244 | |
| 245 | stream.offset(0); |
| 246 | SRC newSRC{stream}; |
| 247 | |
| 248 | EXPECT_TRUE(newSRC.valid()); |
| 249 | EXPECT_EQ(newSRC.isPowerFaultEvent(), src.isPowerFaultEvent()); |
| 250 | EXPECT_EQ(newSRC.asciiString(), src.asciiString()); |
| 251 | EXPECT_FALSE(newSRC.callouts()); |
| 252 | } |
Harisuddin Mohamed Isa | 6fd0c1e | 2020-02-06 14:25:57 +0800 | [diff] [blame] | 253 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 254 | // Test when the CCIN string isn't a 4 character number |
| 255 | TEST_F(SRCTest, BadCCINTest) |
| 256 | { |
| 257 | message::Entry entry; |
| 258 | entry.src.type = 0xBD; |
| 259 | entry.src.reasonCode = 0xABCD; |
| 260 | entry.subsystem = 0x42; |
| 261 | entry.src.powerFault = false; |
| 262 | |
| 263 | std::vector<std::string> adData{}; |
| 264 | AdditionalData ad{adData}; |
| 265 | NiceMock<MockDataInterface> dataIface; |
| 266 | |
| 267 | // First it isn't a number, then it is too long, |
| 268 | // then it is empty. |
| 269 | EXPECT_CALL(dataIface, getMotherboardCCIN) |
| 270 | .WillOnce(Return("X")) |
| 271 | .WillOnce(Return("12345")) |
| 272 | .WillOnce(Return("")); |
| 273 | |
| 274 | // The CCIN in the first half should still be 0 each time. |
| 275 | { |
| 276 | SRC src{entry, ad, dataIface}; |
| 277 | EXPECT_TRUE(src.valid()); |
| 278 | const auto& hexwords = src.hexwordData(); |
| 279 | EXPECT_EQ(hexwords[3 - 2] & 0xFFFF0000, 0x00000000); |
| 280 | } |
| 281 | |
| 282 | { |
| 283 | SRC src{entry, ad, dataIface}; |
| 284 | EXPECT_TRUE(src.valid()); |
| 285 | const auto& hexwords = src.hexwordData(); |
| 286 | EXPECT_EQ(hexwords[3 - 2] & 0xFFFF0000, 0x00000000); |
| 287 | } |
| 288 | |
| 289 | { |
| 290 | SRC src{entry, ad, dataIface}; |
| 291 | EXPECT_TRUE(src.valid()); |
| 292 | const auto& hexwords = src.hexwordData(); |
| 293 | EXPECT_EQ(hexwords[3 - 2] & 0xFFFF0000, 0x00000000); |
| 294 | } |
| 295 | } |
| 296 | |
Harisuddin Mohamed Isa | 6fd0c1e | 2020-02-06 14:25:57 +0800 | [diff] [blame] | 297 | // Test the getErrorDetails function |
| 298 | TEST_F(SRCTest, MessageSubstitutionTest) |
| 299 | { |
| 300 | auto path = SRCTest::writeData(testRegistry); |
| 301 | message::Registry registry{path}; |
| 302 | auto entry = registry.lookup("0xABCD", message::LookupType::reasonCode); |
| 303 | |
| 304 | std::vector<std::string> adData{"COMPID=0x1", "FREQUENCY=0x4", |
| 305 | "DURATION=30", "ERRORCODE=0x01ABCDEF"}; |
| 306 | AdditionalData ad{adData}; |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 307 | NiceMock<MockDataInterface> dataIface; |
Harisuddin Mohamed Isa | 6fd0c1e | 2020-02-06 14:25:57 +0800 | [diff] [blame] | 308 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 309 | SRC src{*entry, ad, dataIface}; |
Harisuddin Mohamed Isa | 6fd0c1e | 2020-02-06 14:25:57 +0800 | [diff] [blame] | 310 | EXPECT_TRUE(src.valid()); |
| 311 | |
| 312 | auto errorDetails = src.getErrorDetails(registry, DetailLevel::message); |
| 313 | ASSERT_TRUE(errorDetails); |
| 314 | EXPECT_EQ( |
| 315 | errorDetails.value(), |
| 316 | "Comp 0x1 failed 0x4 times over 0x1E secs with ErrorCode 0x1ABCDEF"); |
| 317 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 318 | |
| 319 | // Test that an inventory path callout string is |
| 320 | // converted into the appropriate FRU callout. |
| 321 | TEST_F(SRCTest, InventoryCalloutTest) |
| 322 | { |
| 323 | message::Entry entry; |
| 324 | entry.src.type = 0xBD; |
| 325 | entry.src.reasonCode = 0xABCD; |
| 326 | entry.subsystem = 0x42; |
| 327 | entry.src.powerFault = false; |
| 328 | |
| 329 | std::vector<std::string> adData{"CALLOUT_INVENTORY_PATH=motherboard"}; |
| 330 | AdditionalData ad{adData}; |
| 331 | NiceMock<MockDataInterface> dataIface; |
| 332 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 333 | EXPECT_CALL(dataIface, getLocationCode("motherboard")) |
| 334 | .WillOnce(Return("UTMS-P1")); |
| 335 | |
| 336 | EXPECT_CALL(dataIface, getHWCalloutFields("motherboard", _, _, _)) |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 337 | .Times(1) |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 338 | .WillOnce(DoAll(SetArgReferee<1>("1234567"), SetArgReferee<2>("CCCC"), |
| 339 | SetArgReferee<3>("123456789ABC"))); |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 340 | |
| 341 | SRC src{entry, ad, dataIface}; |
| 342 | EXPECT_TRUE(src.valid()); |
| 343 | |
| 344 | ASSERT_TRUE(src.callouts()); |
| 345 | |
| 346 | EXPECT_EQ(src.callouts()->callouts().size(), 1); |
| 347 | |
| 348 | auto& callout = src.callouts()->callouts().front(); |
| 349 | |
| 350 | EXPECT_EQ(callout->locationCode(), "UTMS-P1"); |
| 351 | |
| 352 | auto& fru = callout->fruIdentity(); |
| 353 | |
| 354 | EXPECT_EQ(fru->getPN().value(), "1234567"); |
| 355 | EXPECT_EQ(fru->getCCIN().value(), "CCCC"); |
| 356 | EXPECT_EQ(fru->getSN().value(), "123456789ABC"); |
| 357 | |
| 358 | // flatten and unflatten |
| 359 | std::vector<uint8_t> data; |
| 360 | Stream stream{data}; |
| 361 | src.flatten(stream); |
| 362 | |
| 363 | stream.offset(0); |
| 364 | SRC newSRC{stream}; |
| 365 | EXPECT_TRUE(newSRC.valid()); |
| 366 | ASSERT_TRUE(src.callouts()); |
| 367 | EXPECT_EQ(src.callouts()->callouts().size(), 1); |
| 368 | } |
| 369 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 370 | // Test that when the location code can't be obtained that |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 371 | // a procedure callout is used. |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 372 | TEST_F(SRCTest, InventoryCalloutNoLocCodeTest) |
| 373 | { |
| 374 | message::Entry entry; |
| 375 | entry.src.type = 0xBD; |
| 376 | entry.src.reasonCode = 0xABCD; |
| 377 | entry.subsystem = 0x42; |
| 378 | entry.src.powerFault = false; |
| 379 | |
| 380 | std::vector<std::string> adData{"CALLOUT_INVENTORY_PATH=motherboard"}; |
| 381 | AdditionalData ad{adData}; |
| 382 | NiceMock<MockDataInterface> dataIface; |
| 383 | |
| 384 | auto func = []() { |
| 385 | throw sdbusplus::exception::SdBusError(5, "Error"); |
| 386 | return std::string{}; |
| 387 | }; |
| 388 | |
| 389 | EXPECT_CALL(dataIface, getLocationCode("motherboard")) |
| 390 | .Times(1) |
| 391 | .WillOnce(InvokeWithoutArgs(func)); |
| 392 | |
| 393 | EXPECT_CALL(dataIface, getHWCalloutFields(_, _, _, _)).Times(0); |
| 394 | |
| 395 | SRC src{entry, ad, dataIface}; |
| 396 | EXPECT_TRUE(src.valid()); |
| 397 | |
| 398 | ASSERT_TRUE(src.callouts()); |
| 399 | |
| 400 | EXPECT_EQ(src.callouts()->callouts().size(), 1); |
| 401 | |
| 402 | auto& callout = src.callouts()->callouts().front(); |
| 403 | EXPECT_EQ(callout->locationCodeSize(), 0); |
| 404 | |
| 405 | auto& fru = callout->fruIdentity(); |
| 406 | |
| 407 | EXPECT_EQ(fru->getMaintProc().value(), "BMCSP01"); |
| 408 | EXPECT_FALSE(fru->getPN()); |
| 409 | EXPECT_FALSE(fru->getSN()); |
| 410 | EXPECT_FALSE(fru->getCCIN()); |
| 411 | |
| 412 | // flatten and unflatten |
| 413 | std::vector<uint8_t> data; |
| 414 | Stream stream{data}; |
| 415 | src.flatten(stream); |
| 416 | |
| 417 | stream.offset(0); |
| 418 | SRC newSRC{stream}; |
| 419 | EXPECT_TRUE(newSRC.valid()); |
| 420 | ASSERT_TRUE(src.callouts()); |
| 421 | EXPECT_EQ(src.callouts()->callouts().size(), 1); |
| 422 | } |
| 423 | |
| 424 | // Test that when the VPD can't be obtained that |
| 425 | // a callout is still created. |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 426 | TEST_F(SRCTest, InventoryCalloutNoVPDTest) |
| 427 | { |
| 428 | message::Entry entry; |
| 429 | entry.src.type = 0xBD; |
| 430 | entry.src.reasonCode = 0xABCD; |
| 431 | entry.subsystem = 0x42; |
| 432 | entry.src.powerFault = false; |
| 433 | |
| 434 | std::vector<std::string> adData{"CALLOUT_INVENTORY_PATH=motherboard"}; |
| 435 | AdditionalData ad{adData}; |
| 436 | NiceMock<MockDataInterface> dataIface; |
| 437 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 438 | EXPECT_CALL(dataIface, getLocationCode("motherboard")) |
| 439 | .Times(1) |
| 440 | .WillOnce(Return("UTMS-P10")); |
| 441 | |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 442 | auto func = []() { throw sdbusplus::exception::SdBusError(5, "Error"); }; |
| 443 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 444 | EXPECT_CALL(dataIface, getHWCalloutFields("motherboard", _, _, _)) |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 445 | .Times(1) |
| 446 | .WillOnce(InvokeWithoutArgs(func)); |
| 447 | |
| 448 | SRC src{entry, ad, dataIface}; |
| 449 | EXPECT_TRUE(src.valid()); |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 450 | ASSERT_TRUE(src.callouts()); |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 451 | EXPECT_EQ(src.callouts()->callouts().size(), 1); |
| 452 | |
| 453 | auto& callout = src.callouts()->callouts().front(); |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 454 | EXPECT_EQ(callout->locationCode(), "UTMS-P10"); |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 455 | |
| 456 | auto& fru = callout->fruIdentity(); |
| 457 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 458 | EXPECT_EQ(fru->getPN(), ""); |
| 459 | EXPECT_EQ(fru->getCCIN(), ""); |
| 460 | EXPECT_EQ(fru->getSN(), ""); |
| 461 | EXPECT_FALSE(fru->getMaintProc()); |
| 462 | |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 463 | // flatten and unflatten |
| 464 | std::vector<uint8_t> data; |
| 465 | Stream stream{data}; |
| 466 | src.flatten(stream); |
| 467 | |
| 468 | stream.offset(0); |
| 469 | SRC newSRC{stream}; |
| 470 | EXPECT_TRUE(newSRC.valid()); |
| 471 | ASSERT_TRUE(src.callouts()); |
| 472 | EXPECT_EQ(src.callouts()->callouts().size(), 1); |
| 473 | } |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 474 | |
| 475 | TEST_F(SRCTest, RegistryCalloutTest) |
| 476 | { |
| 477 | message::Entry entry; |
| 478 | entry.src.type = 0xBD; |
| 479 | entry.src.reasonCode = 0xABCD; |
| 480 | entry.subsystem = 0x42; |
| 481 | entry.src.powerFault = false; |
| 482 | |
| 483 | entry.callouts = R"( |
| 484 | [ |
| 485 | { |
| 486 | "System": "systemA", |
| 487 | "CalloutList": |
| 488 | [ |
| 489 | { |
| 490 | "Priority": "high", |
| 491 | "SymbolicFRU": "service_docs" |
| 492 | }, |
| 493 | { |
| 494 | "Priority": "medium", |
| 495 | "Procedure": "no_vpd_for_fru" |
| 496 | } |
| 497 | ] |
| 498 | }, |
| 499 | { |
| 500 | "System": "systemB", |
| 501 | "CalloutList": |
| 502 | [ |
| 503 | { |
| 504 | "Priority": "high", |
| 505 | "LocCode": "P0-C8", |
| 506 | "SymbolicFRUTrusted": "service_docs" |
| 507 | }, |
| 508 | { |
| 509 | "Priority": "medium", |
| 510 | "SymbolicFRUTrusted": "service_docs" |
| 511 | } |
| 512 | ] |
| 513 | |
| 514 | } |
| 515 | ])"_json; |
| 516 | |
| 517 | { |
| 518 | // Call out a symbolic FRU and a procedure |
| 519 | AdditionalData ad; |
| 520 | NiceMock<MockDataInterface> dataIface; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 521 | std::vector<std::string> names{"systemA"}; |
| 522 | |
| 523 | EXPECT_CALL(dataIface, getSystemNames).WillOnce(ReturnRef(names)); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 524 | |
| 525 | SRC src{entry, ad, dataIface}; |
| 526 | |
| 527 | auto& callouts = src.callouts()->callouts(); |
| 528 | ASSERT_EQ(callouts.size(), 2); |
| 529 | |
| 530 | EXPECT_EQ(callouts[0]->locationCodeSize(), 0); |
| 531 | EXPECT_EQ(callouts[0]->priority(), 'H'); |
| 532 | |
| 533 | EXPECT_EQ(callouts[1]->locationCodeSize(), 0); |
| 534 | EXPECT_EQ(callouts[1]->priority(), 'M'); |
| 535 | |
| 536 | auto& fru1 = callouts[0]->fruIdentity(); |
| 537 | EXPECT_EQ(fru1->getPN().value(), "SVCDOCS"); |
| 538 | EXPECT_EQ(fru1->failingComponentType(), src::FRUIdentity::symbolicFRU); |
| 539 | EXPECT_FALSE(fru1->getMaintProc()); |
| 540 | EXPECT_FALSE(fru1->getSN()); |
| 541 | EXPECT_FALSE(fru1->getCCIN()); |
| 542 | |
| 543 | auto& fru2 = callouts[1]->fruIdentity(); |
| 544 | EXPECT_EQ(fru2->getMaintProc().value(), "BMCSP01"); |
| 545 | EXPECT_EQ(fru2->failingComponentType(), |
| 546 | src::FRUIdentity::maintenanceProc); |
| 547 | EXPECT_FALSE(fru2->getPN()); |
| 548 | EXPECT_FALSE(fru2->getSN()); |
| 549 | EXPECT_FALSE(fru2->getCCIN()); |
| 550 | } |
| 551 | |
| 552 | { |
| 553 | // Call out a trusted symbolic FRU with a location code, and |
| 554 | // another one without. |
| 555 | AdditionalData ad; |
| 556 | NiceMock<MockDataInterface> dataIface; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 557 | std::vector<std::string> names{"systemB"}; |
| 558 | |
| 559 | EXPECT_CALL(dataIface, getSystemNames).WillOnce(ReturnRef(names)); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 560 | |
| 561 | SRC src{entry, ad, dataIface}; |
| 562 | |
| 563 | auto& callouts = src.callouts()->callouts(); |
| 564 | EXPECT_EQ(callouts.size(), 2); |
| 565 | |
| 566 | EXPECT_EQ(callouts[0]->locationCode(), "P0-C8"); |
| 567 | EXPECT_EQ(callouts[0]->priority(), 'H'); |
| 568 | |
| 569 | EXPECT_EQ(callouts[1]->locationCodeSize(), 0); |
| 570 | EXPECT_EQ(callouts[1]->priority(), 'M'); |
| 571 | |
| 572 | auto& fru1 = callouts[0]->fruIdentity(); |
| 573 | EXPECT_EQ(fru1->getPN().value(), "SVCDOCS"); |
| 574 | EXPECT_EQ(fru1->failingComponentType(), |
| 575 | src::FRUIdentity::symbolicFRUTrustedLocCode); |
| 576 | EXPECT_FALSE(fru1->getMaintProc()); |
| 577 | EXPECT_FALSE(fru1->getSN()); |
| 578 | EXPECT_FALSE(fru1->getCCIN()); |
| 579 | |
| 580 | // It asked for a trusted symbolic FRU, but no location code |
| 581 | // was provided so it is switched back to a normal one |
| 582 | auto& fru2 = callouts[1]->fruIdentity(); |
| 583 | EXPECT_EQ(fru2->getPN().value(), "SVCDOCS"); |
| 584 | EXPECT_EQ(fru2->failingComponentType(), src::FRUIdentity::symbolicFRU); |
| 585 | EXPECT_FALSE(fru2->getMaintProc()); |
| 586 | EXPECT_FALSE(fru2->getSN()); |
| 587 | EXPECT_FALSE(fru2->getCCIN()); |
| 588 | } |
| 589 | } |