blob: bdaf5f041a3b7be06234b6f8cfd48e203c63e88b [file] [log] [blame]
Lei YUebd3d092020-09-27 18:11:48 +08001#include "config.h"
2
George Liua3a9d2a2024-04-03 09:30:45 +08003#include "iei_oem.hpp"
Lei YUebd3d092020-09-27 18:11:48 +08004#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
13using ::testing::_;
14using ::testing::Invoke;
15using ::testing::IsNull;
16using ::testing::Return;
17using ::testing::StrEq;
18using ::testing::VariantWith;
19
20namespace ipmi
21{
22
23void parseBIOSInfo(const std::vector<uint8_t>& data);
24
25}
26
27void 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 Liua3a9d2a2024-04-03 09:30:45 +080033class TestIpmiOem : public ::testing::Test
Lei YUebd3d092020-09-27 18:11:48 +080034{
35 public:
George Liua3a9d2a2024-04-03 09:30:45 +080036 TestIpmiOem() :
Lei YUebd3d092020-09-27 18:11:48 +080037 mockedUtils(
38 reinterpret_cast<const utils::MockedUtils&>(utils::getUtils()))
39 {}
George Liua3a9d2a2024-04-03 09:30:45 +080040 virtual ~TestIpmiOem()
Lei YUebd3d092020-09-27 18:11:48 +080041 {
42 utils::freeUtils();
43 clearMockedBus();
44 }
45
46 sdbusplus::bus::bus& mockedBus = getBus();
47 const utils::MockedUtils& mockedUtils;
48};
49
George Liua3a9d2a2024-04-03 09:30:45 +080050TEST_F(TestIpmiOem, Empty)
Lei YUebd3d092020-09-27 18:11:48 +080051{
52 // Empty
53}
54
George Liua3a9d2a2024-04-03 09:30:45 +080055TEST_F(TestIpmiOem, parseBIOSInfoEmpty)
Lei YUebd3d092020-09-27 18:11:48 +080056{
Lei YUebd3d092020-09-27 18:11:48 +080057 EXPECT_CALL(mockedUtils, setPropertyImpl(_, _, _, _, _, _)).Times(0);
58 ipmi::parseBIOSInfo({});
59}
60
George Liua3a9d2a2024-04-03 09:30:45 +080061TEST_F(TestIpmiOem, parseBIOSInfoValidBIOSVersion)
Lei YUebd3d092020-09-27 18:11:48 +080062{
Lei YUebd3d092020-09-27 18:11:48 +080063 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}