Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
George Liu | a3a9d2a | 2024-04-03 09:30:45 +0800 | [diff] [blame] | 3 | #include "iei_oem.hpp" |
Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 4 | #include "mocked_sdbus.hpp" |
| 5 | #include "mocked_utils.hpp" |
| 6 | #include "sdbus_wrapper.hpp" |
| 7 | |
| 8 | #include <ipmid/api.h> |
| 9 | |
| 10 | #include <gmock/gmock.h> |
| 11 | #include <gtest/gtest.h> |
| 12 | |
| 13 | using ::testing::_; |
| 14 | using ::testing::Invoke; |
| 15 | using ::testing::IsNull; |
| 16 | using ::testing::Return; |
| 17 | using ::testing::StrEq; |
| 18 | using ::testing::VariantWith; |
| 19 | |
| 20 | namespace ipmi |
| 21 | { |
| 22 | |
| 23 | void parseBIOSInfo(const std::vector<uint8_t>& data); |
| 24 | |
| 25 | } |
| 26 | |
| 27 | void ipmi_register_callback(ipmi_netfn_t, ipmi_cmd_t, ipmi_context_t, |
| 28 | ipmid_callback_t, ipmi_cmd_privilege_t) |
| 29 | { |
| 30 | // Empty |
| 31 | } |
| 32 | |
George Liu | a3a9d2a | 2024-04-03 09:30:45 +0800 | [diff] [blame] | 33 | class TestIpmiOem : public ::testing::Test |
Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 34 | { |
| 35 | public: |
George Liu | a3a9d2a | 2024-04-03 09:30:45 +0800 | [diff] [blame] | 36 | TestIpmiOem() : |
Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 37 | mockedUtils( |
| 38 | reinterpret_cast<const utils::MockedUtils&>(utils::getUtils())) |
| 39 | {} |
George Liu | a3a9d2a | 2024-04-03 09:30:45 +0800 | [diff] [blame] | 40 | virtual ~TestIpmiOem() |
Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 41 | { |
| 42 | utils::freeUtils(); |
| 43 | clearMockedBus(); |
| 44 | } |
| 45 | |
| 46 | sdbusplus::bus::bus& mockedBus = getBus(); |
| 47 | const utils::MockedUtils& mockedUtils; |
| 48 | }; |
| 49 | |
George Liu | a3a9d2a | 2024-04-03 09:30:45 +0800 | [diff] [blame] | 50 | TEST_F(TestIpmiOem, Empty) |
Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 51 | { |
| 52 | // Empty |
| 53 | } |
| 54 | |
George Liu | a3a9d2a | 2024-04-03 09:30:45 +0800 | [diff] [blame] | 55 | TEST_F(TestIpmiOem, parseBIOSInfoEmpty) |
Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 56 | { |
Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 57 | EXPECT_CALL(mockedUtils, setPropertyImpl(_, _, _, _, _, _)).Times(0); |
| 58 | ipmi::parseBIOSInfo({}); |
| 59 | } |
| 60 | |
George Liu | a3a9d2a | 2024-04-03 09:30:45 +0800 | [diff] [blame] | 61 | TEST_F(TestIpmiOem, parseBIOSInfoValidBIOSVersion) |
Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 62 | { |
Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 63 | std::vector<uint8_t> data{ |
| 64 | 0x00, 0x30, 0x31, 0x2e, 0x30, 0x31, 0x2e, 0x30, 0x31, 0x2e, |
| 65 | 0x30, 0x31, 0x2e, 0x30, 0x31, 0x00, 0x30, 0x38, 0x2f, 0x31, |
| 66 | 0x31, 0x2f, 0x32, 0x30, 0x32, 0x30, 0x20, 0x32, 0x30, 0x3a, |
| 67 | 0x31, 0x39, 0x3a, 0x33, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 69 | |
| 70 | std::string dummyService = "com.test.bios.version"; |
| 71 | std::string expectedVersion = "01.01.01.01.01"; |
| 72 | EXPECT_CALL(mockedUtils, |
| 73 | getService(_, StrEq(BIOS_OBJPATH), StrEq(VERSION_IFACE))) |
| 74 | .WillOnce(Return(dummyService)); |
| 75 | EXPECT_CALL( |
| 76 | mockedUtils, |
| 77 | setPropertyImpl(_, StrEq(dummyService), StrEq(BIOS_OBJPATH), |
| 78 | StrEq(VERSION_IFACE), StrEq(VERSION), |
| 79 | VariantWith<std::string>(StrEq(expectedVersion)))) |
| 80 | .Times(1); |
| 81 | ipmi::parseBIOSInfo(data); |
| 82 | } |