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