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 | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 16 | #include "extensions/openpower-pels/registry.hpp" |
| 17 | |
| 18 | #include <filesystem> |
| 19 | #include <fstream> |
| 20 | #include <nlohmann/json.hpp> |
| 21 | |
| 22 | #include <gtest/gtest.h> |
| 23 | |
| 24 | using namespace openpower::pels::message; |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 25 | using namespace openpower::pels; |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 26 | namespace fs = std::filesystem; |
| 27 | |
| 28 | const auto registryData = R"( |
| 29 | { |
| 30 | "PELs": |
| 31 | [ |
| 32 | { |
| 33 | "Name": "xyz.openbmc_project.Power.Fault", |
| 34 | "Subsystem": "power_supply", |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 35 | |
| 36 | "SRC": |
| 37 | { |
| 38 | "ReasonCode": "0x2030" |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 39 | }, |
| 40 | |
| 41 | "Documentation": |
| 42 | { |
| 43 | "Description": "A PGOOD Fault", |
| 44 | "Message": "PS had a PGOOD Fault" |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 45 | } |
| 46 | }, |
| 47 | |
| 48 | { |
| 49 | "Name": "xyz.openbmc_project.Power.OverVoltage", |
| 50 | "Subsystem": "power_control_hw", |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 51 | "Severity": |
| 52 | [ |
| 53 | { |
| 54 | "System": "systemA", |
| 55 | "SevValue": "unrecoverable" |
| 56 | }, |
| 57 | { |
| 58 | "System": "systemB", |
| 59 | "SevValue": "recovered" |
| 60 | }, |
| 61 | { |
| 62 | "SevValue": "predictive" |
| 63 | } |
| 64 | ], |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 65 | "MfgSeverity": "non_error", |
| 66 | "ActionFlags": ["service_action", "report", "call_home"], |
| 67 | "MfgActionFlags": ["hidden"], |
| 68 | |
| 69 | "SRC": |
| 70 | { |
| 71 | "ReasonCode": "0x2333", |
| 72 | "Type": "BD", |
| 73 | "SymptomIDFields": ["SRCWord5", "SRCWord6", "SRCWord7"], |
| 74 | "PowerFault": true, |
| 75 | "Words6To9": |
| 76 | { |
| 77 | "6": |
| 78 | { |
| 79 | "description": "Failing unit number", |
| 80 | "AdditionalDataPropSource": "PS_NUM" |
| 81 | }, |
| 82 | |
| 83 | "7": |
| 84 | { |
| 85 | "description": "bad voltage", |
| 86 | "AdditionalDataPropSource": "VOLTAGE" |
| 87 | } |
| 88 | } |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 89 | }, |
| 90 | |
| 91 | "Documentation": |
| 92 | { |
| 93 | "Description": "A PGOOD Fault", |
| 94 | "Message": "PS %1 had a PGOOD Fault", |
| 95 | "MessageArgSources": |
| 96 | [ |
| 97 | "SRCWord6" |
| 98 | ], |
| 99 | "Notes": [ |
| 100 | "In the UserData section there is a JSON", |
| 101 | "dump that provides debug information." |
| 102 | ] |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | ] |
| 106 | } |
| 107 | )"; |
| 108 | |
| 109 | class RegistryTest : public ::testing::Test |
| 110 | { |
| 111 | protected: |
| 112 | static void SetUpTestCase() |
| 113 | { |
| 114 | char path[] = "/tmp/regtestXXXXXX"; |
| 115 | regDir = mkdtemp(path); |
| 116 | } |
| 117 | |
| 118 | static void TearDownTestCase() |
| 119 | { |
| 120 | fs::remove_all(regDir); |
| 121 | } |
| 122 | |
| 123 | static std::string writeData(const char* data) |
| 124 | { |
| 125 | fs::path path = regDir / "registry.json"; |
| 126 | std::ofstream stream{path}; |
| 127 | stream << data; |
| 128 | return path; |
| 129 | } |
| 130 | |
| 131 | static fs::path regDir; |
| 132 | }; |
| 133 | |
| 134 | fs::path RegistryTest::regDir{}; |
| 135 | |
| 136 | TEST_F(RegistryTest, TestNoEntry) |
| 137 | { |
| 138 | auto path = RegistryTest::writeData(registryData); |
| 139 | Registry registry{path}; |
| 140 | |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 141 | auto entry = registry.lookup("foo", LookupType::name); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 142 | EXPECT_FALSE(entry); |
| 143 | } |
| 144 | |
| 145 | TEST_F(RegistryTest, TestFindEntry) |
| 146 | { |
| 147 | auto path = RegistryTest::writeData(registryData); |
| 148 | Registry registry{path}; |
| 149 | |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 150 | auto entry = registry.lookup("xyz.openbmc_project.Power.OverVoltage", |
| 151 | LookupType::name); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 152 | ASSERT_TRUE(entry); |
| 153 | EXPECT_EQ(entry->name, "xyz.openbmc_project.Power.OverVoltage"); |
| 154 | EXPECT_EQ(entry->subsystem, 0x62); |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 155 | |
| 156 | ASSERT_EQ(entry->severity->size(), 3); |
| 157 | EXPECT_EQ((*entry->severity)[0].severity, 0x40); |
| 158 | EXPECT_EQ((*entry->severity)[0].system, "systemA"); |
| 159 | EXPECT_EQ((*entry->severity)[1].severity, 0x10); |
| 160 | EXPECT_EQ((*entry->severity)[1].system, "systemB"); |
| 161 | EXPECT_EQ((*entry->severity)[2].severity, 0x20); |
| 162 | EXPECT_EQ((*entry->severity)[2].system, ""); |
| 163 | |
| 164 | EXPECT_EQ(entry->mfgSeverity->size(), 1); |
| 165 | EXPECT_EQ((*entry->mfgSeverity)[0].severity, 0x00); |
| 166 | |
Matt Spinler | e07f915 | 2019-11-01 10:48:36 -0500 | [diff] [blame] | 167 | EXPECT_EQ(*(entry->actionFlags), 0xA800); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 168 | EXPECT_EQ(*(entry->mfgActionFlags), 0x4000); |
Matt Spinler | 93e2932 | 2019-09-20 11:16:15 -0500 | [diff] [blame] | 169 | EXPECT_EQ(entry->componentID, 0x2300); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 170 | EXPECT_FALSE(entry->eventType); |
| 171 | EXPECT_FALSE(entry->eventScope); |
| 172 | |
Matt Spinler | 93e2932 | 2019-09-20 11:16:15 -0500 | [diff] [blame] | 173 | EXPECT_EQ(entry->src.type, 0xBD); |
| 174 | EXPECT_EQ(entry->src.reasonCode, 0x2333); |
| 175 | EXPECT_EQ(*(entry->src.powerFault), true); |
| 176 | |
| 177 | auto& hexwords = entry->src.hexwordADFields; |
| 178 | EXPECT_TRUE(hexwords); |
| 179 | EXPECT_EQ((*hexwords).size(), 2); |
| 180 | |
| 181 | auto word = (*hexwords).find(6); |
| 182 | EXPECT_NE(word, (*hexwords).end()); |
| 183 | EXPECT_EQ(word->second, "PS_NUM"); |
| 184 | |
| 185 | word = (*hexwords).find(7); |
| 186 | EXPECT_NE(word, (*hexwords).end()); |
| 187 | EXPECT_EQ(word->second, "VOLTAGE"); |
| 188 | |
| 189 | auto& sid = entry->src.symptomID; |
| 190 | EXPECT_TRUE(sid); |
| 191 | EXPECT_EQ((*sid).size(), 3); |
| 192 | EXPECT_NE(std::find((*sid).begin(), (*sid).end(), 5), (*sid).end()); |
| 193 | EXPECT_NE(std::find((*sid).begin(), (*sid).end(), 6), (*sid).end()); |
| 194 | EXPECT_NE(std::find((*sid).begin(), (*sid).end(), 7), (*sid).end()); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 195 | |
| 196 | EXPECT_EQ(entry->doc.description, "A PGOOD Fault"); |
| 197 | EXPECT_EQ(entry->doc.message, "PS %1 had a PGOOD Fault"); |
| 198 | auto& hexwordSource = entry->doc.messageArgSources; |
| 199 | EXPECT_TRUE(hexwordSource); |
| 200 | EXPECT_EQ((*hexwordSource).size(), 1); |
| 201 | EXPECT_EQ((*hexwordSource).front(), "SRCWord6"); |
| 202 | |
| 203 | entry = registry.lookup("0x2333", LookupType::reasonCode); |
| 204 | ASSERT_TRUE(entry); |
| 205 | EXPECT_EQ(entry->name, "xyz.openbmc_project.Power.OverVoltage"); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | // Check the entry that mostly uses defaults |
| 209 | TEST_F(RegistryTest, TestFindEntryMinimal) |
| 210 | { |
| 211 | auto path = RegistryTest::writeData(registryData); |
| 212 | Registry registry{path}; |
| 213 | |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 214 | auto entry = |
| 215 | registry.lookup("xyz.openbmc_project.Power.Fault", LookupType::name); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 216 | ASSERT_TRUE(entry); |
| 217 | EXPECT_EQ(entry->name, "xyz.openbmc_project.Power.Fault"); |
| 218 | EXPECT_EQ(entry->subsystem, 0x61); |
| 219 | EXPECT_FALSE(entry->severity); |
| 220 | EXPECT_FALSE(entry->mfgSeverity); |
| 221 | EXPECT_FALSE(entry->mfgActionFlags); |
Matt Spinler | e07f915 | 2019-11-01 10:48:36 -0500 | [diff] [blame] | 222 | EXPECT_FALSE(entry->actionFlags); |
Matt Spinler | 93e2932 | 2019-09-20 11:16:15 -0500 | [diff] [blame] | 223 | EXPECT_EQ(entry->componentID, 0x2000); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 224 | EXPECT_FALSE(entry->eventType); |
| 225 | EXPECT_FALSE(entry->eventScope); |
Matt Spinler | 93e2932 | 2019-09-20 11:16:15 -0500 | [diff] [blame] | 226 | |
| 227 | EXPECT_EQ(entry->src.reasonCode, 0x2030); |
| 228 | EXPECT_EQ(entry->src.type, 0xBD); |
| 229 | EXPECT_FALSE(entry->src.powerFault); |
| 230 | EXPECT_FALSE(entry->src.hexwordADFields); |
| 231 | EXPECT_FALSE(entry->src.symptomID); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | TEST_F(RegistryTest, TestBadJSON) |
| 235 | { |
| 236 | auto path = RegistryTest::writeData("bad {} json"); |
| 237 | |
| 238 | Registry registry{path}; |
| 239 | |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 240 | EXPECT_FALSE(registry.lookup("foo", LookupType::name)); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // Test the helper functions the use the pel_values data. |
| 244 | TEST_F(RegistryTest, TestHelperFunctions) |
| 245 | { |
| 246 | using namespace openpower::pels::message::helper; |
| 247 | EXPECT_EQ(getSubsystem("input_power_source"), 0xA1); |
| 248 | EXPECT_THROW(getSubsystem("foo"), std::runtime_error); |
| 249 | |
| 250 | EXPECT_EQ(getSeverity("symptom_recovered"), 0x71); |
| 251 | EXPECT_THROW(getSeverity("foo"), std::runtime_error); |
| 252 | |
| 253 | EXPECT_EQ(getEventType("dump_notification"), 0x08); |
| 254 | EXPECT_THROW(getEventType("foo"), std::runtime_error); |
| 255 | |
| 256 | EXPECT_EQ(getEventScope("possibly_multiple_platforms"), 0x04); |
| 257 | EXPECT_THROW(getEventScope("foo"), std::runtime_error); |
| 258 | |
| 259 | std::vector<std::string> flags{"service_action", "dont_report", |
| 260 | "termination"}; |
| 261 | EXPECT_EQ(getActionFlags(flags), 0x9100); |
| 262 | |
| 263 | flags.clear(); |
| 264 | flags.push_back("foo"); |
| 265 | EXPECT_THROW(getActionFlags(flags), std::runtime_error); |
| 266 | } |
Matt Spinler | 93e2932 | 2019-09-20 11:16:15 -0500 | [diff] [blame] | 267 | |
| 268 | TEST_F(RegistryTest, TestGetSRCReasonCode) |
| 269 | { |
| 270 | using namespace openpower::pels::message::helper; |
| 271 | EXPECT_EQ(getSRCReasonCode(R"({"ReasonCode": "0x5555"})"_json, "foo"), |
| 272 | 0x5555); |
| 273 | |
| 274 | EXPECT_THROW(getSRCReasonCode(R"({"ReasonCode": "ZZZZ"})"_json, "foo"), |
| 275 | std::runtime_error); |
| 276 | } |
| 277 | |
| 278 | TEST_F(RegistryTest, TestGetSRCType) |
| 279 | { |
| 280 | using namespace openpower::pels::message::helper; |
| 281 | EXPECT_EQ(getSRCType(R"({"Type": "11"})"_json, "foo"), 0x11); |
| 282 | EXPECT_EQ(getSRCType(R"({"Type": "BF"})"_json, "foo"), 0xBF); |
| 283 | |
| 284 | EXPECT_THROW(getSRCType(R"({"Type": "1"})"_json, "foo"), |
| 285 | std::runtime_error); |
| 286 | |
| 287 | EXPECT_THROW(getSRCType(R"({"Type": "111"})"_json, "foo"), |
| 288 | std::runtime_error); |
| 289 | } |
| 290 | |
| 291 | TEST_F(RegistryTest, TestGetSRCHexwordFields) |
| 292 | { |
| 293 | using namespace openpower::pels::message::helper; |
| 294 | const auto hexwords = R"( |
| 295 | {"Words6To9": |
| 296 | { |
| 297 | "8": |
| 298 | { |
| 299 | "AdditionalDataPropSource": "TEST" |
| 300 | } |
| 301 | } |
| 302 | })"_json; |
| 303 | |
| 304 | auto fields = getSRCHexwordFields(hexwords, "foo"); |
| 305 | EXPECT_TRUE(fields); |
| 306 | auto word = fields->find(8); |
| 307 | EXPECT_NE(word, fields->end()); |
| 308 | |
| 309 | const auto theInvalidRWord = R"( |
| 310 | {"Words6To9": |
| 311 | { |
| 312 | "R": |
| 313 | { |
| 314 | "AdditionalDataPropSource": "TEST" |
| 315 | } |
| 316 | } |
| 317 | })"_json; |
| 318 | |
| 319 | EXPECT_THROW(getSRCHexwordFields(theInvalidRWord, "foo"), |
| 320 | std::runtime_error); |
| 321 | } |
| 322 | |
| 323 | TEST_F(RegistryTest, TestGetSRCSymptomIDFields) |
| 324 | { |
| 325 | using namespace openpower::pels::message::helper; |
| 326 | const auto sID = R"( |
| 327 | { |
| 328 | "SymptomIDFields": ["SRCWord3", "SRCWord4", "SRCWord5"] |
| 329 | })"_json; |
| 330 | |
| 331 | auto fields = getSRCSymptomIDFields(sID, "foo"); |
| 332 | EXPECT_NE(std::find(fields->begin(), fields->end(), 3), fields->end()); |
| 333 | EXPECT_NE(std::find(fields->begin(), fields->end(), 4), fields->end()); |
| 334 | EXPECT_NE(std::find(fields->begin(), fields->end(), 5), fields->end()); |
| 335 | |
| 336 | const auto badField = R"( |
| 337 | { |
| 338 | "SymptomIDFields": ["SRCWord3", "SRCWord4", "SRCWord"] |
| 339 | })"_json; |
| 340 | |
| 341 | EXPECT_THROW(getSRCSymptomIDFields(badField, "foo"), std::runtime_error); |
| 342 | } |
| 343 | |
| 344 | TEST_F(RegistryTest, TestGetComponentID) |
| 345 | { |
| 346 | using namespace openpower::pels::message::helper; |
| 347 | |
| 348 | // Get it from the JSON |
| 349 | auto id = |
| 350 | getComponentID(0xBD, 0x4200, R"({"ComponentID":"0x4200"})"_json, "foo"); |
| 351 | EXPECT_EQ(id, 0x4200); |
| 352 | |
| 353 | // Get it from the reason code on a 0xBD SRC |
| 354 | id = getComponentID(0xBD, 0x6700, R"({})"_json, "foo"); |
| 355 | EXPECT_EQ(id, 0x6700); |
| 356 | |
| 357 | // Not present on a 0x11 SRC |
| 358 | EXPECT_THROW(getComponentID(0x11, 0x8800, R"({})"_json, "foo"), |
| 359 | std::runtime_error); |
| 360 | } |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 361 | |
| 362 | // Test when callouts are in the JSON. |
| 363 | TEST_F(RegistryTest, TestGetCallouts) |
| 364 | { |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 365 | std::vector<std::string> names; |
| 366 | |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 367 | { |
| 368 | // Callouts without AD, that depend on system type, |
| 369 | // where there is a default entry without a system type. |
| 370 | auto json = R"( |
| 371 | [ |
| 372 | { |
| 373 | "System": "system1", |
| 374 | "CalloutList": |
| 375 | [ |
| 376 | { |
| 377 | "Priority": "high", |
| 378 | "LocCode": "P1-C1" |
| 379 | }, |
| 380 | { |
| 381 | "Priority": "low", |
| 382 | "LocCode": "P1" |
| 383 | }, |
| 384 | { |
| 385 | "Priority": "low", |
| 386 | "SymbolicFRU": "service_docs" |
| 387 | } |
| 388 | ] |
| 389 | }, |
| 390 | { |
| 391 | "CalloutList": |
| 392 | [ |
| 393 | { |
| 394 | "Priority": "medium", |
| 395 | "Procedure": "no_vpd_for_fru" |
| 396 | }, |
| 397 | { |
| 398 | "Priority": "low", |
| 399 | "LocCode": "P3-C8", |
| 400 | "SymbolicFRUTrusted": "service_docs" |
| 401 | } |
| 402 | ] |
| 403 | |
| 404 | } |
| 405 | ])"_json; |
| 406 | |
| 407 | AdditionalData ad; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 408 | names.push_back("system1"); |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 409 | |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 410 | auto callouts = Registry::getCallouts(json, names, ad); |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 411 | EXPECT_EQ(callouts.size(), 3); |
| 412 | EXPECT_EQ(callouts[0].priority, "high"); |
| 413 | EXPECT_EQ(callouts[0].locCode, "P1-C1"); |
| 414 | EXPECT_EQ(callouts[0].procedure, ""); |
| 415 | EXPECT_EQ(callouts[0].symbolicFRU, ""); |
| 416 | EXPECT_EQ(callouts[0].symbolicFRUTrusted, ""); |
| 417 | EXPECT_EQ(callouts[1].priority, "low"); |
| 418 | EXPECT_EQ(callouts[1].locCode, "P1"); |
| 419 | EXPECT_EQ(callouts[1].procedure, ""); |
| 420 | EXPECT_EQ(callouts[1].symbolicFRU, ""); |
| 421 | EXPECT_EQ(callouts[1].symbolicFRUTrusted, ""); |
| 422 | EXPECT_EQ(callouts[2].priority, "low"); |
| 423 | EXPECT_EQ(callouts[2].locCode, ""); |
| 424 | EXPECT_EQ(callouts[2].procedure, ""); |
| 425 | EXPECT_EQ(callouts[2].symbolicFRU, "service_docs"); |
| 426 | EXPECT_EQ(callouts[2].symbolicFRUTrusted, ""); |
| 427 | |
| 428 | // system2 isn't in the JSON, so it will pick the default one |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 429 | names[0] = "system2"; |
| 430 | callouts = Registry::getCallouts(json, names, ad); |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 431 | EXPECT_EQ(callouts.size(), 2); |
| 432 | EXPECT_EQ(callouts[0].priority, "medium"); |
| 433 | EXPECT_EQ(callouts[0].locCode, ""); |
| 434 | EXPECT_EQ(callouts[0].procedure, "no_vpd_for_fru"); |
| 435 | EXPECT_EQ(callouts[0].symbolicFRU, ""); |
| 436 | EXPECT_EQ(callouts[1].priority, "low"); |
| 437 | EXPECT_EQ(callouts[1].locCode, "P3-C8"); |
| 438 | EXPECT_EQ(callouts[1].procedure, ""); |
| 439 | EXPECT_EQ(callouts[1].symbolicFRU, ""); |
| 440 | EXPECT_EQ(callouts[1].symbolicFRUTrusted, "service_docs"); |
| 441 | } |
| 442 | |
| 443 | // Empty JSON array (treated as an error) |
| 444 | { |
| 445 | auto json = R"([])"_json; |
| 446 | AdditionalData ad; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 447 | names[0] = "system1"; |
| 448 | EXPECT_THROW(Registry::getCallouts(json, names, ad), |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 449 | std::runtime_error); |
| 450 | } |
| 451 | |
| 452 | { |
| 453 | // Callouts without AD, that depend on system type, |
| 454 | // where there isn't a default entry without a system type. |
| 455 | auto json = R"( |
| 456 | [ |
| 457 | { |
| 458 | "System": "system1", |
| 459 | "CalloutList": |
| 460 | [ |
| 461 | { |
| 462 | "Priority": "high", |
| 463 | "LocCode": "P1-C1" |
| 464 | }, |
| 465 | { |
| 466 | "Priority": "low", |
| 467 | "LocCode": "P1", |
| 468 | "SymbolicFRU": "1234567" |
| 469 | } |
| 470 | ] |
| 471 | }, |
| 472 | { |
| 473 | "System": "system2", |
| 474 | "CalloutList": |
| 475 | [ |
| 476 | { |
| 477 | "Priority": "medium", |
| 478 | "LocCode": "P7", |
| 479 | "CalloutType": "tool_fru" |
| 480 | } |
| 481 | ] |
| 482 | |
| 483 | } |
| 484 | ])"_json; |
| 485 | |
| 486 | AdditionalData ad; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 487 | names[0] = "system1"; |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 488 | |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 489 | auto callouts = Registry::getCallouts(json, names, ad); |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 490 | EXPECT_EQ(callouts.size(), 2); |
| 491 | EXPECT_EQ(callouts[0].priority, "high"); |
| 492 | EXPECT_EQ(callouts[0].locCode, "P1-C1"); |
| 493 | EXPECT_EQ(callouts[0].procedure, ""); |
| 494 | EXPECT_EQ(callouts[0].symbolicFRU, ""); |
| 495 | EXPECT_EQ(callouts[0].symbolicFRUTrusted, ""); |
| 496 | EXPECT_EQ(callouts[1].priority, "low"); |
| 497 | EXPECT_EQ(callouts[1].locCode, "P1"); |
| 498 | EXPECT_EQ(callouts[1].procedure, ""); |
| 499 | EXPECT_EQ(callouts[1].symbolicFRU, "1234567"); |
| 500 | EXPECT_EQ(callouts[1].symbolicFRUTrusted, ""); |
| 501 | |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 502 | names[0] = "system2"; |
| 503 | callouts = Registry::getCallouts(json, names, ad); |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 504 | EXPECT_EQ(callouts.size(), 1); |
| 505 | EXPECT_EQ(callouts[0].priority, "medium"); |
| 506 | EXPECT_EQ(callouts[0].locCode, "P7"); |
| 507 | EXPECT_EQ(callouts[0].procedure, ""); |
| 508 | EXPECT_EQ(callouts[0].symbolicFRU, ""); |
| 509 | EXPECT_EQ(callouts[0].symbolicFRUTrusted, ""); |
| 510 | |
| 511 | // There is no entry for system3 or a default system, |
| 512 | // so this should fail. |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 513 | names[0] = "system3"; |
| 514 | EXPECT_THROW(Registry::getCallouts(json, names, ad), |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 515 | std::runtime_error); |
| 516 | } |
| 517 | |
| 518 | { |
| 519 | // Callouts that use the AdditionalData key PROC_NUM |
| 520 | // as an index into them, along with a system type. |
| 521 | // It supports PROC_NUMs 0 and 1. |
| 522 | auto json = R"( |
| 523 | { |
| 524 | "ADName": "PROC_NUM", |
| 525 | "CalloutsWithTheirADValues": |
| 526 | [ |
| 527 | { |
| 528 | "ADValue": "0", |
| 529 | "Callouts": |
| 530 | [ |
| 531 | { |
| 532 | "System": "system3", |
| 533 | "CalloutList": |
| 534 | [ |
| 535 | { |
| 536 | "Priority": "high", |
| 537 | "LocCode": "P1-C5" |
| 538 | }, |
| 539 | { |
| 540 | "Priority": "medium", |
| 541 | "LocCode": "P1-C6", |
| 542 | "SymbolicFRU": "1234567" |
| 543 | }, |
| 544 | { |
| 545 | "Priority": "low", |
| 546 | "Procedure": "no_vpd_for_fru", |
| 547 | "CalloutType": "config_procedure" |
| 548 | } |
| 549 | ] |
| 550 | }, |
| 551 | { |
| 552 | "CalloutList": |
| 553 | [ |
| 554 | { |
| 555 | "Priority": "low", |
| 556 | "LocCode": "P55" |
| 557 | } |
| 558 | ] |
| 559 | } |
| 560 | ] |
| 561 | }, |
| 562 | { |
| 563 | "ADValue": "1", |
| 564 | "Callouts": |
| 565 | [ |
| 566 | { |
| 567 | "CalloutList": |
| 568 | [ |
| 569 | { |
| 570 | "Priority": "high", |
| 571 | "LocCode": "P1-C6", |
| 572 | "CalloutType": "external_fru" |
| 573 | } |
| 574 | ] |
| 575 | } |
| 576 | ] |
| 577 | } |
| 578 | ] |
| 579 | })"_json; |
| 580 | |
| 581 | { |
| 582 | // Find callouts for PROC_NUM 0 on system3 |
| 583 | std::vector<std::string> adData{"PROC_NUM=0"}; |
| 584 | AdditionalData ad{adData}; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 585 | names[0] = "system3"; |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 586 | |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 587 | auto callouts = Registry::getCallouts(json, names, ad); |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 588 | EXPECT_EQ(callouts.size(), 3); |
| 589 | EXPECT_EQ(callouts[0].priority, "high"); |
| 590 | EXPECT_EQ(callouts[0].locCode, "P1-C5"); |
| 591 | EXPECT_EQ(callouts[0].procedure, ""); |
| 592 | EXPECT_EQ(callouts[0].symbolicFRU, ""); |
| 593 | EXPECT_EQ(callouts[0].symbolicFRUTrusted, ""); |
| 594 | EXPECT_EQ(callouts[1].priority, "medium"); |
| 595 | EXPECT_EQ(callouts[1].locCode, "P1-C6"); |
| 596 | EXPECT_EQ(callouts[1].procedure, ""); |
| 597 | EXPECT_EQ(callouts[1].symbolicFRU, "1234567"); |
| 598 | EXPECT_EQ(callouts[1].symbolicFRUTrusted, ""); |
| 599 | EXPECT_EQ(callouts[2].priority, "low"); |
| 600 | EXPECT_EQ(callouts[2].locCode, ""); |
| 601 | EXPECT_EQ(callouts[2].procedure, "no_vpd_for_fru"); |
| 602 | EXPECT_EQ(callouts[2].symbolicFRU, ""); |
| 603 | EXPECT_EQ(callouts[2].symbolicFRUTrusted, ""); |
| 604 | |
| 605 | // Find callouts for PROC_NUM 0 that uses the default system entry. |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 606 | names[0] = "system99"; |
| 607 | |
| 608 | callouts = Registry::getCallouts(json, names, ad); |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 609 | EXPECT_EQ(callouts.size(), 1); |
| 610 | EXPECT_EQ(callouts[0].priority, "low"); |
| 611 | EXPECT_EQ(callouts[0].locCode, "P55"); |
| 612 | EXPECT_EQ(callouts[0].procedure, ""); |
| 613 | EXPECT_EQ(callouts[0].symbolicFRU, ""); |
| 614 | EXPECT_EQ(callouts[0].symbolicFRUTrusted, ""); |
| 615 | } |
| 616 | { |
| 617 | // Find callouts for PROC_NUM 1 that uses a default system entry. |
| 618 | std::vector<std::string> adData{"PROC_NUM=1"}; |
| 619 | AdditionalData ad{adData}; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 620 | names[0] = "system1"; |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 621 | |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 622 | auto callouts = Registry::getCallouts(json, names, ad); |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 623 | EXPECT_EQ(callouts.size(), 1); |
| 624 | EXPECT_EQ(callouts[0].priority, "high"); |
| 625 | EXPECT_EQ(callouts[0].locCode, "P1-C6"); |
| 626 | EXPECT_EQ(callouts[0].procedure, ""); |
| 627 | EXPECT_EQ(callouts[0].symbolicFRU, ""); |
| 628 | EXPECT_EQ(callouts[0].symbolicFRUTrusted, ""); |
| 629 | } |
| 630 | { |
| 631 | // There is no entry for PROC_NUM 2, it will fail. |
| 632 | std::vector<std::string> adData{"PROC_NUM=2"}; |
| 633 | AdditionalData ad{adData}; |
| 634 | |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 635 | EXPECT_THROW(Registry::getCallouts(json, names, ad), |
Matt Spinler | 6b427cc | 2020-04-09 09:42:59 -0500 | [diff] [blame] | 636 | std::runtime_error); |
| 637 | } |
| 638 | } |
| 639 | } |