blob: 96b79b5ca16a5fbb592ea8d1f8ed9852b05877ea [file] [log] [blame]
Alexander Hansen40fb5492025-10-28 17:56:12 +01001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2019 IBM Corporation
3
Matt Spinler14d671f2019-09-25 13:11:22 -05004#include "extensions/openpower-pels/generic.hpp"
5#include "pel_utils.hpp"
6
7#include <gtest/gtest.h>
8
9using namespace openpower::pels;
10
11TEST(GenericSectionTest, UnflattenFlattenTest)
12{
13 // Use the private header data
Matt Spinler42828bd2019-10-11 10:39:30 -050014 auto data = pelDataFactory(TestPELType::privateHeaderSection);
Matt Spinler14d671f2019-09-25 13:11:22 -050015
Matt Spinler42828bd2019-10-11 10:39:30 -050016 Stream stream(data);
Matt Spinler14d671f2019-09-25 13:11:22 -050017 Generic section(stream);
18
19 EXPECT_EQ(section.header().id, 0x5048);
Matt Spinler42828bd2019-10-11 10:39:30 -050020 EXPECT_EQ(section.header().size, data.size());
Matt Spinler14d671f2019-09-25 13:11:22 -050021 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 Spinler42828bd2019-10-11 10:39:30 -050028 EXPECT_EQ(sectionData.size(), data.size() - 8);
Matt Spinler14d671f2019-09-25 13:11:22 -050029
30 for (size_t i = 0; i < sectionData.size(); i++)
31 {
Matt Spinler42828bd2019-10-11 10:39:30 -050032 EXPECT_EQ(sectionData[i], (data)[i + 8]);
Matt Spinler14d671f2019-09-25 13:11:22 -050033 }
34
35 // Now flatten
36 std::vector<uint8_t> newData;
37 Stream newStream(newData);
38 section.flatten(newStream);
39
Matt Spinler42828bd2019-10-11 10:39:30 -050040 EXPECT_EQ(data, newData);
Matt Spinler14d671f2019-09-25 13:11:22 -050041}
42
43TEST(GenericSectionTest, BadDataTest)
44{
45 // Use the private header data to start with
Matt Spinler42828bd2019-10-11 10:39:30 -050046 auto data = pelDataFactory(TestPELType::privateHeaderSection);
47 data.resize(4);
Matt Spinler14d671f2019-09-25 13:11:22 -050048
Matt Spinler42828bd2019-10-11 10:39:30 -050049 Stream stream(data);
Matt Spinler14d671f2019-09-25 13:11:22 -050050 Generic section(stream);
51 ASSERT_FALSE(section.valid());
52}