1 #include "config.h"
2
3 #include "bmc_epoch.hpp"
4 #include "manager.hpp"
5 #include "types.hpp"
6
7 #include <sdbusplus/bus.hpp>
8
9 #include <gtest/gtest.h>
10
11 namespace phosphor
12 {
13 namespace time
14 {
15
16 class TestBmcEpoch : public testing::Test
17 {
18 public:
19 sdbusplus::bus_t bus;
20 Manager manager;
21 sd_event* event = nullptr;
22 std::unique_ptr<BmcEpoch> bmcEpoch;
23
TestBmcEpoch()24 TestBmcEpoch() : bus(sdbusplus::bus::new_default()), manager(bus)
25 {
26 // BmcEpoch requires sd_event to init
27 sd_event_default(&event);
28 bus.attach_event(event, SD_EVENT_PRIORITY_NORMAL);
29 bmcEpoch = std::make_unique<BmcEpoch>(bus, objpathBmc, manager);
30 }
31
~TestBmcEpoch()32 ~TestBmcEpoch() override
33 {
34 bus.detach_event();
35 sd_event_unref(event);
36 }
37 TestBmcEpoch(const TestBmcEpoch&) = delete;
38 TestBmcEpoch(TestBmcEpoch&&) = delete;
39 TestBmcEpoch& operator=(const TestBmcEpoch&) = delete;
40 TestBmcEpoch& operator=(TestBmcEpoch&&) = delete;
41 };
42
TEST_F(TestBmcEpoch,onModeChange)43 TEST_F(TestBmcEpoch, onModeChange)
44 {
45 bmcEpoch->onModeChanged(Mode::NTP);
46 EXPECT_EQ(Mode::NTP, manager.getTimeMode());
47
48 bmcEpoch->onModeChanged(Mode::Manual);
49 EXPECT_EQ(Mode::Manual, manager.getTimeMode());
50 }
51
TEST_F(TestBmcEpoch,empty)52 TEST_F(TestBmcEpoch, empty)
53 {
54 // Default mode is MANUAL
55 EXPECT_EQ(Mode::Manual, manager.getTimeMode());
56 }
57
TEST_F(TestBmcEpoch,getElapsed)58 TEST_F(TestBmcEpoch, getElapsed)
59 {
60 auto t1 = bmcEpoch->elapsed();
61 EXPECT_NE(0, t1);
62 auto t2 = bmcEpoch->elapsed();
63 EXPECT_GE(t2, t1);
64 }
65
TEST_F(TestBmcEpoch,setElapsedOK)66 TEST_F(TestBmcEpoch, setElapsedOK)
67 {
68 // TODO: setting time will call sd-bus functions and it will fail on host
69 // if we have gmock for sdbusplus::bus, we can test setElapsed.
70 // But for now we can not test it
71 }
72
73 } // namespace time
74 } // namespace phosphor
75