Added discrete threshold trigger support
Implemented discrete threshold logic
Discrete trigger with empty threshold array is handled as 'onChange'
Added unit tests coverage for discrete trigger
Supported scenarios:
-discrete threshold with value and dwell time
-discrete threshold with value, without dwell time
-discrete trigger without threshold ('onChange')
Tests:
-Unit tests passed
Change-Id: Id60a48f4113bd955d97e154888c00d1b6e5490af
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
diff --git a/tests/meson.build b/tests/meson.build
index 5be01be..d2e5aac 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -11,8 +11,10 @@
executable(
'telemetry-ut',
[
+ '../src/discrete_threshold.cpp',
'../src/metric.cpp',
'../src/numeric_threshold.cpp',
+ '../src/on_change_threshold.cpp',
'../src/persistent_json_storage.cpp',
'../src/report.cpp',
'../src/report_factory.cpp',
@@ -28,8 +30,10 @@
'src/stubs/dbus_sensor_object.cpp',
'src/test_conversion.cpp',
'src/test_detached_timer.cpp',
+ 'src/test_discrete_threshold.cpp',
'src/test_metric.cpp',
'src/test_numeric_threshold.cpp',
+ 'src/test_on_change_threshold.cpp',
'src/test_persistent_json_storage.cpp',
'src/test_report.cpp',
'src/test_report_manager.cpp',
diff --git a/tests/src/dbus_environment.cpp b/tests/src/dbus_environment.cpp
index 4780cc5..9e025d7 100644
--- a/tests/src/dbus_environment.cpp
+++ b/tests/src/dbus_environment.cpp
@@ -72,6 +72,17 @@
return waitForFuture(getFuture(name), timeout);
}
+bool DbusEnvironment::waitForFutures(std::string_view name,
+ std::chrono::milliseconds timeout)
+{
+ auto& data = futures[std::string(name)];
+ auto ret = waitForFutures(
+ std::move(data), true, [](auto sum, auto val) { return sum && val; },
+ timeout);
+ data = std::vector<std::future<bool>>{};
+ return ret;
+}
+
std::future<bool> DbusEnvironment::getFuture(std::string_view name)
{
auto& data = futures[std::string(name)];
diff --git a/tests/src/dbus_environment.hpp b/tests/src/dbus_environment.hpp
index 07c4368..8146bcb 100644
--- a/tests/src/dbus_environment.hpp
+++ b/tests/src/dbus_environment.hpp
@@ -1,3 +1,5 @@
+#pragma once
+
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/asio/property.hpp>
@@ -36,35 +38,61 @@
synchronizeIoc();
}
- template <class T>
- static T waitForFuture(
- std::future<T> future,
+ template <class T, class F>
+ static T waitForFutures(
+ std::vector<std::future<T>> futures, T init, F&& accumulator,
std::chrono::milliseconds timeout = std::chrono::seconds(10))
{
constexpr auto precission = std::chrono::milliseconds(10);
auto elapsed = std::chrono::milliseconds(0);
- while (future.valid() && elapsed < timeout)
+ auto sum = init;
+ for (auto& future : futures)
{
- synchronizeIoc();
+ while (future.valid() && elapsed < timeout)
+ {
+ synchronizeIoc();
- if (future.wait_for(precission) == std::future_status::ready)
- {
- return future.get();
- }
- else
- {
- elapsed += precission;
+ if (future.wait_for(precission) == std::future_status::ready)
+ {
+ sum = accumulator(sum, future.get());
+ }
+ else
+ {
+ elapsed += precission;
+ }
}
}
- throw std::runtime_error("Timed out while waiting for future");
+ if (elapsed >= timeout)
+ {
+ throw std::runtime_error("Timed out while waiting for future");
+ }
+
+ return sum;
+ }
+
+ template <class T>
+ static T waitForFuture(
+ std::future<T> future,
+ std::chrono::milliseconds timeout = std::chrono::seconds(10))
+ {
+ std::vector<std::future<T>> futures;
+ futures.emplace_back(std::move(future));
+
+ return waitForFutures(
+ std::move(futures), T{},
+ [](auto, const auto& value) { return value; }, timeout);
}
static bool waitForFuture(
std::string_view name,
std::chrono::milliseconds timeout = std::chrono::seconds(10));
+ static bool waitForFutures(
+ std::string_view name,
+ std::chrono::milliseconds timeout = std::chrono::seconds(10));
+
private:
static std::future<bool> getFuture(std::string_view name);
diff --git a/tests/src/params/trigger_params.hpp b/tests/src/params/trigger_params.hpp
index 6d34d3b..95b19d2 100644
--- a/tests/src/params/trigger_params.hpp
+++ b/tests/src/params/trigger_params.hpp
@@ -21,6 +21,12 @@
return nameProperty;
}
+ TriggerParams& isDiscrete(bool val)
+ {
+ discreteProperty = val;
+ return *this;
+ }
+
bool isDiscrete() const
{
return discreteProperty;
@@ -52,6 +58,12 @@
return reportNamesProperty;
}
+ TriggerParams& thresholdParams(TriggerThresholdParams val)
+ {
+ thresholdsProperty = std::move(val);
+ return *this;
+ }
+
const TriggerThresholdParams& thresholdParams() const
{
return thresholdsProperty;
diff --git a/tests/src/test_discrete_threshold.cpp b/tests/src/test_discrete_threshold.cpp
new file mode 100644
index 0000000..2b31767
--- /dev/null
+++ b/tests/src/test_discrete_threshold.cpp
@@ -0,0 +1,271 @@
+#include "dbus_environment.hpp"
+#include "discrete_threshold.hpp"
+#include "helpers.hpp"
+#include "mocks/sensor_mock.hpp"
+#include "mocks/trigger_action_mock.hpp"
+#include "utils/conv_container.hpp"
+
+#include <gmock/gmock.h>
+
+using namespace testing;
+using namespace std::chrono_literals;
+
+class TestDiscreteThreshold : public Test
+{
+ public:
+ std::vector<std::shared_ptr<SensorMock>> sensorMocks = {
+ std::make_shared<NiceMock<SensorMock>>(),
+ std::make_shared<NiceMock<SensorMock>>()};
+ std::vector<std::string> sensorNames = {"Sensor1", "Sensor2"};
+ std::unique_ptr<TriggerActionMock> actionMockPtr =
+ std::make_unique<StrictMock<TriggerActionMock>>();
+ TriggerActionMock& actionMock = *actionMockPtr;
+ std::shared_ptr<DiscreteThreshold> sut;
+
+ std::shared_ptr<DiscreteThreshold>
+ makeThreshold(std::chrono::milliseconds dwellTime,
+ double thresholdValue)
+ {
+ std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
+ actions.push_back(std::move(actionMockPtr));
+
+ return std::make_shared<DiscreteThreshold>(
+ DbusEnvironment::getIoc(),
+ utils::convContainer<std::shared_ptr<interfaces::Sensor>>(
+ sensorMocks),
+ sensorNames, std::move(actions), dwellTime, thresholdValue,
+ "treshold_name");
+ }
+
+ void SetUp() override
+ {
+ sut = makeThreshold(0ms, 90.0);
+ }
+};
+
+TEST_F(TestDiscreteThreshold, initializeThresholdExpectAllSensorsAreRegistered)
+{
+ for (auto& sensor : sensorMocks)
+ {
+ EXPECT_CALL(*sensor,
+ registerForUpdates(Truly([sut = sut.get()](const auto& x) {
+ return x.lock().get() == sut;
+ })));
+ }
+
+ sut->initialize();
+}
+
+TEST_F(TestDiscreteThreshold, thresholdIsNotInitializeExpectNoActionCommit)
+{
+ EXPECT_CALL(actionMock, commit(_, _, _)).Times(0);
+}
+
+struct DiscreteParams
+{
+ struct UpdateParams
+ {
+ size_t sensor;
+ uint64_t timestamp;
+ double value;
+ std::chrono::milliseconds sleepAfter;
+
+ UpdateParams(size_t sensor, uint64_t timestamp, double value,
+ std::chrono::milliseconds sleepAfter = 0ms) :
+ sensor(sensor),
+ timestamp(timestamp), value(value), sleepAfter(sleepAfter)
+ {}
+ };
+
+ struct ExpectedParams
+ {
+ size_t sensor;
+ uint64_t timestamp;
+ double value;
+ std::chrono::milliseconds waitMin;
+
+ ExpectedParams(size_t sensor, uint64_t timestamp, double value,
+ std::chrono::milliseconds waitMin = 0ms) :
+ sensor(sensor),
+ timestamp(timestamp), value(value), waitMin(waitMin)
+ {}
+ };
+
+ DiscreteParams& Updates(std::vector<UpdateParams> val)
+ {
+ updates = std::move(val);
+ return *this;
+ }
+
+ DiscreteParams& Expected(std::vector<ExpectedParams> val)
+ {
+ expected = std::move(val);
+ return *this;
+ }
+
+ DiscreteParams& ThresholdValue(double val)
+ {
+ thresholdValue = val;
+ return *this;
+ }
+
+ DiscreteParams& DwellTime(std::chrono::milliseconds val)
+ {
+ dwellTime = std::move(val);
+ return *this;
+ }
+
+ friend void PrintTo(const DiscreteParams& o, std::ostream* os)
+ {
+ *os << "{ DwellTime: " << o.dwellTime.count() << "ms ";
+ *os << ", ThresholdValue: " << o.thresholdValue;
+ *os << ", Updates: ";
+ for (const auto& [index, timestamp, value, sleepAfter] : o.updates)
+ {
+ *os << "{ SensorIndex: " << index << ", Timestamp: " << timestamp
+ << ", Value: " << value
+ << ", SleepAfter: " << sleepAfter.count() << "ms }, ";
+ }
+ *os << "Expected: ";
+ for (const auto& [index, timestamp, value, waitMin] : o.expected)
+ {
+ *os << "{ SensorIndex: " << index << ", Timestamp: " << timestamp
+ << ", Value: " << value << ", waitMin: " << waitMin.count()
+ << "ms }, ";
+ }
+ *os << " }";
+ }
+
+ std::vector<UpdateParams> updates;
+ std::vector<ExpectedParams> expected;
+ double thresholdValue = 0.0;
+ std::chrono::milliseconds dwellTime = 0ms;
+};
+
+class TestDiscreteThresholdCommon :
+ public TestDiscreteThreshold,
+ public WithParamInterface<DiscreteParams>
+{
+ public:
+ void sleep(std::chrono::milliseconds duration)
+ {
+ if (duration != 0ms)
+ {
+ DbusEnvironment::sleepFor(duration);
+ }
+ }
+
+ void testBodySensorIsUpdatedMultipleTimes()
+ {
+ std::vector<std::chrono::time_point<std::chrono::high_resolution_clock>>
+ timestamps(sensorMocks.size());
+
+ sut->initialize();
+
+ InSequence seq;
+
+ for (const auto& [index, timestamp, value, waitMin] :
+ GetParam().expected)
+ {
+ EXPECT_CALL(actionMock,
+ commit(sensorNames[index], timestamp, value))
+ .WillOnce(DoAll(
+ InvokeWithoutArgs([idx = index, ×tamps] {
+ timestamps[idx] =
+ std::chrono::high_resolution_clock::now();
+ }),
+ InvokeWithoutArgs(DbusEnvironment::setPromise("commit"))));
+ }
+
+ auto start = std::chrono::high_resolution_clock::now();
+
+ for (const auto& [index, timestamp, value, sleepAfter] :
+ GetParam().updates)
+ {
+ sut->sensorUpdated(*sensorMocks[index], timestamp, value);
+ sleep(sleepAfter);
+ }
+
+ EXPECT_THAT(DbusEnvironment::waitForFutures("commit"), true);
+ for (const auto& [index, timestamp, value, waitMin] :
+ GetParam().expected)
+ {
+ EXPECT_THAT(timestamps[index] - start, Ge(waitMin));
+ }
+ }
+};
+
+class TestDiscreteThresholdNoDwellTime : public TestDiscreteThresholdCommon
+{
+ public:
+ void SetUp() override
+ {
+ sut = makeThreshold(0ms, GetParam().thresholdValue);
+ }
+};
+
+INSTANTIATE_TEST_SUITE_P(
+ _, TestDiscreteThresholdNoDwellTime,
+ Values(
+ DiscreteParams()
+ .ThresholdValue(90.0)
+ .Updates({{0, 1, 80.0}, {0, 2, 89.0}})
+ .Expected({}),
+ DiscreteParams()
+ .ThresholdValue(90.0)
+ .Updates({{0, 1, 80.0}, {0, 2, 90.0}, {0, 3, 80.0}, {0, 4, 90.0}})
+ .Expected({{0, 2, 90.0}, {0, 4, 90.0}}),
+ DiscreteParams()
+ .ThresholdValue(90.0)
+ .Updates({{0, 1, 90.0}, {0, 2, 99.0}, {1, 3, 100.0}, {1, 4, 90.0}})
+ .Expected({{0, 1, 90.0}, {1, 4, 90.0}})));
+
+TEST_P(TestDiscreteThresholdNoDwellTime, senorsIsUpdatedMultipleTimes)
+{
+ testBodySensorIsUpdatedMultipleTimes();
+}
+
+class TestDiscreteThresholdWithDwellTime : public TestDiscreteThresholdCommon
+{
+ public:
+ void SetUp() override
+ {
+ sut = makeThreshold(GetParam().dwellTime, GetParam().thresholdValue);
+ }
+};
+
+INSTANTIATE_TEST_SUITE_P(
+ _, TestDiscreteThresholdWithDwellTime,
+ Values(DiscreteParams()
+ .DwellTime(200ms)
+ .ThresholdValue(90.0)
+ .Updates({{0, 1, 90.0, 100ms}, {0, 2, 91.0}, {0, 3, 90.0}})
+ .Expected({{0, 3, 90.0, 300ms}}),
+ DiscreteParams()
+ .DwellTime(100ms)
+ .ThresholdValue(90.0)
+ .Updates({{0, 1, 90.0, 100ms}})
+ .Expected({{0, 1, 90.0, 100ms}}),
+ DiscreteParams()
+ .DwellTime(1000ms)
+ .ThresholdValue(90.0)
+ .Updates({{0, 1, 90.0, 700ms},
+ {0, 1, 91.0, 100ms},
+ {0, 1, 90.0, 300ms},
+ {0, 1, 91.0, 100ms}})
+ .Expected({}),
+ DiscreteParams()
+ .DwellTime(200ms)
+ .ThresholdValue(90.0)
+ .Updates({{0, 1, 90.0},
+ {1, 2, 89.0, 100ms},
+ {1, 3, 90.0, 100ms},
+ {1, 4, 89.0, 100ms},
+ {1, 5, 90.0, 300ms},
+ {1, 6, 89.0, 100ms}})
+ .Expected({{0, 1, 90, 200ms}, {1, 5, 90, 500ms}})));
+
+TEST_P(TestDiscreteThresholdWithDwellTime, senorsIsUpdatedMultipleTimes)
+{
+ testBodySensorIsUpdatedMultipleTimes();
+}
diff --git a/tests/src/test_on_change_threshold.cpp b/tests/src/test_on_change_threshold.cpp
new file mode 100644
index 0000000..20819c5
--- /dev/null
+++ b/tests/src/test_on_change_threshold.cpp
@@ -0,0 +1,129 @@
+#include "dbus_environment.hpp"
+#include "helpers.hpp"
+#include "mocks/sensor_mock.hpp"
+#include "mocks/trigger_action_mock.hpp"
+#include "on_change_threshold.hpp"
+#include "utils/conv_container.hpp"
+
+#include <gmock/gmock.h>
+
+using namespace testing;
+using namespace std::chrono_literals;
+
+class TestOnChangeThreshold : public Test
+{
+ public:
+ std::vector<std::shared_ptr<SensorMock>> sensorMocks = {
+ std::make_shared<NiceMock<SensorMock>>(),
+ std::make_shared<NiceMock<SensorMock>>()};
+ std::vector<std::string> sensorNames = {"Sensor1", "Sensor2"};
+ std::unique_ptr<TriggerActionMock> actionMockPtr =
+ std::make_unique<StrictMock<TriggerActionMock>>();
+ TriggerActionMock& actionMock = *actionMockPtr;
+ std::shared_ptr<OnChangeThreshold> sut;
+
+ void SetUp() override
+ {
+ std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
+ actions.push_back(std::move(actionMockPtr));
+
+ sut = std::make_shared<OnChangeThreshold>(
+ utils::convContainer<std::shared_ptr<interfaces::Sensor>>(
+ sensorMocks),
+ sensorNames, std::move(actions));
+ }
+};
+
+TEST_F(TestOnChangeThreshold, initializeThresholdExpectAllSensorsAreRegistered)
+{
+ for (auto& sensor : sensorMocks)
+ {
+ EXPECT_CALL(*sensor,
+ registerForUpdates(Truly([sut = sut.get()](const auto& x) {
+ return x.lock().get() == sut;
+ })));
+ }
+
+ sut->initialize();
+}
+
+TEST_F(TestOnChangeThreshold, thresholdIsNotInitializeExpectNoActionCommit)
+{
+ EXPECT_CALL(actionMock, commit(_, _, _)).Times(0);
+}
+
+struct OnChangeParams
+{
+ using UpdateParams = std::tuple<size_t, uint64_t, double>;
+ using ExpectedParams = std::tuple<size_t, uint64_t, double>;
+
+ OnChangeParams& Updates(std::vector<UpdateParams> val)
+ {
+ updates = std::move(val);
+ return *this;
+ }
+
+ OnChangeParams& Expected(std::vector<ExpectedParams> val)
+ {
+ expected = std::move(val);
+ return *this;
+ }
+
+ friend void PrintTo(const OnChangeParams& o, std::ostream* os)
+ {
+ *os << "{ Updates: ";
+ for (const auto& [index, timestamp, value] : o.updates)
+ {
+ *os << "{ SensorIndex: " << index << ", Timestamp: " << timestamp
+ << ", Value: " << value << " }, ";
+ }
+ *os << "Expected: ";
+ for (const auto& [index, timestamp, value] : o.expected)
+ {
+ *os << "{ SensorIndex: " << index << ", Timestamp: " << timestamp
+ << ", Value: " << value << " }, ";
+ }
+ *os << " }";
+ }
+
+ std::vector<UpdateParams> updates;
+ std::vector<ExpectedParams> expected;
+};
+
+class TestOnChangeThresholdUpdates :
+ public TestOnChangeThreshold,
+ public WithParamInterface<OnChangeParams>
+{};
+
+INSTANTIATE_TEST_SUITE_P(
+ _, TestOnChangeThresholdUpdates,
+ Values(
+ OnChangeParams().Updates({{0, 1, 80.0}}).Expected({{0, 1, 80.0}}),
+ OnChangeParams()
+ .Updates({{0, 1, 80.0}, {1, 2, 81.0}})
+ .Expected({{0, 1, 80.0}, {1, 2, 81.0}}),
+ OnChangeParams()
+ .Updates({{0, 1, 80.0}, {0, 2, 90.0}})
+ .Expected({{0, 1, 80.0}, {0, 2, 90.0}}),
+ OnChangeParams()
+ .Updates({{0, 1, 80.0}, {1, 2, 90.0}, {0, 3, 90.0}})
+ .Expected({{0, 1, 80.0}, {1, 2, 90.0}, {0, 3, 90.0}}),
+ OnChangeParams()
+ .Updates({{0, 1, 80.0}, {1, 2, 80.0}, {1, 3, 90.0}, {0, 4, 90.0}})
+ .Expected(
+ {{0, 1, 80.0}, {1, 2, 80.0}, {1, 3, 90.0}, {0, 4, 90.0}})));
+
+TEST_P(TestOnChangeThresholdUpdates, senorsIsUpdatedMultipleTimes)
+{
+ InSequence seq;
+ for (const auto& [index, timestamp, value] : GetParam().expected)
+ {
+ EXPECT_CALL(actionMock, commit(sensorNames[index], timestamp, value));
+ }
+
+ sut->initialize();
+ for (const auto& [index, timestamp, value] : GetParam().updates)
+ {
+ sut->sensorUpdated(*sensorMocks[index], timestamp, value);
+ }
+}
diff --git a/tests/src/test_trigger_actions.cpp b/tests/src/test_trigger_actions.cpp
index 2fa220a..7a65fa2 100644
--- a/tests/src/test_trigger_actions.cpp
+++ b/tests/src/test_trigger_actions.cpp
@@ -7,85 +7,212 @@
namespace action
{
+namespace numeric
+{
+using LogParam = std::tuple<::numeric::Type, double, double>;
-using LogParam = std::pair<numeric::Type, double>;
+static auto getCorrectParams()
+{
+ return Values(std::make_tuple(::numeric::Type::upperCritical, 91.1, 90),
+ std::make_tuple(::numeric::Type::lowerCritical, 91.2, 90),
+ std::make_tuple(::numeric::Type::upperWarning, 88.5, 90),
+ std::make_tuple(::numeric::Type::lowerWarning, 88.6, 90));
+}
-class TestLogToJournal : public Test, public WithParamInterface<LogParam>
+static auto getIncorrectParams()
+{
+ return Values(
+ std::make_tuple(::numeric::Type::upperCritical, 90.0, 90),
+ std::make_tuple(static_cast<::numeric::Type>(-1), 88.0, 90),
+ std::make_tuple(static_cast<::numeric::Type>(123), 123.0, 90));
+}
+
+class TestLogToJournalNumeric : public Test, public WithParamInterface<LogParam>
{
public:
void SetUp() override
{
- auto [type, threshold] = GetParam();
- sut = std::make_unique<LogToJournal>(type, threshold);
+ auto [type, threshold, value] = GetParam();
+ sut = std::make_unique<numeric::LogToJournal>(type, threshold);
+ commmitValue = value;
+ }
+
+ std::unique_ptr<numeric::LogToJournal> sut;
+ double commmitValue;
+};
+
+INSTANTIATE_TEST_SUITE_P(LogToJournalNumericParams, TestLogToJournalNumeric,
+ getCorrectParams());
+
+TEST_P(TestLogToJournalNumeric, commitAnActionDoesNotThrow)
+{
+ EXPECT_NO_THROW(sut->commit("Test", 100'000, commmitValue));
+}
+
+class TestLogToJournalNumericThrow : public TestLogToJournalNumeric
+{};
+
+INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalNumericThrow, getIncorrectParams());
+
+TEST_P(TestLogToJournalNumericThrow, commitAnActionExpectThrow)
+{
+ EXPECT_THROW(sut->commit("Test", 100'000, commmitValue),
+ std::runtime_error);
+}
+
+class TestLogToRedfishNumeric : public Test, public WithParamInterface<LogParam>
+{
+ public:
+ void SetUp() override
+ {
+ auto [type, threshold, value] = GetParam();
+ sut = std::make_unique<LogToRedfish>(type, threshold);
+ commmitValue = value;
+ }
+
+ std::unique_ptr<LogToRedfish> sut;
+ double commmitValue;
+};
+
+INSTANTIATE_TEST_SUITE_P(LogToRedfishNumericParams, TestLogToRedfishNumeric,
+ getCorrectParams());
+
+TEST_P(TestLogToRedfishNumeric, commitExpectNoThrow)
+{
+ EXPECT_NO_THROW(sut->commit("Test", 100'000, commmitValue));
+}
+
+class TestLogToRedfishNumericThrow : public TestLogToRedfishNumeric
+{};
+
+INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishNumericThrow, getIncorrectParams());
+
+TEST_P(TestLogToRedfishNumericThrow, commitExpectToThrow)
+{
+ EXPECT_THROW(sut->commit("Test", 100'000, commmitValue),
+ std::runtime_error);
+}
+
+} // namespace numeric
+
+namespace discrete
+{
+using LogParam = ::discrete::Severity;
+
+static auto getCorrectParams()
+{
+ return Values(::discrete::Severity::critical, ::discrete::Severity::warning,
+ ::discrete::Severity::ok);
+}
+
+static auto getIncorrectParams()
+{
+ return Values(static_cast<::discrete::Severity>(-1),
+ static_cast<::discrete::Severity>(42));
+}
+
+class TestLogToJournalDiscrete :
+ public Test,
+ public WithParamInterface<LogParam>
+{
+ public:
+ void SetUp() override
+ {
+ auto severity = GetParam();
+ sut = std::make_unique<LogToJournal>(severity);
}
std::unique_ptr<LogToJournal> sut;
};
-INSTANTIATE_TEST_SUITE_P(
- LogToJournalParams, TestLogToJournal,
- Values(std::make_pair(numeric::Type::upperCritical, 91.1),
- std::make_pair(numeric::Type::lowerCritical, 91.2),
- std::make_pair(numeric::Type::upperWarning, 88.5),
- std::make_pair(numeric::Type::lowerWarning, 88.6)));
+INSTANTIATE_TEST_SUITE_P(LogToJournalDiscreteParams, TestLogToJournalDiscrete,
+ getCorrectParams());
-TEST_P(TestLogToJournal, commitAnActionDoesNotThrow)
+TEST_P(TestLogToJournalDiscrete, commitAnActionDoesNotThrow)
{
EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
}
-class TestLogToJournalThrow : public TestLogToJournal
+class TestLogToJournalDiscreteThrow : public TestLogToJournalDiscrete
{};
-INSTANTIATE_TEST_SUITE_P(
- _, TestLogToJournalThrow,
- Values(std::make_pair(numeric::Type::upperCritical, 90.0),
- std::make_pair(static_cast<numeric::Type>(-1), 88.0),
- std::make_pair(static_cast<numeric::Type>(123), 123.0)));
+INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalDiscreteThrow,
+ getIncorrectParams());
-TEST_P(TestLogToJournalThrow, commitAnActionExpectThrow)
+TEST_P(TestLogToJournalDiscreteThrow, commitAnActionExpectThrow)
{
EXPECT_THROW(sut->commit("Test", 100'000, 90.0), std::runtime_error);
}
-class TestLogToRedfish : public Test, public WithParamInterface<LogParam>
+class TestLogToRedfishDiscrete :
+ public Test,
+ public WithParamInterface<LogParam>
{
public:
void SetUp() override
{
- auto [type, threshold] = GetParam();
- sut = std::make_unique<LogToRedfish>(type, threshold);
+ auto severity = GetParam();
+ sut = std::make_unique<LogToRedfish>(severity);
}
std::unique_ptr<LogToRedfish> sut;
};
-INSTANTIATE_TEST_SUITE_P(
- LogToRedfishParams, TestLogToRedfish,
- Values(std::make_pair(numeric::Type::upperCritical, 91.1),
- std::make_pair(numeric::Type::lowerCritical, 91.4),
- std::make_pair(numeric::Type::upperWarning, 88.6),
- std::make_pair(numeric::Type::lowerWarning, 88.5)));
+INSTANTIATE_TEST_SUITE_P(LogToRedfishDiscreteParams, TestLogToRedfishDiscrete,
+ getCorrectParams());
-TEST_P(TestLogToRedfish, commitExpectNoThrow)
+TEST_P(TestLogToRedfishDiscrete, commitExpectNoThrow)
{
EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
}
-class TestLogToRedfishThrow : public TestLogToRedfish
+class TestLogToRedfishDiscreteThrow : public TestLogToRedfishDiscrete
{};
-INSTANTIATE_TEST_SUITE_P(
- _, TestLogToRedfishThrow,
- Values(std::make_pair(numeric::Type::upperCritical, 90.0),
- std::make_pair(static_cast<numeric::Type>(-1), 88.5),
- std::make_pair(static_cast<numeric::Type>(123), 123.6)));
+INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishDiscreteThrow,
+ getIncorrectParams());
-TEST_P(TestLogToRedfishThrow, commitExpectToThrow)
+TEST_P(TestLogToRedfishDiscreteThrow, commitExpectToThrow)
{
EXPECT_THROW(sut->commit("Test", 100'000, 90.0), std::runtime_error);
}
+namespace onChange
+{
+class TestLogToJournalDiscreteOnChange : public Test
+{
+ public:
+ void SetUp() override
+ {
+ sut = std::make_unique<LogToJournal>();
+ }
+
+ std::unique_ptr<LogToJournal> sut;
+};
+
+TEST_F(TestLogToJournalDiscreteOnChange, commitExpectNoThrow)
+{
+ EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
+}
+
+class TestLogToRedfishDiscreteOnChange : public Test
+{
+ public:
+ void SetUp() override
+ {
+ sut = std::make_unique<LogToRedfish>();
+ }
+
+ std::unique_ptr<LogToRedfish> sut;
+};
+
+TEST_F(TestLogToRedfishDiscreteOnChange, commitExpectNoThrow)
+{
+ EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
+}
+} // namespace onChange
+} // namespace discrete
+
class TestUpdateReport : public Test
{
public:
diff --git a/tests/src/test_trigger_manager.cpp b/tests/src/test_trigger_manager.cpp
index 95043e2..8754446 100644
--- a/tests/src/test_trigger_manager.cpp
+++ b/tests/src/test_trigger_manager.cpp
@@ -51,6 +51,36 @@
EXPECT_THAT(path, Eq(triggerMock.getPath()));
}
+TEST_F(TestTriggerManager, addTriggerWithDiscreteThresholds)
+{
+ TriggerParams triggerParamsDiscrete;
+ auto thresholds = std::vector<discrete::ThresholdParam>{
+ {"discrete_threshold1",
+ discrete::severityToString(discrete::Severity::ok), 10, 11.0},
+ {"discrete_threshold2",
+ discrete::severityToString(discrete::Severity::warning), 10, 12.0},
+ {"discrete_threshold3",
+ discrete::severityToString(discrete::Severity::critical), 10, 13.0}};
+
+ triggerParamsDiscrete.thresholdParams(thresholds).isDiscrete(true);
+
+ auto [ec, path] = addTrigger(triggerParamsDiscrete);
+ EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
+ EXPECT_THAT(path, Eq(triggerMock.getPath()));
+}
+
+TEST_F(TestTriggerManager, addDiscreteTriggerWithoutThresholds)
+{
+ TriggerParams triggerParamsDiscrete;
+ auto thresholds = std::vector<discrete::ThresholdParam>();
+
+ triggerParamsDiscrete.thresholdParams(thresholds).isDiscrete(true);
+
+ auto [ec, path] = addTrigger(triggerParamsDiscrete);
+ EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
+ EXPECT_THAT(path, Eq(triggerMock.getPath()));
+}
+
TEST_F(TestTriggerManager, DISABLED_failToAddTriggerTwice)
{
triggerFactoryMock.expectMake(triggerParams, Ref(*sut))