PEL: ExtendedUserData section class
This class represents the Extended User Data section. This section is
similar to the UserData class in that it stores free form FFDC data,
except that it is meant to be added to an already existing PEL by a
creator subsystem that is different than the PEL creator's subsystem.
As such, it stores the section creator's creator ID value as a field
within the section, which the regular UserData class doesn't do.
The same parsers that run on the UserData section can also run on this
section.
Change-Id: I8562a89141f0305e397703f0cb92a06eb9f10133
diff --git a/test/openpower-pels/Makefile.include b/test/openpower-pels/Makefile.include
index b4c6a01..a098ad9 100644
--- a/test/openpower-pels/Makefile.include
+++ b/test/openpower-pels/Makefile.include
@@ -6,6 +6,7 @@
bcd_time_test \
device_callouts_test \
event_logger_test \
+ extended_user_data_test \
extended_user_header_test \
failing_mtms_test \
fru_identity_test \
@@ -39,6 +40,7 @@
$(top_builddir)/extensions/openpower-pels/callout.o \
$(top_builddir)/extensions/openpower-pels/callouts.o \
$(top_builddir)/extensions/openpower-pels/device_callouts.o \
+ $(top_builddir)/extensions/openpower-pels/extended_user_data.o \
$(top_builddir)/extensions/openpower-pels/extended_user_header.o \
$(top_builddir)/extensions/openpower-pels/failing_mtms.o \
$(top_builddir)/extensions/openpower-pels/fru_identity.o \
@@ -383,3 +385,14 @@
$(pel_test_utils_ldadd) \
$(top_builddir)/extensions/openpower-pels/service_indicators.o
service_indicators_test_LDFLAGS = $(test_ldflags)
+
+extended_user_data_test_SOURCES = \
+ %reldir%/extended_user_data_test.cpp
+extended_user_data_test_CPPFLAGS = $(test_cppflags)
+extended_user_data_test_CXXFLAGS = $(test_cxxflags)
+extended_user_data_test_LDADD = \
+ $(test_ldadd) \
+ $(pel_test_utils_ldadd) \
+ $(FMT_LIBS) \
+ $(top_builddir)/extensions/openpower-pels/extended_user_data.o
+extended_user_data_test_LDFLAGS = $(test_ldflags)
diff --git a/test/openpower-pels/extended_user_data_test.cpp b/test/openpower-pels/extended_user_data_test.cpp
new file mode 100644
index 0000000..902cee6
--- /dev/null
+++ b/test/openpower-pels/extended_user_data_test.cpp
@@ -0,0 +1,139 @@
+/**
+ * Copyright © 2019 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "extensions/openpower-pels/extended_user_data.hpp"
+#include "pel_utils.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace openpower::pels;
+
+TEST(ExtUserDataTest, UnflattenFlattenTest)
+{
+ auto eudSectionData = pelDataFactory(TestPELType::extendedUserDataSection);
+ Stream stream(eudSectionData);
+ ExtendedUserData eud(stream);
+
+ EXPECT_TRUE(eud.valid());
+ EXPECT_EQ(eud.header().id, 0x4544);
+ EXPECT_EQ(eud.header().size, eudSectionData.size());
+ EXPECT_EQ(eud.header().version, 0x01);
+ EXPECT_EQ(eud.header().subType, 0x02);
+ EXPECT_EQ(eud.header().componentID, 0x2000);
+ EXPECT_EQ(eud.creatorID(), 'O');
+
+ const auto& data = eud.data();
+
+ // The eudSectionData itself starts 4B after the 8B header
+ EXPECT_EQ(data.size(), eudSectionData.size() - 12);
+
+ for (size_t i = 0; i < data.size(); i++)
+ {
+ EXPECT_EQ(data[i], eudSectionData[i + 12]);
+ }
+
+ // Now flatten
+ std::vector<uint8_t> newData;
+ Stream newStream(newData);
+ eud.flatten(newStream);
+
+ EXPECT_EQ(eudSectionData, newData);
+}
+
+TEST(ExtUserDataTest, BadDataTest)
+{
+ auto data = pelDataFactory(TestPELType::extendedUserDataSection);
+ data.resize(8); // Too small
+
+ Stream stream(data);
+ ExtendedUserData eud(stream);
+ EXPECT_FALSE(eud.valid());
+}
+
+TEST(ExtUserDataTest, BadSizeFieldTest)
+{
+ auto data = pelDataFactory(TestPELType::extendedUserDataSection);
+
+ {
+ data[3] = 0xFF; // Set the size field too large
+ Stream stream(data);
+ ExtendedUserData eud(stream);
+ EXPECT_FALSE(eud.valid());
+ }
+ {
+ data[3] = 0x7; // Set the size field too small
+ Stream stream(data);
+ ExtendedUserData eud(stream);
+ EXPECT_FALSE(eud.valid());
+ }
+}
+
+TEST(ExtUserDataTest, ConstructorTest)
+{
+ std::vector<uint8_t> data{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
+
+ ExtendedUserData eud{0x1112, 0x42, 0x01, 'B', data};
+
+ EXPECT_TRUE(eud.valid());
+ EXPECT_EQ(eud.header().id, 0x4544);
+ EXPECT_EQ(eud.header().size, 20);
+ EXPECT_EQ(eud.header().subType, 0x42);
+ EXPECT_EQ(eud.header().version, 0x01);
+ EXPECT_EQ(eud.header().componentID, 0x1112);
+ EXPECT_EQ(eud.flattenedSize(), 20);
+ EXPECT_EQ(eud.creatorID(), 'B');
+
+ const auto& d = eud.data();
+
+ EXPECT_EQ(d, data);
+}
+
+TEST(ExtUserDataTest, ShrinkTest)
+{
+ std::vector<uint8_t> data(100, 0xFF);
+
+ ExtendedUserData eud(0x1112, 0x42, 0x01, 'O', data);
+ EXPECT_TRUE(eud.valid());
+
+ // 4B aligned
+ EXPECT_TRUE(eud.shrink(88));
+ EXPECT_EQ(eud.flattenedSize(), 88);
+ EXPECT_EQ(eud.header().size, 88);
+
+ // rounded off
+ EXPECT_TRUE(eud.shrink(87));
+ EXPECT_EQ(eud.flattenedSize(), 84);
+ EXPECT_EQ(eud.header().size, 84);
+
+ // too big
+ EXPECT_FALSE(eud.shrink(200));
+ EXPECT_EQ(eud.flattenedSize(), 84);
+ EXPECT_EQ(eud.header().size, 84);
+
+ // way too small
+ EXPECT_FALSE(eud.shrink(3));
+ EXPECT_EQ(eud.flattenedSize(), 84);
+ EXPECT_EQ(eud.header().size, 84);
+
+ // the smallest it can go
+ EXPECT_TRUE(eud.shrink(16));
+ EXPECT_EQ(eud.flattenedSize(), 16);
+ EXPECT_EQ(eud.header().size, 16);
+
+ // one too small
+ EXPECT_FALSE(eud.shrink(15));
+ EXPECT_EQ(eud.flattenedSize(), 16);
+ EXPECT_EQ(eud.header().size, 16);
+}
diff --git a/test/openpower-pels/pel_utils.cpp b/test/openpower-pels/pel_utils.cpp
index a42b0b9..b596d34 100644
--- a/test/openpower-pels/pel_utils.cpp
+++ b/test/openpower-pels/pel_utils.cpp
@@ -145,6 +145,14 @@
0x04, 0x04, 0x04, 0x04, // MRU ID 3
};
+const std::vector<uint8_t> extendedUserDataSection{
+ // Header
+ 0x45, 0x44, 0x00, 0x18, 0x01, 0x02, 0x20, 0x00,
+
+ // Creator ID 'O', and then data
+ 0x4F, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x05, 0x0A, 0x0B, 0x0C};
+
constexpr size_t sectionCountOffset = 27;
constexpr size_t createTimestampPHOffset = 8;
constexpr size_t commitTimestampPHOffset = 16;
@@ -174,7 +182,9 @@
UserDataSection.end());
data.insert(data.end(), ExtUserHeaderSection.begin(),
ExtUserHeaderSection.end());
- data.at(sectionCountOffset) = 6;
+ data.insert(data.end(), extendedUserDataSection.begin(),
+ extendedUserDataSection.end());
+ data.at(sectionCountOffset) = 7;
break;
case TestPELType::privateHeaderSection:
data.insert(data.end(), privateHeaderSection.begin(),
@@ -220,6 +230,9 @@
case TestPELType::failingMTMSSection:
data.insert(data.end(), failingMTMSSection.begin(),
failingMTMSSection.end());
+ case TestPELType::extendedUserDataSection:
+ data.insert(data.end(), extendedUserDataSection.begin(),
+ extendedUserDataSection.end());
}
return data;
}
diff --git a/test/openpower-pels/pel_utils.hpp b/test/openpower-pels/pel_utils.hpp
index 1c4eebb..da38fa9 100644
--- a/test/openpower-pels/pel_utils.hpp
+++ b/test/openpower-pels/pel_utils.hpp
@@ -59,7 +59,8 @@
userHeaderSection,
primarySRCSection,
primarySRCSection2Callouts,
- failingMTMSSection
+ failingMTMSSection,
+ extendedUserDataSection
};
/**