summaryrefslogtreecommitdiffstats
path: root/test/TestHostEpoch.cpp
diff options
context:
space:
mode:
authorGunnar Mills <gmills@us.ibm.com>2018-09-14 14:42:39 -0500
committerLei YU <mine260309@gmail.com>2018-10-08 06:07:30 +0000
commitab4cc6a5585436a29b120429abaa48b416f8edb7 (patch)
treee1e153150cb1aff1656359f4d03c4536d47e1fe0 /test/TestHostEpoch.cpp
parent19b37ee2205ff4e772d344fe8a5fcfee2aa0d8ec (diff)
downloadphosphor-time-manager-ab4cc6a5585436a29b120429abaa48b416f8edb7.tar.gz
phosphor-time-manager-ab4cc6a5585436a29b120429abaa48b416f8edb7.zip
clang-format: Update to match docs repo
Update the .clang-format file and run clang-format-6.0. This .clang-format matches the example one in https://github.com/openbmc/docs/blob/master/cpp-style-and-conventions.md#clang-formatting Change-Id: Ic2c462525eb27b8295c2b298871e04268d93faf2 Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Diffstat (limited to 'test/TestHostEpoch.cpp')
-rw-r--r--test/TestHostEpoch.cpp255
1 files changed, 127 insertions, 128 deletions
diff --git a/test/TestHostEpoch.cpp b/test/TestHostEpoch.cpp
index 1004dad..7ddf92f 100644
--- a/test/TestHostEpoch.cpp
+++ b/test/TestHostEpoch.cpp
@@ -1,14 +1,14 @@
-#include "host_epoch.hpp"
-#include "utils.hpp"
#include "config.h"
+
+#include "host_epoch.hpp"
#include "types.hpp"
+#include "utils.hpp"
+#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Time/error.hpp>
-#include <sdbusplus/bus.hpp>
#include <gtest/gtest.h>
-
namespace phosphor
{
namespace time
@@ -16,129 +16,128 @@ namespace time
using namespace std::chrono;
using namespace std::chrono_literals;
-using NotAllowed =
- sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
+using NotAllowed = sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
const constexpr microseconds USEC_ZERO{0};
class TestHostEpoch : public testing::Test
{
- public:
- sdbusplus::bus::bus bus;
- HostEpoch hostEpoch;
-
- static constexpr auto FILE_NOT_EXIST = "path/to/file-not-exist";
- static constexpr auto FILE_OFFSET = "saved_host_offset";
- const microseconds delta = 2s;
-
- TestHostEpoch()
- : bus(sdbusplus::bus::new_default()),
- hostEpoch(bus, OBJPATH_HOST)
- {
- // Make sure the file does not exist
- std::remove(FILE_NOT_EXIST);
- }
- ~TestHostEpoch()
- {
- // Cleanup test file
- std::remove(FILE_OFFSET);
- }
-
- // Proxies for HostEpoch's private members and functions
- Mode getTimeMode()
- {
- return hostEpoch.timeMode;
- }
- Owner getTimeOwner()
- {
- return hostEpoch.timeOwner;
- }
- microseconds getOffset()
- {
- return hostEpoch.offset;
- }
- void setOffset(microseconds us)
- {
- hostEpoch.offset = us;
- }
- void setTimeOwner(Owner owner)
- {
- hostEpoch.onOwnerChanged(owner);
- }
- void setTimeMode(Mode mode)
- {
- hostEpoch.onModeChanged(mode);
- }
-
- void checkSettingTimeNotAllowed()
- {
- // By default offset shall be 0
- EXPECT_EQ(0, getOffset().count());
-
- // Set time is not allowed,
- // so verify offset is still 0 after set time
- microseconds diff = 1min;
- EXPECT_THROW(
- hostEpoch.elapsed(hostEpoch.elapsed() + diff.count()),
- NotAllowed);
- EXPECT_EQ(0, getOffset().count());
- }
-
- void checkSetSplitTimeInFuture()
- {
- // Get current time, and set future +1min time
- auto t1 = hostEpoch.elapsed();
- EXPECT_NE(0, t1);
- microseconds diff = 1min;
- auto t2 = t1 + diff.count();
- hostEpoch.elapsed(t2);
-
- // Verify that the offset shall be positive,
- // and less or equal to diff, and shall be not too less.
- auto offset = getOffset();
- EXPECT_GT(offset, USEC_ZERO);
- EXPECT_LE(offset, diff);
- diff -= delta;
- EXPECT_GE(offset, diff);
-
- // Now get time shall be around future +1min time
- auto epochNow = duration_cast<microseconds>(
- system_clock::now().time_since_epoch()).count();
- auto elapsedGot = hostEpoch.elapsed();
- EXPECT_LT(epochNow, elapsedGot);
- auto epochDiff = elapsedGot - epochNow;
- diff = 1min;
- EXPECT_GT(epochDiff, (diff - delta).count());
- EXPECT_LT(epochDiff, (diff + delta).count());
- }
- void checkSetSplitTimeInPast()
- {
- // Get current time, and set past -1min time
- auto t1 = hostEpoch.elapsed();
- EXPECT_NE(0, t1);
- microseconds diff = 1min;
- auto t2 = t1 - diff.count();
- hostEpoch.elapsed(t2);
-
- // Verify that the offset shall be negative, and the absolute value
- // shall be equal or greater than diff, and shall not be too greater
- auto offset = getOffset();
- EXPECT_LT(offset, USEC_ZERO);
- offset = -offset;
- EXPECT_GE(offset, diff);
- diff += 10s;
- EXPECT_LE(offset, diff);
-
- // Now get time shall be around past -1min time
- auto epochNow = duration_cast<microseconds>(
- system_clock::now().time_since_epoch()).count();
- auto elapsedGot = hostEpoch.elapsed();
- EXPECT_LT(elapsedGot, epochNow);
- auto epochDiff = epochNow - elapsedGot;
- diff = 1min;
- EXPECT_GT(epochDiff, (diff - delta).count());
- EXPECT_LT(epochDiff, (diff + delta).count());
- }
+ public:
+ sdbusplus::bus::bus bus;
+ HostEpoch hostEpoch;
+
+ static constexpr auto FILE_NOT_EXIST = "path/to/file-not-exist";
+ static constexpr auto FILE_OFFSET = "saved_host_offset";
+ const microseconds delta = 2s;
+
+ TestHostEpoch() :
+ bus(sdbusplus::bus::new_default()), hostEpoch(bus, OBJPATH_HOST)
+ {
+ // Make sure the file does not exist
+ std::remove(FILE_NOT_EXIST);
+ }
+ ~TestHostEpoch()
+ {
+ // Cleanup test file
+ std::remove(FILE_OFFSET);
+ }
+
+ // Proxies for HostEpoch's private members and functions
+ Mode getTimeMode()
+ {
+ return hostEpoch.timeMode;
+ }
+ Owner getTimeOwner()
+ {
+ return hostEpoch.timeOwner;
+ }
+ microseconds getOffset()
+ {
+ return hostEpoch.offset;
+ }
+ void setOffset(microseconds us)
+ {
+ hostEpoch.offset = us;
+ }
+ void setTimeOwner(Owner owner)
+ {
+ hostEpoch.onOwnerChanged(owner);
+ }
+ void setTimeMode(Mode mode)
+ {
+ hostEpoch.onModeChanged(mode);
+ }
+
+ void checkSettingTimeNotAllowed()
+ {
+ // By default offset shall be 0
+ EXPECT_EQ(0, getOffset().count());
+
+ // Set time is not allowed,
+ // so verify offset is still 0 after set time
+ microseconds diff = 1min;
+ EXPECT_THROW(hostEpoch.elapsed(hostEpoch.elapsed() + diff.count()),
+ NotAllowed);
+ EXPECT_EQ(0, getOffset().count());
+ }
+
+ void checkSetSplitTimeInFuture()
+ {
+ // Get current time, and set future +1min time
+ auto t1 = hostEpoch.elapsed();
+ EXPECT_NE(0, t1);
+ microseconds diff = 1min;
+ auto t2 = t1 + diff.count();
+ hostEpoch.elapsed(t2);
+
+ // Verify that the offset shall be positive,
+ // and less or equal to diff, and shall be not too less.
+ auto offset = getOffset();
+ EXPECT_GT(offset, USEC_ZERO);
+ EXPECT_LE(offset, diff);
+ diff -= delta;
+ EXPECT_GE(offset, diff);
+
+ // Now get time shall be around future +1min time
+ auto epochNow =
+ duration_cast<microseconds>(system_clock::now().time_since_epoch())
+ .count();
+ auto elapsedGot = hostEpoch.elapsed();
+ EXPECT_LT(epochNow, elapsedGot);
+ auto epochDiff = elapsedGot - epochNow;
+ diff = 1min;
+ EXPECT_GT(epochDiff, (diff - delta).count());
+ EXPECT_LT(epochDiff, (diff + delta).count());
+ }
+ void checkSetSplitTimeInPast()
+ {
+ // Get current time, and set past -1min time
+ auto t1 = hostEpoch.elapsed();
+ EXPECT_NE(0, t1);
+ microseconds diff = 1min;
+ auto t2 = t1 - diff.count();
+ hostEpoch.elapsed(t2);
+
+ // Verify that the offset shall be negative, and the absolute value
+ // shall be equal or greater than diff, and shall not be too greater
+ auto offset = getOffset();
+ EXPECT_LT(offset, USEC_ZERO);
+ offset = -offset;
+ EXPECT_GE(offset, diff);
+ diff += 10s;
+ EXPECT_LE(offset, diff);
+
+ // Now get time shall be around past -1min time
+ auto epochNow =
+ duration_cast<microseconds>(system_clock::now().time_since_epoch())
+ .count();
+ auto elapsedGot = hostEpoch.elapsed();
+ EXPECT_LT(elapsedGot, epochNow);
+ auto epochDiff = epochNow - elapsedGot;
+ diff = 1min;
+ EXPECT_GT(epochDiff, (diff - delta).count());
+ EXPECT_LT(epochDiff, (diff + delta).count());
+ }
};
TEST_F(TestHostEpoch, empty)
@@ -160,13 +159,13 @@ TEST_F(TestHostEpoch, writeAndReadData)
{
// Write offset to file
microseconds offsetToWrite(1234567);
- utils::writeData<decltype(offsetToWrite)::rep>(
- FILE_OFFSET, offsetToWrite.count());
+ utils::writeData<decltype(offsetToWrite)::rep>(FILE_OFFSET,
+ offsetToWrite.count());
// Read it back
microseconds offsetToRead;
- offsetToRead = microseconds(
- utils::readData<decltype(offsetToRead)::rep>(FILE_OFFSET));
+ offsetToRead =
+ microseconds(utils::readData<decltype(offsetToRead)::rep>(FILE_OFFSET));
EXPECT_EQ(offsetToWrite, offsetToRead);
}
@@ -295,5 +294,5 @@ TEST_F(TestHostEpoch, clearOffsetOnOwnerChange)
EXPECT_EQ(USEC_ZERO, getOffset());
}
-}
-}
+} // namespace time
+} // namespace phosphor
OpenPOWER on IntegriCloud