blob: 7cb9949cfcd1d0fd02a1eb915e51378296a55196 [file] [log] [blame]
Matt Spinler14d671f2019-09-25 13:11:22 -05001#include "extensions/openpower-pels/generic.hpp"
2#include "pel_utils.hpp"
3
4#include <gtest/gtest.h>
5
6using namespace openpower::pels;
7
8TEST(GenericSectionTest, UnflattenFlattenTest)
9{
10 // Use the private header data
Matt Spinler42828bd2019-10-11 10:39:30 -050011 auto data = pelDataFactory(TestPELType::privateHeaderSection);
Matt Spinler14d671f2019-09-25 13:11:22 -050012
Matt Spinler42828bd2019-10-11 10:39:30 -050013 Stream stream(data);
Matt Spinler14d671f2019-09-25 13:11:22 -050014 Generic section(stream);
15
16 EXPECT_EQ(section.header().id, 0x5048);
Matt Spinler42828bd2019-10-11 10:39:30 -050017 EXPECT_EQ(section.header().size, data.size());
Matt Spinler14d671f2019-09-25 13:11:22 -050018 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 Spinler42828bd2019-10-11 10:39:30 -050025 EXPECT_EQ(sectionData.size(), data.size() - 8);
Matt Spinler14d671f2019-09-25 13:11:22 -050026
27 for (size_t i = 0; i < sectionData.size(); i++)
28 {
Matt Spinler42828bd2019-10-11 10:39:30 -050029 EXPECT_EQ(sectionData[i], (data)[i + 8]);
Matt Spinler14d671f2019-09-25 13:11:22 -050030 }
31
32 // Now flatten
33 std::vector<uint8_t> newData;
34 Stream newStream(newData);
35 section.flatten(newStream);
36
Matt Spinler42828bd2019-10-11 10:39:30 -050037 EXPECT_EQ(data, newData);
Matt Spinler14d671f2019-09-25 13:11:22 -050038}
39
40TEST(GenericSectionTest, BadDataTest)
41{
42 // Use the private header data to start with
Matt Spinler42828bd2019-10-11 10:39:30 -050043 auto data = pelDataFactory(TestPELType::privateHeaderSection);
44 data.resize(4);
Matt Spinler14d671f2019-09-25 13:11:22 -050045
Matt Spinler42828bd2019-10-11 10:39:30 -050046 Stream stream(data);
Matt Spinler14d671f2019-09-25 13:11:22 -050047 Generic section(stream);
48 ASSERT_FALSE(section.valid());
49}