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