Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 1 | #include "extensions/openpower-pels/private_header.hpp" |
| 2 | #include "extensions/openpower-pels/user_header.hpp" |
| 3 | #include "pel_utils.hpp" |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | using namespace openpower::pels; |
| 8 | |
| 9 | TEST(UserHeaderTest, SizeTest) |
| 10 | { |
| 11 | EXPECT_EQ(UserHeader::flattenedSize(), 24); |
| 12 | } |
| 13 | |
| 14 | TEST(UserHeaderTest, UnflattenFlattenTest) |
| 15 | { |
| 16 | auto data = pelDataFactory(TestPelType::userHeaderSimple); |
| 17 | |
| 18 | Stream stream(*data); |
| 19 | UserHeader uh(stream); |
| 20 | EXPECT_EQ(uh.valid(), true); |
| 21 | |
| 22 | EXPECT_EQ(uh.header().id, 0x5548); |
| 23 | EXPECT_EQ(uh.header().size, UserHeader::flattenedSize()); |
| 24 | EXPECT_EQ(uh.header().version, 0x01); |
| 25 | EXPECT_EQ(uh.header().subType, 0x0A); |
| 26 | EXPECT_EQ(uh.header().componentID, 0x0B0C); |
| 27 | |
| 28 | EXPECT_EQ(uh.subsystem(), 0x10); |
| 29 | EXPECT_EQ(uh.scope(), 0x04); |
| 30 | EXPECT_EQ(uh.severity(), 0x20); |
| 31 | EXPECT_EQ(uh.eventType(), 0x00); |
| 32 | EXPECT_EQ(uh.problemDomain(), 0x03); |
| 33 | EXPECT_EQ(uh.problemVector(), 0x04); |
| 34 | EXPECT_EQ(uh.actionFlags(), 0x80C0); |
| 35 | |
| 36 | // Now flatten into a vector and check that this vector |
| 37 | // matches the original one. |
| 38 | std::vector<uint8_t> newData; |
| 39 | Stream newStream(newData); |
| 40 | |
| 41 | newStream << uh; |
| 42 | EXPECT_EQ(*data, newData); |
| 43 | |
| 44 | // Change a field, then flatten and unflatten again |
| 45 | uh.subsystem() = 0x44; |
| 46 | |
| 47 | newStream.offset(0); |
| 48 | newData.clear(); |
| 49 | newStream << uh; |
| 50 | EXPECT_NE(*data, newData); |
| 51 | |
| 52 | newStream.offset(0); |
| 53 | UserHeader newUH(newStream); |
| 54 | |
| 55 | EXPECT_TRUE(newUH.valid()); |
| 56 | EXPECT_EQ(newUH.subsystem(), 0x44); |
| 57 | } |
| 58 | |
| 59 | TEST(UserHeaderTest, ShortDataTest) |
| 60 | { |
| 61 | auto data = pelDataFactory(TestPelType::userHeaderSimple); |
| 62 | data->resize(data->size() - 1); |
| 63 | |
| 64 | Stream stream(*data); |
| 65 | UserHeader uh(stream); |
| 66 | |
| 67 | EXPECT_EQ(uh.valid(), false); |
| 68 | } |
| 69 | |
| 70 | TEST(UserHeaderTest, CorruptDataTest1) |
| 71 | { |
| 72 | auto data = pelDataFactory(TestPelType::userHeaderSimple); |
| 73 | data->resize(data->size() - 1); |
| 74 | |
| 75 | data->at(0) = 0; // corrupt the section ID |
| 76 | |
| 77 | Stream stream(*data); |
| 78 | UserHeader uh(stream); |
| 79 | |
| 80 | EXPECT_EQ(uh.valid(), false); |
| 81 | } |
| 82 | |
| 83 | TEST(UserHeaderTest, CorruptDataTest2) |
| 84 | { |
| 85 | auto data = pelDataFactory(TestPelType::userHeaderSimple); |
| 86 | |
| 87 | data->at(4) = 0x22; // corrupt the version |
| 88 | |
| 89 | Stream stream(*data); |
| 90 | UserHeader uh(stream); |
| 91 | |
| 92 | EXPECT_EQ(uh.valid(), false); |
| 93 | } |