diff options
| author | Lei YU <mine260309@gmail.com> | 2017-01-20 14:05:46 +0800 |
|---|---|---|
| committer | Lei YU <mine260309@gmail.com> | 2017-08-01 10:31:07 +0800 |
| commit | 962328277259ce12115fa6bf7ae31f43f1951dd0 (patch) | |
| tree | 6c23ed91355444f687caa49368d26f9b7a4c17e5 | |
| parent | 2f9c0cc25478709f25f449d46ab9836152cf1cd9 (diff) | |
| download | phosphor-time-manager-962328277259ce12115fa6bf7ae31f43f1951dd0.tar.gz phosphor-time-manager-962328277259ce12115fa6bf7ae31f43f1951dd0.zip | |
Implement part of BmcEpoch
Add BmcEpoch which inherits EpochBase and will handle times for BMC,
it is partly implemented.
Add unit test cases to test basic functions.
Change-Id: Ia5e4d0f884156d238f3f84df490a2efbce43e89a
Signed-off-by: Lei YU <mine260309@gmail.com>
| -rw-r--r-- | Makefile.am | 3 | ||||
| -rw-r--r-- | bmc_epoch.cpp | 50 | ||||
| -rw-r--r-- | bmc_epoch.hpp | 39 | ||||
| -rw-r--r-- | main.cpp | 2 | ||||
| -rw-r--r-- | test/Makefile.am | 3 | ||||
| -rw-r--r-- | test/TestBmcEpoch.cpp | 55 |
6 files changed, 150 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am index 4b4cf02..3eef41a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,8 @@ sbin_PROGRAMS = phosphor-timemanager noinst_LTLIBRARIES = libtimemanager.la libtimemanager_la_SOURCES = \ - epoch_base.cpp + epoch_base.cpp \ + bmc_epoch.cpp phosphor_timemanager_SOURCES = \ main.cpp diff --git a/bmc_epoch.cpp b/bmc_epoch.cpp new file mode 100644 index 0000000..c17ddf5 --- /dev/null +++ b/bmc_epoch.cpp @@ -0,0 +1,50 @@ +#include "bmc_epoch.hpp" + +#include <phosphor-logging/log.hpp> + +namespace phosphor +{ +namespace time +{ +namespace server = sdbusplus::xyz::openbmc_project::Time::server; +using namespace phosphor::logging; + +BmcEpoch::BmcEpoch(sdbusplus::bus::bus& bus, + const char* objPath) + : EpochBase(bus, objPath) +{ + // Empty +} + +uint64_t BmcEpoch::elapsed() const +{ + // It does not needs to check owner when getting time + return getTime().count(); +} + +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) + { + 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; + } + server::EpochTime::elapsed(value); + return value; +} + +} +} + diff --git a/bmc_epoch.hpp b/bmc_epoch.hpp new file mode 100644 index 0000000..56d78e9 --- /dev/null +++ b/bmc_epoch.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "epoch_base.hpp" + +namespace phosphor +{ +namespace time +{ + +/** @class BmcEpoch + * @brief OpenBMC BMC EpochTime implementation. + * @details A concrete implementation for xyz.openbmc_project.Time.EpochTime + * DBus API for BMC's epoch time. + */ +class BmcEpoch : public EpochBase +{ + public: + friend class TestBmcEpoch; + BmcEpoch(sdbusplus::bus::bus& bus, + const char* objPath); + + /** + * @brief Get value of Elapsed property + * + * @return The elapsed microseconds since UTC + **/ + uint64_t elapsed() const override; + + /** + * @brief Set value of Elapsed property + * + * @param[in] value - The microseconds since UTC to set + * @return The updated elapsed microseconds since UTC + **/ + uint64_t elapsed(uint64_t value) override; +}; + +} +} @@ -1,10 +1,12 @@ #include <sdbusplus/bus.hpp> #include "config.h" +#include "bmc_epoch.hpp" int main() { auto bus = sdbusplus::bus::new_default(); + phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC); bus.request_name(BUSNAME); diff --git a/test/Makefile.am b/test/Makefile.am index 66e1ae5..26c4c15 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -6,7 +6,8 @@ TESTS = $(check_PROGRAMS) check_PROGRAMS += test test_SOURCES = \ - TestEpochBase.cpp + TestEpochBase.cpp \ + TestBmcEpoch.cpp test_LDADD = $(top_builddir)/libtimemanager.la diff --git a/test/TestBmcEpoch.cpp b/test/TestBmcEpoch.cpp new file mode 100644 index 0000000..67f89bb --- /dev/null +++ b/test/TestBmcEpoch.cpp @@ -0,0 +1,55 @@ +#include <sdbusplus/bus.hpp> +#include <gtest/gtest.h> + +#include "bmc_epoch.hpp" +#include "config.h" + +namespace phosphor +{ +namespace time +{ + +class TestBmcEpoch : public testing::Test +{ + public: + using Mode = EpochBase::Mode; + using Owner = EpochBase::Owner; + + sdbusplus::bus::bus bus; + BmcEpoch bmcEpoch; + + TestBmcEpoch() + : bus(sdbusplus::bus::new_default()), + bmcEpoch(bus, OBJPATH_BMC) + { + // Empty + } + + // Proxies for BmcEpoch's private members and functions + Mode getTimeMode() + { + return bmcEpoch.timeMode; + } + Owner getTimeOwner() + { + return bmcEpoch.timeOwner; + } +}; + +TEST_F(TestBmcEpoch, empty) +{ + EXPECT_EQ(Mode::NTP, getTimeMode()); + EXPECT_EQ(Owner::BMC, getTimeOwner()); +} + +TEST_F(TestBmcEpoch, getElapsed) +{ + auto t1 = bmcEpoch.elapsed(); + EXPECT_NE(0, t1); + auto t2 = bmcEpoch.elapsed(); + EXPECT_GE(t2, t1); +} + + +} +} |

