Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 1 | #include "extensions/openpower-pels/generic.hpp" |
| 2 | #include "pel_utils.hpp" |
| 3 | |
| 4 | #include <gtest/gtest.h> |
| 5 | |
| 6 | using namespace openpower::pels; |
| 7 | |
| 8 | TEST(GenericSectionTest, UnflattenFlattenTest) |
| 9 | { |
| 10 | // Use the private header data |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame^] | 11 | auto data = pelDataFactory(TestPELType::privateHeaderSection); |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 12 | |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame^] | 13 | Stream stream(data); |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 14 | Generic section(stream); |
| 15 | |
| 16 | EXPECT_EQ(section.header().id, 0x5048); |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame^] | 17 | EXPECT_EQ(section.header().size, data.size()); |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 18 | EXPECT_EQ(section.header().version, 0x01); |
| 19 | EXPECT_EQ(section.header().subType, 0x02); |
| 20 | EXPECT_EQ(section.header().componentID, 0x0304); |
| 21 | |
| 22 | const auto& sectionData = section.data(); |
| 23 | |
| 24 | // The data itself starts after the header |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame^] | 25 | EXPECT_EQ(sectionData.size(), data.size() - 8); |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 26 | |
| 27 | for (size_t i = 0; i < sectionData.size(); i++) |
| 28 | { |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame^] | 29 | EXPECT_EQ(sectionData[i], (data)[i + 8]); |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | // Now flatten |
| 33 | std::vector<uint8_t> newData; |
| 34 | Stream newStream(newData); |
| 35 | section.flatten(newStream); |
| 36 | |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame^] | 37 | EXPECT_EQ(data, newData); |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | TEST(GenericSectionTest, BadDataTest) |
| 41 | { |
| 42 | // Use the private header data to start with |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame^] | 43 | auto data = pelDataFactory(TestPELType::privateHeaderSection); |
| 44 | data.resize(4); |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 45 | |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame^] | 46 | Stream stream(data); |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 47 | Generic section(stream); |
| 48 | ASSERT_FALSE(section.valid()); |
| 49 | } |