Pavithra Barithaya | 0fc6abe | 2024-07-31 13:51:02 +0530 | [diff] [blame] | 1 | #include "bios_attribute.hpp" |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 2 | #include "libpldmresponder/bios_table.hpp" |
| 3 | |
| 4 | #include <gmock/gmock.h> |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | using testing::ElementsAreArray; |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 8 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 9 | class MockBIOSStringTable : public pldm::responder::bios::BIOSStringTable |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 10 | { |
| 11 | public: |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 12 | MockBIOSStringTable() : BIOSStringTable({}) {} |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 13 | |
| 14 | MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override)); |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 15 | |
| 16 | MOCK_METHOD(std::string, findString, (const uint16_t), (const override)); |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 17 | }; |
| 18 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 19 | void checkHeader(const pldm::responder::bios::Table& attrEntry, |
| 20 | const pldm::responder::bios::Table& attrValueEntry) |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 21 | { |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 22 | auto attrHeader = pldm::responder::bios::table::attribute::decodeHeader( |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 23 | reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data())); |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 24 | auto attrValueHeader = |
| 25 | pldm::responder::bios::table::attribute_value::decodeHeader( |
| 26 | reinterpret_cast<const pldm_bios_attr_val_table_entry*>( |
| 27 | attrValueEntry.data())); |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 28 | |
| 29 | EXPECT_EQ(attrHeader.attrHandle, attrValueHeader.attrHandle); |
| 30 | } |
| 31 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 32 | void checkEntry(pldm::responder::bios::Table& entry, |
| 33 | pldm::responder::bios::Table& expectedEntry) |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 34 | { |
| 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 Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 50 | void 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 Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 54 | { |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 55 | pldm::responder::bios::Table attrEntry, attrValueEntry; |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 56 | attribute.constructEntry(stringTable, attrEntry, attrValueEntry); |
| 57 | |
| 58 | checkHeader(attrEntry, attrValueEntry); |
| 59 | checkEntry(attrEntry, expectedAttrEntry); |
| 60 | checkEntry(attrValueEntry, expectedAttrValueEntry); |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 61 | } |