Throw excpetion when it is not allowed to set time
When it is not allowed to set time depending on the time setting,
previously we only log an error and continue.
Now sdbusplus supports errors on properties, so we can throw exception
on such case.
Tested: Verify in unittest that exception is thrown when it is not
allowed to set time.
Verify in BMC that busctl gets the error message when it is not
allowed to set time.
Change-Id: I4a04d1aa8c081abf0f9fd449118dc1107e12f689
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/test/TestHostEpoch.cpp b/test/TestHostEpoch.cpp
index a492b9a..6c460ad 100644
--- a/test/TestHostEpoch.cpp
+++ b/test/TestHostEpoch.cpp
@@ -1,11 +1,14 @@
-#include <sdbusplus/bus.hpp>
-#include <gtest/gtest.h>
-
#include "host_epoch.hpp"
#include "utils.hpp"
#include "config.h"
#include "types.hpp"
+#include <xyz/openbmc_project/Common/error.hpp>
+
+#include <sdbusplus/bus.hpp>
+#include <gtest/gtest.h>
+
+
namespace phosphor
{
namespace time
@@ -13,6 +16,8 @@
using namespace std::chrono;
using namespace std::chrono_literals;
+using InsufficientPermission =
+ sdbusplus::xyz::openbmc_project::Common::Error::InsufficientPermission;
const constexpr microseconds USEC_ZERO{0};
@@ -73,9 +78,10 @@
// Set time is not allowed,
// so verify offset is still 0 after set time
microseconds diff = 1min;
- hostEpoch.elapsed(hostEpoch.elapsed() + diff.count());
+ EXPECT_THROW(
+ hostEpoch.elapsed(hostEpoch.elapsed() + diff.count()),
+ InsufficientPermission);
EXPECT_EQ(0, getOffset().count());
- // TODO: when gmock is ready, check there is no call to timedatectl
}
void checkSetSplitTimeInFuture()