blob: 5c5c8680e6142886b51b480f5cb203210cbf8187 [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 Spinlerf9bae182019-10-09 13:37:38 -050016#include "extensions/openpower-pels/src.hpp"
Matt Spinler075e5ba2020-02-21 15:46:00 -060017#include "mocks.hpp"
Matt Spinlerf9bae182019-10-09 13:37:38 -050018#include "pel_utils.hpp"
19
Harisuddin Mohamed Isa6fd0c1e2020-02-06 14:25:57 +080020#include <fstream>
21
Matt Spinlerf9bae182019-10-09 13:37:38 -050022#include <gtest/gtest.h>
23
24using namespace openpower::pels;
Matt Spinlered046852020-03-13 13:58:15 -050025using ::testing::_;
26using ::testing::InvokeWithoutArgs;
Matt Spinler075e5ba2020-02-21 15:46:00 -060027using ::testing::NiceMock;
28using ::testing::Return;
Matt Spinler6ea4d5f2020-05-20 13:31:07 -050029using ::testing::ReturnRef;
Matt Spinlered046852020-03-13 13:58:15 -050030using ::testing::SetArgReferee;
Harisuddin Mohamed Isa6fd0c1e2020-02-06 14:25:57 +080031namespace fs = std::filesystem;
Matt Spinlerf9bae182019-10-09 13:37:38 -050032
Harisuddin Mohamed Isa6fd0c1e2020-02-06 14:25:57 +080033const 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
81class 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
106fs::path SRCTest::regDir{};
107
108TEST_F(SRCTest, UnflattenFlattenTestNoCallouts)
Matt Spinlerf9bae182019-10-09 13:37:38 -0500109{
Matt Spinler42828bd2019-10-11 10:39:30 -0500110 auto data = pelDataFactory(TestPELType::primarySRCSection);
Matt Spinlerf9bae182019-10-09 13:37:38 -0500111
112 Stream stream{data};
113 SRC src{stream};
114
115 EXPECT_TRUE(src.valid());
116
117 EXPECT_EQ(src.header().id, 0x5053);
Matt Spinlerf1b46ff2020-01-22 14:10:04 -0600118 EXPECT_EQ(src.header().size, 0x50);
Matt Spinlerf9bae182019-10-09 13:37:38 -0500119 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 Spinlerbd716f02019-10-15 10:54:11 -0500129 EXPECT_EQ(0x02020255, hexwords[0]);
130 EXPECT_EQ(0x03030310, hexwords[1]);
Matt Spinlerf9bae182019-10-09 13:37:38 -0500131 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 Isa6fd0c1e2020-02-06 14:25:57 +0800149TEST_F(SRCTest, UnflattenFlattenTest2Callouts)
Matt Spinlerf9bae182019-10-09 13:37:38 -0500150{
Matt Spinler42828bd2019-10-11 10:39:30 -0500151 auto data = pelDataFactory(TestPELType::primarySRCSection2Callouts);
Matt Spinlerf9bae182019-10-09 13:37:38 -0500152
153 Stream stream{data};
154 SRC src{stream};
155
156 EXPECT_TRUE(src.valid());
Matt Spinlerbd716f02019-10-15 10:54:11 -0500157 EXPECT_EQ(src.flags(), 0x01); // Additional sections within the SRC.
Matt Spinlerf9bae182019-10-09 13:37:38 -0500158
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 Spinlerbd716f02019-10-15 10:54:11 -0500184
185// Create an SRC from the message registry
Harisuddin Mohamed Isa6fd0c1e2020-02-06 14:25:57 +0800186TEST_F(SRCTest, CreateTestNoCallouts)
Matt Spinlerbd716f02019-10-15 10:54:11 -0500187{
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 Spinler075e5ba2020-02-21 15:46:00 -0600203 NiceMock<MockDataInterface> dataIface;
204
205 EXPECT_CALL(dataIface, getMotherboardCCIN).WillOnce(Return("ABCD"));
206
207 SRC src{entry, ad, dataIface};
Matt Spinlerbd716f02019-10-15 10:54:11 -0500208
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 Spinler075e5ba2020-02-21 15:46:00 -0600222 EXPECT_EQ(hexwords[3 - 2] & 0xFFFF0000, 0xABCD0000); // Motherboard CCIN
Matt Spinlerbd716f02019-10-15 10:54:11 -0500223
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 Isa6fd0c1e2020-02-06 14:25:57 +0800253
Matt Spinler075e5ba2020-02-21 15:46:00 -0600254// Test when the CCIN string isn't a 4 character number
255TEST_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 Isa6fd0c1e2020-02-06 14:25:57 +0800297// Test the getErrorDetails function
298TEST_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 Spinler075e5ba2020-02-21 15:46:00 -0600307 NiceMock<MockDataInterface> dataIface;
Harisuddin Mohamed Isa6fd0c1e2020-02-06 14:25:57 +0800308
Matt Spinler075e5ba2020-02-21 15:46:00 -0600309 SRC src{*entry, ad, dataIface};
Harisuddin Mohamed Isa6fd0c1e2020-02-06 14:25:57 +0800310 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 Spinlered046852020-03-13 13:58:15 -0500318
319// Test that an inventory path callout string is
320// converted into the appropriate FRU callout.
321TEST_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 Spinler9b90e2a2020-04-14 10:59:04 -0500333 EXPECT_CALL(dataIface, getLocationCode("motherboard"))
334 .WillOnce(Return("UTMS-P1"));
335
336 EXPECT_CALL(dataIface, getHWCalloutFields("motherboard", _, _, _))
Matt Spinlered046852020-03-13 13:58:15 -0500337 .Times(1)
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500338 .WillOnce(DoAll(SetArgReferee<1>("1234567"), SetArgReferee<2>("CCCC"),
339 SetArgReferee<3>("123456789ABC")));
Matt Spinlered046852020-03-13 13:58:15 -0500340
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 Spinler9b90e2a2020-04-14 10:59:04 -0500370// Test that when the location code can't be obtained that
Matt Spinlered046852020-03-13 13:58:15 -0500371// a procedure callout is used.
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500372TEST_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 Spinlered046852020-03-13 13:58:15 -0500426TEST_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 Spinler9b90e2a2020-04-14 10:59:04 -0500438 EXPECT_CALL(dataIface, getLocationCode("motherboard"))
439 .Times(1)
440 .WillOnce(Return("UTMS-P10"));
441
Matt Spinlered046852020-03-13 13:58:15 -0500442 auto func = []() { throw sdbusplus::exception::SdBusError(5, "Error"); };
443
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500444 EXPECT_CALL(dataIface, getHWCalloutFields("motherboard", _, _, _))
Matt Spinlered046852020-03-13 13:58:15 -0500445 .Times(1)
446 .WillOnce(InvokeWithoutArgs(func));
447
448 SRC src{entry, ad, dataIface};
449 EXPECT_TRUE(src.valid());
Matt Spinlered046852020-03-13 13:58:15 -0500450 ASSERT_TRUE(src.callouts());
Matt Spinlered046852020-03-13 13:58:15 -0500451 EXPECT_EQ(src.callouts()->callouts().size(), 1);
452
453 auto& callout = src.callouts()->callouts().front();
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500454 EXPECT_EQ(callout->locationCode(), "UTMS-P10");
Matt Spinlered046852020-03-13 13:58:15 -0500455
456 auto& fru = callout->fruIdentity();
457
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500458 EXPECT_EQ(fru->getPN(), "");
459 EXPECT_EQ(fru->getCCIN(), "");
460 EXPECT_EQ(fru->getSN(), "");
461 EXPECT_FALSE(fru->getMaintProc());
462
Matt Spinlered046852020-03-13 13:58:15 -0500463 // 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 Spinler03984582020-04-09 13:17:58 -0500474
475TEST_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 ]
Matt Spinleraf191c72020-06-04 11:35:13 -0500513 },
514 {
515 "System": "systemC",
516 "CalloutList":
517 [
518 {
519 "Priority": "high",
520 "LocCode": "P0-C8"
521 },
522 {
523 "Priority": "medium",
524 "LocCode": "P0-C9"
525 }
526 ]
Matt Spinler03984582020-04-09 13:17:58 -0500527 }
528 ])"_json;
529
530 {
531 // Call out a symbolic FRU and a procedure
532 AdditionalData ad;
533 NiceMock<MockDataInterface> dataIface;
Matt Spinler6ea4d5f2020-05-20 13:31:07 -0500534 std::vector<std::string> names{"systemA"};
535
536 EXPECT_CALL(dataIface, getSystemNames).WillOnce(ReturnRef(names));
Matt Spinler03984582020-04-09 13:17:58 -0500537
538 SRC src{entry, ad, dataIface};
539
540 auto& callouts = src.callouts()->callouts();
541 ASSERT_EQ(callouts.size(), 2);
542
543 EXPECT_EQ(callouts[0]->locationCodeSize(), 0);
544 EXPECT_EQ(callouts[0]->priority(), 'H');
545
546 EXPECT_EQ(callouts[1]->locationCodeSize(), 0);
547 EXPECT_EQ(callouts[1]->priority(), 'M');
548
549 auto& fru1 = callouts[0]->fruIdentity();
550 EXPECT_EQ(fru1->getPN().value(), "SVCDOCS");
551 EXPECT_EQ(fru1->failingComponentType(), src::FRUIdentity::symbolicFRU);
552 EXPECT_FALSE(fru1->getMaintProc());
553 EXPECT_FALSE(fru1->getSN());
554 EXPECT_FALSE(fru1->getCCIN());
555
556 auto& fru2 = callouts[1]->fruIdentity();
557 EXPECT_EQ(fru2->getMaintProc().value(), "BMCSP01");
558 EXPECT_EQ(fru2->failingComponentType(),
559 src::FRUIdentity::maintenanceProc);
560 EXPECT_FALSE(fru2->getPN());
561 EXPECT_FALSE(fru2->getSN());
562 EXPECT_FALSE(fru2->getCCIN());
563 }
564
565 {
566 // Call out a trusted symbolic FRU with a location code, and
567 // another one without.
568 AdditionalData ad;
569 NiceMock<MockDataInterface> dataIface;
Matt Spinler6ea4d5f2020-05-20 13:31:07 -0500570 std::vector<std::string> names{"systemB"};
571
Matt Spinleraf191c72020-06-04 11:35:13 -0500572 EXPECT_CALL(dataIface, expandLocationCode).WillOnce(Return("P0-C8"));
Matt Spinler6ea4d5f2020-05-20 13:31:07 -0500573 EXPECT_CALL(dataIface, getSystemNames).WillOnce(ReturnRef(names));
Matt Spinler03984582020-04-09 13:17:58 -0500574
575 SRC src{entry, ad, dataIface};
576
577 auto& callouts = src.callouts()->callouts();
578 EXPECT_EQ(callouts.size(), 2);
579
580 EXPECT_EQ(callouts[0]->locationCode(), "P0-C8");
581 EXPECT_EQ(callouts[0]->priority(), 'H');
582
583 EXPECT_EQ(callouts[1]->locationCodeSize(), 0);
584 EXPECT_EQ(callouts[1]->priority(), 'M');
585
586 auto& fru1 = callouts[0]->fruIdentity();
587 EXPECT_EQ(fru1->getPN().value(), "SVCDOCS");
588 EXPECT_EQ(fru1->failingComponentType(),
589 src::FRUIdentity::symbolicFRUTrustedLocCode);
590 EXPECT_FALSE(fru1->getMaintProc());
591 EXPECT_FALSE(fru1->getSN());
592 EXPECT_FALSE(fru1->getCCIN());
593
594 // It asked for a trusted symbolic FRU, but no location code
595 // was provided so it is switched back to a normal one
596 auto& fru2 = callouts[1]->fruIdentity();
597 EXPECT_EQ(fru2->getPN().value(), "SVCDOCS");
598 EXPECT_EQ(fru2->failingComponentType(), src::FRUIdentity::symbolicFRU);
599 EXPECT_FALSE(fru2->getMaintProc());
600 EXPECT_FALSE(fru2->getSN());
601 EXPECT_FALSE(fru2->getCCIN());
602 }
Matt Spinleraf191c72020-06-04 11:35:13 -0500603
604 {
605 // Two hardware callouts
606 AdditionalData ad;
607 NiceMock<MockDataInterface> dataIface;
608 std::vector<std::string> names{"systemC"};
609
610 EXPECT_CALL(dataIface, getSystemNames).WillOnce(ReturnRef(names));
611
612 EXPECT_CALL(dataIface, expandLocationCode("P0-C8", 0))
613 .WillOnce(Return("UXXX-P0-C8"));
614
615 EXPECT_CALL(dataIface, expandLocationCode("P0-C9", 0))
616 .WillOnce(Return("UXXX-P0-C9"));
617
618 EXPECT_CALL(dataIface, getInventoryFromLocCode("P0-C8", 0))
619 .WillOnce(Return(
620 "/xyz/openbmc_project/inventory/chassis/motherboard/cpu0"));
621
622 EXPECT_CALL(dataIface, getInventoryFromLocCode("P0-C9", 0))
623 .WillOnce(Return(
624 "/xyz/openbmc_project/inventory/chassis/motherboard/cpu1"));
625
626 EXPECT_CALL(
627 dataIface,
628 getHWCalloutFields(
629 "/xyz/openbmc_project/inventory/chassis/motherboard/cpu0", _, _,
630 _))
631 .Times(1)
632 .WillOnce(DoAll(SetArgReferee<1>("1234567"),
633 SetArgReferee<2>("CCCC"),
634 SetArgReferee<3>("123456789ABC")));
635
636 EXPECT_CALL(
637 dataIface,
638 getHWCalloutFields(
639 "/xyz/openbmc_project/inventory/chassis/motherboard/cpu1", _, _,
640 _))
641 .Times(1)
642 .WillOnce(DoAll(SetArgReferee<1>("2345678"),
643 SetArgReferee<2>("DDDD"),
644 SetArgReferee<3>("23456789ABCD")));
645
646 SRC src{entry, ad, dataIface};
647
648 auto& callouts = src.callouts()->callouts();
649 EXPECT_EQ(callouts.size(), 2);
650
651 EXPECT_EQ(callouts[0]->locationCode(), "UXXX-P0-C8");
652 EXPECT_EQ(callouts[0]->priority(), 'H');
653
654 auto& fru1 = callouts[0]->fruIdentity();
655 EXPECT_EQ(fru1->getPN().value(), "1234567");
656 EXPECT_EQ(fru1->getCCIN().value(), "CCCC");
657 EXPECT_EQ(fru1->getSN().value(), "123456789ABC");
658
659 EXPECT_EQ(callouts[1]->locationCode(), "UXXX-P0-C9");
660 EXPECT_EQ(callouts[1]->priority(), 'M');
661
662 auto& fru2 = callouts[1]->fruIdentity();
663 EXPECT_EQ(fru2->getPN().value(), "2345678");
664 EXPECT_EQ(fru2->getCCIN().value(), "DDDD");
665 EXPECT_EQ(fru2->getSN().value(), "23456789ABCD");
666 }
Matt Spinler03984582020-04-09 13:17:58 -0500667}