summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLei YU <mine260309@gmail.com>2017-01-16 15:05:24 +0800
committerLei YU <mine260309@gmail.com>2017-08-01 10:31:07 +0800
commite7abcdc7bb9cc3b5e36d829aa777b2c544792d10 (patch)
treecfde92e169b094f78038d7f10106966c00fe0177
parentbef42ed1d0c7b22234cf2b7ca581e7b3280bf207 (diff)
downloadphosphor-time-manager-e7abcdc7bb9cc3b5e36d829aa777b2c544792d10.tar.gz
phosphor-time-manager-e7abcdc7bb9cc3b5e36d829aa777b2c544792d10.zip
Implement BmcEpoch set/get elapsed()
Getting elapsed returns BMC's time; Setting elapsed will check the current time mode/owner, and will return error when mode is NTP or owner is HOST. Add unit test cases. Change-Id: Ibf4e90957f3b26b68c4a1b6dc66dc364c66bef10 Signed-off-by: Lei YU <mine260309@gmail.com>
-rw-r--r--bmc_epoch.cpp29
-rw-r--r--test/TestBmcEpoch.cpp30
2 files changed, 44 insertions, 15 deletions
diff --git a/bmc_epoch.cpp b/bmc_epoch.cpp
index c17ddf5..5923e8e 100644
--- a/bmc_epoch.cpp
+++ b/bmc_epoch.cpp
@@ -24,23 +24,22 @@ uint64_t BmcEpoch::elapsed() const
uint64_t BmcEpoch::elapsed(uint64_t value)
{
- // TODO: set time based on current time mode and owner
- auto time = std::chrono::microseconds(value);
- switch (timeOwner)
+ if (timeMode == Mode::NTP)
+ {
+ log<level::ERR>("Setting BmcTime with NTP mode is not allowed");
+ // TODO: throw NotAllowed exception
+ return 0;
+ }
+ if (timeOwner == Owner::HOST)
{
- case Owner::BMC:
- {
- setTime(time);
- break;
- }
- // TODO: below cases are to be implemented
- case Owner::HOST:
- break;
- case Owner::SPLIT:
- break;
- case Owner::BOTH:
- break;
+ log<level::ERR>("Setting BmcTime with HOST owner is not allowed");
+ // TODO: throw NotAllowed exception
+ return 0;
}
+
+ auto time = std::chrono::microseconds(value);
+ setTime(time);
+
server::EpochTime::elapsed(value);
return value;
}
diff --git a/test/TestBmcEpoch.cpp b/test/TestBmcEpoch.cpp
index 67f89bb..da65b3e 100644
--- a/test/TestBmcEpoch.cpp
+++ b/test/TestBmcEpoch.cpp
@@ -9,6 +9,7 @@ namespace phosphor
namespace time
{
+using namespace std::chrono;
class TestBmcEpoch : public testing::Test
{
public:
@@ -34,6 +35,14 @@ class TestBmcEpoch : public testing::Test
{
return bmcEpoch.timeOwner;
}
+ void setTimeOwner(Owner owner)
+ {
+ bmcEpoch.timeOwner = owner;
+ }
+ void setTimeMode(Mode mode)
+ {
+ bmcEpoch.timeMode = mode;
+ }
};
TEST_F(TestBmcEpoch, empty)
@@ -50,6 +59,27 @@ TEST_F(TestBmcEpoch, getElapsed)
EXPECT_GE(t2, t1);
}
+TEST_F(TestBmcEpoch, setElapsedNotAllowed)
+{
+ auto epochNow = duration_cast<microseconds>(
+ system_clock::now().time_since_epoch()).count();
+ // In NTP mode, setting time is not allowed
+ auto ret = bmcEpoch.elapsed(epochNow);
+ EXPECT_EQ(0, ret);
+
+ // In Host owner, setting time is not allowed
+ setTimeMode(Mode::MANUAL);
+ setTimeOwner(Owner::HOST);
+ ret = bmcEpoch.elapsed(epochNow);
+ EXPECT_EQ(0, ret);
+}
+
+TEST_F(TestBmcEpoch, setElapsedOK)
+{
+ // TODO: setting time will call sd-bus functions and it will fail on host
+ // if we have gmock for sdbusplus::bus, we can test setElapsed.
+ // But for now we can not test it
+}
}
}
OpenPOWER on IntegriCloud