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