blob: 7c80894b1ab6c82bc9aaa05647e489bd79702c67 [file] [log] [blame]
Matt Spinler97f7abc2019-11-06 09:40:23 -06001/**
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 Spinler14d671f2019-09-25 13:11:22 -050016#include "extensions/openpower-pels/generic.hpp"
17#include "pel_utils.hpp"
18
19#include <gtest/gtest.h>
20
21using namespace openpower::pels;
22
23TEST(GenericSectionTest, UnflattenFlattenTest)
24{
25 // Use the private header data
Matt Spinler42828bd2019-10-11 10:39:30 -050026 auto data = pelDataFactory(TestPELType::privateHeaderSection);
Matt Spinler14d671f2019-09-25 13:11:22 -050027
Matt Spinler42828bd2019-10-11 10:39:30 -050028 Stream stream(data);
Matt Spinler14d671f2019-09-25 13:11:22 -050029 Generic section(stream);
30
31 EXPECT_EQ(section.header().id, 0x5048);
Matt Spinler42828bd2019-10-11 10:39:30 -050032 EXPECT_EQ(section.header().size, data.size());
Matt Spinler14d671f2019-09-25 13:11:22 -050033 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 Spinler42828bd2019-10-11 10:39:30 -050040 EXPECT_EQ(sectionData.size(), data.size() - 8);
Matt Spinler14d671f2019-09-25 13:11:22 -050041
42 for (size_t i = 0; i < sectionData.size(); i++)
43 {
Matt Spinler42828bd2019-10-11 10:39:30 -050044 EXPECT_EQ(sectionData[i], (data)[i + 8]);
Matt Spinler14d671f2019-09-25 13:11:22 -050045 }
46
47 // Now flatten
48 std::vector<uint8_t> newData;
49 Stream newStream(newData);
50 section.flatten(newStream);
51
Matt Spinler42828bd2019-10-11 10:39:30 -050052 EXPECT_EQ(data, newData);
Matt Spinler14d671f2019-09-25 13:11:22 -050053}
54
55TEST(GenericSectionTest, BadDataTest)
56{
57 // Use the private header data to start with
Matt Spinler42828bd2019-10-11 10:39:30 -050058 auto data = pelDataFactory(TestPELType::privateHeaderSection);
59 data.resize(4);
Matt Spinler14d671f2019-09-25 13:11:22 -050060
Matt Spinler42828bd2019-10-11 10:39:30 -050061 Stream stream(data);
Matt Spinler14d671f2019-09-25 13:11:22 -050062 Generic section(stream);
63 ASSERT_FALSE(section.valid());
64}