blob: f5f660ed39627cc9d0407453b701150235443b9c [file] [log] [blame]
Pavithra Barithaya0fc6abe2024-07-31 13:51:02 +05301#include "bios_attribute.hpp"
John Wang29683b52020-02-27 16:41:44 +08002#include "libpldmresponder/bios_table.hpp"
3
4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
6
7using testing::ElementsAreArray;
John Wang29683b52020-02-27 16:41:44 +08008
Brad Bishop5079ac42021-08-19 18:35:06 -04009class MockBIOSStringTable : public pldm::responder::bios::BIOSStringTable
John Wang29683b52020-02-27 16:41:44 +080010{
11 public:
Patrick Williams6da4f912023-05-10 07:50:53 -050012 MockBIOSStringTable() : BIOSStringTable({}) {}
John Wang29683b52020-02-27 16:41:44 +080013
14 MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override));
John Wang3be70852020-02-13 15:59:04 +080015
16 MOCK_METHOD(std::string, findString, (const uint16_t), (const override));
John Wang29683b52020-02-27 16:41:44 +080017};
18
Brad Bishop5079ac42021-08-19 18:35:06 -040019void checkHeader(const pldm::responder::bios::Table& attrEntry,
20 const pldm::responder::bios::Table& attrValueEntry)
John Wang29683b52020-02-27 16:41:44 +080021{
Brad Bishop5079ac42021-08-19 18:35:06 -040022 auto attrHeader = pldm::responder::bios::table::attribute::decodeHeader(
John Wang29683b52020-02-27 16:41:44 +080023 reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data()));
Brad Bishop5079ac42021-08-19 18:35:06 -040024 auto attrValueHeader =
25 pldm::responder::bios::table::attribute_value::decodeHeader(
26 reinterpret_cast<const pldm_bios_attr_val_table_entry*>(
27 attrValueEntry.data()));
John Wang29683b52020-02-27 16:41:44 +080028
29 EXPECT_EQ(attrHeader.attrHandle, attrValueHeader.attrHandle);
30}
31
Brad Bishop5079ac42021-08-19 18:35:06 -040032void checkEntry(pldm::responder::bios::Table& entry,
33 pldm::responder::bios::Table& expectedEntry)
John Wang29683b52020-02-27 16:41:44 +080034{
35 /** backup the attr handle */
36 auto attr0 = entry[0], eAttr0 = expectedEntry[0];
37 auto attr1 = entry[1], eAttr1 = expectedEntry[1];
38
39 /** attr handle is computed by libpldm, set it to 0 to test */
40 entry[0] = 0, expectedEntry[0] = 0;
41 entry[1] = 0, expectedEntry[1] = 0;
42
43 EXPECT_THAT(entry, ElementsAreArray(expectedEntry));
44
45 /** restore the attr handle */
46 entry[0] = attr0, expectedEntry[0] = eAttr0;
47 entry[1] = attr1, expectedEntry[1] = eAttr1;
48}
49
Brad Bishop5079ac42021-08-19 18:35:06 -040050void checkConstructEntry(pldm::responder::bios::BIOSAttribute& attribute,
51 pldm::responder::bios::BIOSStringTable& stringTable,
52 pldm::responder::bios::Table& expectedAttrEntry,
53 pldm::responder::bios::Table& expectedAttrValueEntry)
John Wang29683b52020-02-27 16:41:44 +080054{
Brad Bishop5079ac42021-08-19 18:35:06 -040055 pldm::responder::bios::Table attrEntry, attrValueEntry;
John Wang29683b52020-02-27 16:41:44 +080056 attribute.constructEntry(stringTable, attrEntry, attrValueEntry);
57
58 checkHeader(attrEntry, attrValueEntry);
59 checkEntry(attrEntry, expectedAttrEntry);
60 checkEntry(attrValueEntry, expectedAttrValueEntry);
Patrick Williams6da4f912023-05-10 07:50:53 -050061}