Add APIs to store/load BIOS tables
This commit implements C++ APIs to store a PLDM BIOS table into
persistent storage, and to load the same back into memory. This commit
also defines C structs representing the different BIOS tables.
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Change-Id: I4a771a368c6931464f45ae4a8f467b579c7a5d74
diff --git a/test/Makefile.am b/test/Makefile.am
index fef5f96..1ab21e7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,7 +8,8 @@
libpldmresponder_base_test \
libpldm_bios_test \
libpldmresponder_bios_test \
- libpldmresponder_pdr_state_effecter_test
+ libpldmresponder_pdr_state_effecter_test \
+ libpldmresponder_bios_table_test
if OEM_IBM
check_PROGRAMS += \
@@ -130,3 +131,21 @@
$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
-lstdc++fs
libpldmresponder_pdr_state_effecter_test_SOURCES = libpldmresponder_pdr_state_effecter_test.cpp
+
+libpldmresponder_bios_table_test_CPPFLAGS = $(test_cppflags)
+libpldmresponder_bios_table_test_CXXFLAGS = $(test_cxxflags)
+libpldmresponder_bios_table_test_LDFLAGS = \
+ $(test_ldflags) \
+ $(SDBUSPLUS_LIBS)
+libpldmresponder_bios_table_test_LDADD = \
+ $(top_builddir)/libpldmresponder/libpldmresponder_la-bios.o \
+ $(top_builddir)/libpldmresponder/libpldmresponder_la-bios_table.o \
+ $(top_builddir)/libpldmresponder/libpldmresponder_la-utils.o \
+ $(top_builddir)/libpldm/libpldm_la-base.o \
+ $(top_builddir)/libpldm/libpldm_la-bios.o \
+ $(top_builddir)/pldmd-registration.o \
+ $(CODE_COVERAGE_LIBS) \
+ $(SDBUSPLUS_LIBS) \
+ -lstdc++fs
+libpldmresponder_bios_table_test_SOURCES = \
+ libpldmresponder_bios_table_test.cpp
diff --git a/test/libpldmresponder_bios_table_test.cpp b/test/libpldmresponder_bios_table_test.cpp
new file mode 100644
index 0000000..47764ee
--- /dev/null
+++ b/test/libpldmresponder_bios_table_test.cpp
@@ -0,0 +1,61 @@
+#include "libpldmresponder/bios_table.hpp"
+
+#include <stdlib.h>
+
+#include <algorithm>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+using namespace pldm::responder::bios;
+
+class TestBIOSTable : public testing::Test
+{
+ public:
+ void SetUp() override
+ {
+ char tmpdir[] = "/tmp/pldm_bios_table.XXXXXX";
+ dir = fs::path(mkdtemp(tmpdir));
+ }
+
+ void TearDown() override
+ {
+ fs::remove_all(dir);
+ }
+
+ fs::path dir;
+};
+
+TEST_F(TestBIOSTable, testStoreLoad)
+{
+ std::vector<uint8_t> table{10, 34, 56, 100, 44, 55, 69, 21, 48, 2, 7, 82};
+ fs::path file(dir / "t1");
+ BIOSTable t(file.string().c_str());
+ std::vector<uint8_t> out{};
+
+ ASSERT_THROW(t.load(out), fs::filesystem_error);
+
+ ASSERT_EQ(true, t.isEmpty());
+
+ t.store(table);
+ t.load(out);
+ ASSERT_EQ(true, std::equal(table.begin(), table.end(), out.begin()));
+}
+
+TEST_F(TestBIOSTable, testLoadOntoExisting)
+{
+ std::vector<uint8_t> table{10, 34, 56, 100, 44, 55, 69, 21, 48, 2, 7, 82};
+ fs::path file(dir / "t1");
+ BIOSTable t(file.string().c_str());
+ std::vector<uint8_t> out{99, 99};
+
+ ASSERT_THROW(t.load(out), fs::filesystem_error);
+
+ ASSERT_EQ(true, t.isEmpty());
+
+ t.store(table);
+ t.load(out);
+ ASSERT_EQ(true, std::equal(table.begin(), table.end(), out.begin() + 2));
+ ASSERT_EQ(out[0], 99);
+ ASSERT_EQ(out[1], 99);
+}