summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLei YU <mine260309@gmail.com>2017-02-23 15:15:51 +0800
committerLei YU <mine260309@gmail.com>2017-10-16 20:18:26 +0800
commit7f4fca554b250d40230d5735d1d0ddf9ac6af801 (patch)
treea66c3034e0c6666e45ce8063f4c0d5de64fad438 /test
parentc6fe8693f72bdc673c25838c4c8a8a39a6cdea8b (diff)
downloadphosphor-time-manager-7f4fca554b250d40230d5735d1d0ddf9ac6af801.tar.gz
phosphor-time-manager-7f4fca554b250d40230d5735d1d0ddf9ac6af801.zip
Save properties to persistent storage when host is on
1. When host is on, set properties as requested properties instead of notify listeners; 2. When host becomes off, and requested properties are not empty, notify the listners and reset the requested properties. Add unit tests. Change-Id: I9359c801c698df0c6e5eab43e12427bb5a6da611 Signed-off-by: Lei YU <mine260309@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/TestHostEpoch.cpp18
-rw-r--r--test/TestManager.cpp63
2 files changed, 68 insertions, 13 deletions
diff --git a/test/TestHostEpoch.cpp b/test/TestHostEpoch.cpp
index ec8ecf1..0ff8a11 100644
--- a/test/TestHostEpoch.cpp
+++ b/test/TestHostEpoch.cpp
@@ -2,6 +2,7 @@
#include <gtest/gtest.h>
#include "host_epoch.hpp"
+#include "utils.hpp"
#include "config.h"
#include "types.hpp"
@@ -45,16 +46,6 @@ class TestHostEpoch : public testing::Test
{
return hostEpoch.timeOwner;
}
- template <typename T>
- T readData(const char* fileName)
- {
- return HostEpoch::readData<T>(fileName);
- }
- template <typename T>
- void writeData(const char* fileName, T&& data)
- {
- HostEpoch::writeData<T>(fileName, std::forward<T>(data));
- }
microseconds getOffset()
{
return hostEpoch.offset;
@@ -75,7 +66,7 @@ TEST_F(TestHostEpoch, readDataFileNotExist)
{
// When file does not exist, the default offset shall be 0
microseconds offset(0);
- auto value = readData<decltype(offset)::rep>(FILE_NOT_EXIST);
+ auto value = utils::readData<decltype(offset)::rep>(FILE_NOT_EXIST);
EXPECT_EQ(0, value);
}
@@ -83,12 +74,13 @@ TEST_F(TestHostEpoch, writeAndReadData)
{
// Write offset to file
microseconds offsetToWrite(1234567);
- writeData<decltype(offsetToWrite)::rep>(FILE_OFFSET, offsetToWrite.count());
+ utils::writeData<decltype(offsetToWrite)::rep>(
+ FILE_OFFSET, offsetToWrite.count());
// Read it back
microseconds offsetToRead;
offsetToRead = microseconds(
- readData<decltype(offsetToRead)::rep>(FILE_OFFSET));
+ utils::readData<decltype(offsetToRead)::rep>(FILE_OFFSET));
EXPECT_EQ(offsetToWrite, offsetToRead);
}
diff --git a/test/TestManager.cpp b/test/TestManager.cpp
index 4d9ae73..935590e 100644
--- a/test/TestManager.cpp
+++ b/test/TestManager.cpp
@@ -39,10 +39,34 @@ class TestManager : public testing::Test
{
return Manager::convertToOwner(owner);
}
+ bool hostOn()
+ {
+ return manager.hostOn;
+ }
+ std::string getRequestedMode()
+ {
+ return manager.requestedMode;
+ }
+ std::string getRequestedOwner()
+ {
+ return manager.requestedOwner;
+ }
+ void notifyPropertyChanged(const std::string& key,
+ const std::string& value)
+ {
+ manager.onPropertyChanged(key, value);
+ }
+ void notifyPgoodChanged(bool pgood)
+ {
+ manager.onPgoodChanged(pgood);
+ }
};
TEST_F(TestManager, empty)
{
+ EXPECT_FALSE(hostOn());
+ EXPECT_EQ("", getRequestedMode());
+ EXPECT_EQ("", getRequestedOwner());
EXPECT_EQ(Mode::NTP, getTimeMode());
EXPECT_EQ(Owner::BMC, getTimeOwner());
}
@@ -72,5 +96,44 @@ TEST_F(TestManager, convertToOwner)
EXPECT_EQ(Owner::BMC, convertToOwner("xyz"));
}
+TEST_F(TestManager, pgoodChange)
+{
+ notifyPgoodChanged(true);
+ EXPECT_TRUE(hostOn());
+ notifyPgoodChanged(false);
+ EXPECT_FALSE(hostOn());
+}
+
+TEST_F(TestManager, propertyChange)
+{
+ // When host is off, property change will be notified to listners
+ EXPECT_FALSE(hostOn());
+ notifyPropertyChanged("time_mode", "MANUAL");
+ notifyPropertyChanged("time_owner", "HOST");
+ EXPECT_EQ("", getRequestedMode());
+ EXPECT_EQ("", getRequestedOwner());
+ // TODO: if gmock is ready, check mocked listners shall receive notifies
+
+ notifyPgoodChanged(true);
+ // When host is on, property changes are saved as requested ones
+ notifyPropertyChanged("time_mode", "MANUAL");
+ notifyPropertyChanged("time_owner", "HOST");
+ EXPECT_EQ("MANUAL", getRequestedMode());
+ EXPECT_EQ("HOST", getRequestedOwner());
+
+
+ // When host becomes off, the requested mode/owner shall be notified
+ // to listners, and be cleared
+ notifyPgoodChanged(false);
+ // TODO: if gmock is ready, check mocked listners shall receive notifies
+ EXPECT_EQ("", getRequestedMode());
+ EXPECT_EQ("", getRequestedOwner());
+
+ // When host is on, and invalid property is changed,
+ // verify the code asserts because it shall never occur
+ notifyPgoodChanged(true);
+ ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), "");
+}
+
}
}
OpenPOWER on IntegriCloud