sched-host-tran: handle with the scheduled time
Add the basic process to handle with the scheduled time
Tested:
1. Scheduled time is 0
# busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t 1
------
Feb 19 08:09:47 witherspoon phosphor-scheduled-host-transition[28263]: \
The function Scheduled Host Transition is disabled.
2. Scheduled time is the past
# busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t 1582100042
------
Failed to set property ScheduledTime on interface xyz.openbmc_project.State.\
ScheduledHostTransition: Scheduled time is in the past
Feb 19 08:14:42 witherspoon phosphor-scheduled-host-transition[28263]: \
Scheduled time is earlier than current time. Fail to do host transition.
Feb 19 08:14:42 witherspoon phosphor-scheduled-host-transition[28263]: \
Scheduled time is in the past
Change-Id: I0b6a98dcb6d0e70336bf42fc88a633abf3e64633
Signed-off-by: Carol Wang <wangkair@cn.ibm.com>
diff --git a/test/test_scheduled_host_transition.cpp b/test/test_scheduled_host_transition.cpp
new file mode 100644
index 0000000..f5ffa2c
--- /dev/null
+++ b/test/test_scheduled_host_transition.cpp
@@ -0,0 +1,54 @@
+#include "scheduled_host_transition.hpp"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/test/sdbus_mock.hpp>
+#include <xyz/openbmc_project/ScheduledTime/error.hpp>
+
+namespace phosphor
+{
+namespace state
+{
+namespace manager
+{
+
+using namespace std::chrono;
+using InvalidTimeError =
+ sdbusplus::xyz::openbmc_project::ScheduledTime::Error::InvalidTime;
+
+class TestScheduledHostTransition : public testing::Test
+{
+ public:
+ sdbusplus::SdBusMock sdbusMock;
+ sdbusplus::bus::bus mockedBus = sdbusplus::get_mocked_new(&sdbusMock);
+ ScheduledHostTransition scheduledHostTransition;
+
+ TestScheduledHostTransition() : scheduledHostTransition(mockedBus, "")
+ {
+ // Empty
+ }
+
+ seconds getCurrentTime()
+ {
+ return scheduledHostTransition.getTime();
+ }
+};
+
+TEST_F(TestScheduledHostTransition, disableHostTransition)
+{
+ EXPECT_EQ(scheduledHostTransition.scheduledTime(0), 0);
+}
+
+TEST_F(TestScheduledHostTransition, invalidScheduledTime)
+{
+ // scheduled time is 1 min earlier than current time
+ uint64_t schTime =
+ static_cast<uint64_t>((getCurrentTime() - seconds(60)).count());
+ EXPECT_THROW(scheduledHostTransition.scheduledTime(schTime),
+ InvalidTimeError);
+}
+
+} // namespace manager
+} // namespace state
+} // namespace phosphor