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 | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 16 | #include "elog_entry.hpp" |
| 17 | #include "extensions/openpower-pels/pel_types.hpp" |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 18 | #include "extensions/openpower-pels/private_header.hpp" |
| 19 | #include "extensions/openpower-pels/user_header.hpp" |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 20 | #include "mocks.hpp" |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 21 | #include "pel_utils.hpp" |
| 22 | |
| 23 | #include <gtest/gtest.h> |
| 24 | |
| 25 | using namespace openpower::pels; |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 26 | using ::testing::Return; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 27 | |
| 28 | TEST(UserHeaderTest, SizeTest) |
| 29 | { |
| 30 | EXPECT_EQ(UserHeader::flattenedSize(), 24); |
| 31 | } |
| 32 | |
| 33 | TEST(UserHeaderTest, UnflattenFlattenTest) |
| 34 | { |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 35 | auto data = pelDataFactory(TestPELType::userHeaderSection); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 36 | |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 37 | Stream stream(data); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 38 | UserHeader uh(stream); |
| 39 | EXPECT_EQ(uh.valid(), true); |
| 40 | |
| 41 | EXPECT_EQ(uh.header().id, 0x5548); |
| 42 | EXPECT_EQ(uh.header().size, UserHeader::flattenedSize()); |
| 43 | EXPECT_EQ(uh.header().version, 0x01); |
| 44 | EXPECT_EQ(uh.header().subType, 0x0A); |
| 45 | EXPECT_EQ(uh.header().componentID, 0x0B0C); |
| 46 | |
| 47 | EXPECT_EQ(uh.subsystem(), 0x10); |
| 48 | EXPECT_EQ(uh.scope(), 0x04); |
| 49 | EXPECT_EQ(uh.severity(), 0x20); |
| 50 | EXPECT_EQ(uh.eventType(), 0x00); |
| 51 | EXPECT_EQ(uh.problemDomain(), 0x03); |
| 52 | EXPECT_EQ(uh.problemVector(), 0x04); |
| 53 | EXPECT_EQ(uh.actionFlags(), 0x80C0); |
| 54 | |
| 55 | // Now flatten into a vector and check that this vector |
| 56 | // matches the original one. |
| 57 | std::vector<uint8_t> newData; |
| 58 | Stream newStream(newData); |
| 59 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 60 | uh.flatten(newStream); |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 61 | EXPECT_EQ(data, newData); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | TEST(UserHeaderTest, ShortDataTest) |
| 65 | { |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 66 | auto data = pelDataFactory(TestPELType::userHeaderSection); |
| 67 | data.resize(data.size() - 1); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 68 | |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 69 | Stream stream(data); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 70 | UserHeader uh(stream); |
| 71 | |
| 72 | EXPECT_EQ(uh.valid(), false); |
| 73 | } |
| 74 | |
| 75 | TEST(UserHeaderTest, CorruptDataTest1) |
| 76 | { |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 77 | auto data = pelDataFactory(TestPELType::userHeaderSection); |
| 78 | data.resize(data.size() - 1); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 79 | |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 80 | data.at(0) = 0; // corrupt the section ID |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 81 | |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 82 | Stream stream(data); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 83 | UserHeader uh(stream); |
| 84 | |
| 85 | EXPECT_EQ(uh.valid(), false); |
| 86 | } |
| 87 | |
| 88 | TEST(UserHeaderTest, CorruptDataTest2) |
| 89 | { |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 90 | auto data = pelDataFactory(TestPELType::userHeaderSection); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 91 | |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 92 | data.at(4) = 0x22; // corrupt the version |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 93 | |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 94 | Stream stream(data); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 95 | UserHeader uh(stream); |
| 96 | |
| 97 | EXPECT_EQ(uh.valid(), false); |
| 98 | } |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 99 | |
| 100 | // Construct the User Header from the message registry |
| 101 | TEST(UserHeaderTest, ConstructionTest) |
| 102 | { |
| 103 | using namespace openpower::pels::message; |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 104 | { |
| 105 | Entry regEntry; |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 106 | |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 107 | regEntry.name = "test"; |
| 108 | regEntry.subsystem = 5; |
| 109 | regEntry.severity = {{"", 0x40}}; |
| 110 | regEntry.actionFlags = 0xC000; |
| 111 | regEntry.eventType = 1; |
| 112 | regEntry.eventScope = 2; |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 113 | |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 114 | MockDataInterface dataIface; |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 115 | AdditionalData ad; |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 116 | |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 117 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad, |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 118 | dataIface); |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 119 | |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 120 | ASSERT_TRUE(uh.valid()); |
| 121 | EXPECT_EQ(uh.header().id, 0x5548); |
| 122 | EXPECT_EQ(uh.header().size, UserHeader::flattenedSize()); |
| 123 | EXPECT_EQ(uh.header().version, 0x01); |
| 124 | EXPECT_EQ(uh.header().subType, 0x00); |
| 125 | EXPECT_EQ(uh.header().componentID, |
| 126 | static_cast<uint16_t>(ComponentID::phosphorLogging)); |
| 127 | |
Matt Spinler | 1f93c59 | 2020-09-10 10:43:08 -0500 | [diff] [blame] | 128 | EXPECT_EQ(uh.subsystem(), 5); |
| 129 | EXPECT_EQ(uh.severity(), 0x40); |
| 130 | EXPECT_EQ(uh.eventType(), 1); |
| 131 | EXPECT_EQ(uh.scope(), 2); |
| 132 | EXPECT_EQ(uh.problemDomain(), 0); |
| 133 | EXPECT_EQ(uh.problemVector(), 0); |
| 134 | EXPECT_EQ(uh.actionFlags(), 0xC000); |
| 135 | |
| 136 | { |
| 137 | // The same thing, but as if the action flags weren't specified |
| 138 | // in the registry so they are a nullopt. The object should |
| 139 | // then set them to 0xFFFF. |
Matt Spinler | 1f93c59 | 2020-09-10 10:43:08 -0500 | [diff] [blame] | 140 | regEntry.actionFlags = std::nullopt; |
| 141 | |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 142 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad, |
Matt Spinler | 1f93c59 | 2020-09-10 10:43:08 -0500 | [diff] [blame] | 143 | dataIface); |
| 144 | EXPECT_EQ(uh.actionFlags(), 0xFFFF); |
| 145 | } |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // Test the system type based severity lookups |
| 149 | { |
| 150 | Entry regEntry; |
| 151 | |
| 152 | regEntry.name = "test"; |
| 153 | regEntry.subsystem = 5; |
| 154 | regEntry.severity = {{"", 0x20}, {"systemB", 0x10}, {"systemA", 0x00}}; |
| 155 | |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 156 | AdditionalData ad; |
| 157 | |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 158 | MockDataInterface dataIface; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 159 | std::vector<std::string> names1{"systemA"}; |
| 160 | std::vector<std::string> names2{"systemB"}; |
| 161 | std::vector<std::string> names3{"systemC"}; |
| 162 | |
| 163 | EXPECT_CALL(dataIface, getSystemNames) |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 164 | .WillOnce(Return(names1)) |
| 165 | .WillOnce(Return(names2)) |
| 166 | .WillOnce(Return(names3)); |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 167 | |
| 168 | { |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 169 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad, |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 170 | dataIface); |
| 171 | |
| 172 | EXPECT_EQ(uh.severity(), 0x00); |
| 173 | } |
| 174 | |
| 175 | { |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 176 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad, |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 177 | dataIface); |
| 178 | |
| 179 | EXPECT_EQ(uh.severity(), 0x10); |
| 180 | } |
| 181 | |
| 182 | { |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 183 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad, |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 184 | dataIface); |
| 185 | |
| 186 | EXPECT_EQ(uh.severity(), 0x20); |
| 187 | } |
| 188 | } |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Test that the severity comes from the event log if not |
| 192 | // in the message registry |
| 193 | TEST(UserHeaderTest, UseEventLogSevTest) |
| 194 | { |
| 195 | using namespace openpower::pels::message; |
| 196 | Entry regEntry; |
| 197 | |
| 198 | regEntry.name = "test"; |
| 199 | regEntry.subsystem = 5; |
| 200 | regEntry.actionFlags = 0xC000; |
| 201 | regEntry.eventType = 1; |
| 202 | regEntry.eventScope = 2; |
| 203 | // Leave off severity |
| 204 | |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 205 | MockDataInterface dataIface; |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 206 | AdditionalData ad; |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 207 | |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 208 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad, |
| 209 | dataIface); |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 210 | ASSERT_EQ(uh.severity(), 0x40); |
| 211 | } |
| 212 | |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 213 | // Test that the critical severity comes from the event log if not |
| 214 | // in the message registry |
| 215 | TEST(UserHeaderTest, UseEventLogSevCritTest) |
| 216 | { |
| 217 | using namespace openpower::pels::message; |
| 218 | Entry regEntry; |
| 219 | |
| 220 | regEntry.name = "test"; |
| 221 | regEntry.subsystem = 5; |
| 222 | regEntry.actionFlags = 0xC000; |
| 223 | regEntry.eventType = 1; |
| 224 | regEntry.eventScope = 2; |
| 225 | // Leave off severity |
| 226 | |
| 227 | MockDataInterface dataIface; |
| 228 | AdditionalData ad; |
| 229 | |
| 230 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Critical, ad, |
| 231 | dataIface); |
| 232 | ASSERT_EQ(uh.severity(), 0x50); |
| 233 | } |
| 234 | |
| 235 | // Test that the critical severity comes from the event log if not |
| 236 | // in the message registry and termination condition is set |
| 237 | TEST(UserHeaderTest, UseEventLogSevCritTermTest) |
| 238 | { |
| 239 | using namespace openpower::pels::message; |
| 240 | Entry regEntry; |
| 241 | |
| 242 | regEntry.name = "test"; |
| 243 | regEntry.subsystem = 5; |
| 244 | regEntry.actionFlags = 0xC000; |
| 245 | regEntry.eventType = 1; |
| 246 | regEntry.eventScope = 2; |
| 247 | // Leave off severity |
| 248 | |
| 249 | MockDataInterface dataIface; |
| 250 | std::vector<std::string> adData{"SEVERITY_DETAIL=SYSTEM_TERM"}; |
| 251 | AdditionalData ad{adData}; |
| 252 | |
| 253 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Critical, ad, |
| 254 | dataIface); |
| 255 | ASSERT_EQ(uh.severity(), 0x51); |
| 256 | } |
| 257 | |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 258 | // Test that the optional event type & scope fields work |
| 259 | TEST(UserHeaderTest, DefaultEventTypeScopeTest) |
| 260 | { |
| 261 | using namespace openpower::pels::message; |
| 262 | Entry regEntry; |
| 263 | |
| 264 | regEntry.name = "test"; |
| 265 | regEntry.subsystem = 5; |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 266 | regEntry.severity = {{"", 0x40}}; |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 267 | regEntry.actionFlags = 0xC000; |
| 268 | |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 269 | MockDataInterface dataIface; |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 270 | AdditionalData ad; |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 271 | |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 272 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad, |
| 273 | dataIface); |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 274 | |
| 275 | ASSERT_EQ(uh.eventType(), 0); |
| 276 | ASSERT_EQ(uh.scope(), 0x03); |
| 277 | } |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 278 | |
| 279 | // Test that the event severity & action flags override |
| 280 | // when QuiesceOnHwError is set |
| 281 | TEST(UserHeaderTest, UseEventLogQuiesceOnErrorTest) |
| 282 | { |
| 283 | using namespace openpower::pels::message; |
| 284 | Entry regEntry; |
| 285 | |
| 286 | regEntry.name = "test"; |
| 287 | regEntry.subsystem = 5; |
| 288 | regEntry.actionFlags = 0xC000; |
| 289 | regEntry.eventType = 1; |
| 290 | regEntry.eventScope = 2; |
| 291 | regEntry.severity = {{"", 0x40}, {"systemB", 0x10}, {"systemA", 0x00}}; |
| 292 | |
| 293 | // set the value for mfg severity and action flags |
| 294 | regEntry.mfgSeverity = {{"systemA", 0x20}}; |
| 295 | regEntry.mfgActionFlags = 0xF000; |
| 296 | |
| 297 | std::vector<std::string> names{"systemA"}; |
| 298 | |
| 299 | MockDataInterface dataIface; |
| 300 | AdditionalData ad; |
| 301 | |
| 302 | EXPECT_CALL(dataIface, getSystemNames).WillOnce(Return(names)); |
| 303 | EXPECT_CALL(dataIface, getQuiesceOnError).WillOnce(Return(true)); |
| 304 | |
| 305 | UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad, |
| 306 | dataIface); |
| 307 | |
| 308 | EXPECT_EQ(uh.severity(), 0x20); |
| 309 | EXPECT_EQ(uh.actionFlags(), 0xF000); |
| 310 | } |