Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "inspur_oem.hpp" |
| 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 | |
| 33 | class TestInspurIpmiOem : public ::testing::Test |
| 34 | { |
| 35 | public: |
| 36 | TestInspurIpmiOem() : |
| 37 | mockedUtils( |
| 38 | reinterpret_cast<const utils::MockedUtils&>(utils::getUtils())) |
| 39 | {} |
| 40 | virtual ~TestInspurIpmiOem() |
| 41 | { |
| 42 | utils::freeUtils(); |
| 43 | clearMockedBus(); |
| 44 | } |
| 45 | |
| 46 | sdbusplus::bus::bus& mockedBus = getBus(); |
| 47 | const utils::MockedUtils& mockedUtils; |
| 48 | }; |
| 49 | |
| 50 | TEST_F(TestInspurIpmiOem, Empty) |
| 51 | { |
| 52 | // Empty |
| 53 | } |
| 54 | |
| 55 | TEST_F(TestInspurIpmiOem, parseBIOSInfoEmpty) |
| 56 | { |
| 57 | |
| 58 | EXPECT_CALL(mockedUtils, setPropertyImpl(_, _, _, _, _, _)).Times(0); |
| 59 | ipmi::parseBIOSInfo({}); |
| 60 | } |
| 61 | |
| 62 | TEST_F(TestInspurIpmiOem, parseBIOSInfoValidBIOSVersion) |
| 63 | { |
| 64 | |
| 65 | std::vector<uint8_t> data{ |
| 66 | 0x00, 0x30, 0x31, 0x2e, 0x30, 0x31, 0x2e, 0x30, 0x31, 0x2e, |
| 67 | 0x30, 0x31, 0x2e, 0x30, 0x31, 0x00, 0x30, 0x38, 0x2f, 0x31, |
| 68 | 0x31, 0x2f, 0x32, 0x30, 0x32, 0x30, 0x20, 0x32, 0x30, 0x3a, |
| 69 | 0x31, 0x39, 0x3a, 0x33, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 70 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 71 | |
| 72 | std::string dummyService = "com.test.bios.version"; |
| 73 | std::string expectedVersion = "01.01.01.01.01"; |
| 74 | EXPECT_CALL(mockedUtils, |
| 75 | getService(_, StrEq(BIOS_OBJPATH), StrEq(VERSION_IFACE))) |
| 76 | .WillOnce(Return(dummyService)); |
| 77 | EXPECT_CALL( |
| 78 | mockedUtils, |
| 79 | setPropertyImpl(_, StrEq(dummyService), StrEq(BIOS_OBJPATH), |
| 80 | StrEq(VERSION_IFACE), StrEq(VERSION), |
| 81 | VariantWith<std::string>(StrEq(expectedVersion)))) |
| 82 | .Times(1); |
| 83 | ipmi::parseBIOSInfo(data); |
| 84 | } |