Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 1 | #include "dbus_environment.hpp" |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 2 | #include "fakes/clock_fake.hpp" |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 3 | #include "helpers.hpp" |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 4 | #include "messages/collect_trigger_id.hpp" |
| 5 | #include "messages/trigger_presence_changed_ind.hpp" |
| 6 | #include "messages/update_report_ind.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 7 | #include "mocks/json_storage_mock.hpp" |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 8 | #include "mocks/metric_mock.hpp" |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 9 | #include "mocks/report_factory_mock.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 10 | #include "mocks/report_manager_mock.hpp" |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 11 | #include "params/report_params.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 12 | #include "report.hpp" |
| 13 | #include "report_manager.hpp" |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 14 | #include "utils/clock.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 15 | #include "utils/contains.hpp" |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 16 | #include "utils/conv_container.hpp" |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 17 | #include "utils/dbus_path_utils.hpp" |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 18 | #include "utils/messanger.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 19 | #include "utils/transform.hpp" |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 20 | #include "utils/tstring.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 21 | |
| 22 | #include <sdbusplus/exception.hpp> |
| 23 | |
| 24 | using namespace testing; |
| 25 | using namespace std::literals::string_literals; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 26 | using namespace std::chrono_literals; |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 27 | using sdbusplus::message::object_path; |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 28 | namespace tstring = utils::tstring; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 29 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 30 | using ErrorMessageDbusType = std::tuple<std::string, std::string>; |
| 31 | using ErrorMessagesDbusType = std::vector<ErrorMessageDbusType>; |
| 32 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 33 | constexpr Milliseconds systemTimestamp = 55ms; |
| 34 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 35 | namespace |
| 36 | { |
| 37 | |
| 38 | ReportParams defaultParams() |
| 39 | { |
| 40 | return ReportParams(); |
| 41 | } |
| 42 | |
| 43 | ReportParams defaultOnChangeParams() |
| 44 | { |
| 45 | return defaultParams().reportingType(ReportingType::onChange); |
| 46 | } |
| 47 | |
| 48 | } // namespace |
| 49 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 50 | class TestReport : public Test |
| 51 | { |
| 52 | public: |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 53 | std::unique_ptr<ReportManagerMock> reportManagerMock = |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 54 | std::make_unique<NiceMock<ReportManagerMock>>(); |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 55 | std::unique_ptr<ReportFactoryMock> reportFactoryMock = |
| 56 | std::make_unique<NiceMock<ReportFactoryMock>>(); |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 57 | nlohmann::json storedConfiguration; |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 58 | NiceMock<StorageMock> storageMock; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 59 | std::vector<std::shared_ptr<MetricMock>> metricMocks; |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 60 | std::unique_ptr<ClockFake> clockFakePtr = std::make_unique<ClockFake>(); |
| 61 | ClockFake& clockFake = *clockFakePtr; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 62 | std::unique_ptr<Report> sut; |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 63 | utils::Messanger messanger; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 64 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 65 | MockFunction<void()> checkPoint; |
| 66 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 67 | TestReport() : messanger(DbusEnvironment::getIoc()) |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 68 | { |
| 69 | clockFake.system.set(systemTimestamp); |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 70 | ON_CALL(storageMock, store(to_file_path(ReportParams().reportId()), _)) |
| 71 | .WillByDefault(SaveArg<1>(&storedConfiguration)); |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 72 | } |
| 73 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 74 | void initMetricMocks( |
| 75 | const std::vector<LabeledMetricParameters>& metricParameters) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 76 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 77 | for (auto i = metricMocks.size(); i < metricParameters.size(); ++i) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 78 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 79 | metricMocks.emplace_back(std::make_shared<NiceMock<MetricMock>>()); |
| 80 | } |
| 81 | metricMocks.resize(metricParameters.size()); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 82 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 83 | std::vector<MetricValue> readings{{MetricValue{"a", "b", 17.1, 114}, |
| 84 | MetricValue{"aa", "bb", 42.0, 74}}}; |
| 85 | readings.resize(metricParameters.size()); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 86 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 87 | for (size_t i = 0; i < metricParameters.size(); ++i) |
| 88 | { |
Krzysztof Grobelny | 9e8da54 | 2022-02-17 10:40:16 +0100 | [diff] [blame] | 89 | ON_CALL(*metricMocks[i], getUpdatedReadings()) |
| 90 | .WillByDefault(ReturnRefOfCopy(std::vector({readings[i]}))); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 91 | ON_CALL(*metricMocks[i], dumpConfiguration()) |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 92 | .WillByDefault(Return(metricParameters[i])); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 96 | std::vector<std::shared_ptr<interfaces::Metric>> |
| 97 | getMetricsFromReadingParams(const ReadingParameters& params) |
| 98 | { |
| 99 | const auto metricParameters = |
| 100 | reportFactoryMock->convertMetricParams(params); |
| 101 | std::vector<std::shared_ptr<MetricMock>> metricMocks; |
| 102 | |
| 103 | for (size_t i = 0; i < metricParameters.size(); ++i) |
| 104 | { |
| 105 | metricMocks.emplace_back(std::make_shared<NiceMock<MetricMock>>()); |
| 106 | ON_CALL(*metricMocks[i], dumpConfiguration()) |
| 107 | .WillByDefault(Return(metricParameters[i])); |
| 108 | } |
| 109 | |
| 110 | return utils::convContainer<std::shared_ptr<interfaces::Metric>>( |
| 111 | metricMocks); |
| 112 | } |
| 113 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 114 | void SetUp() override |
| 115 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 116 | sut = makeReport(defaultParams()); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 117 | } |
| 118 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 119 | static interfaces::JsonStorage::FilePath to_file_path(std::string id) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 120 | { |
| 121 | return interfaces::JsonStorage::FilePath( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 122 | std::to_string(std::hash<std::string>{}(id))); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 125 | std::unique_ptr<Report> makeReport(const ReportParams& params) |
| 126 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 127 | initMetricMocks(params.metricParameters()); |
| 128 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 129 | return std::make_unique<Report>( |
| 130 | DbusEnvironment::getIoc(), DbusEnvironment::getObjServer(), |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 131 | params.reportId(), params.reportName(), params.reportingType(), |
| 132 | params.reportActions(), params.interval(), params.appendLimit(), |
| 133 | params.reportUpdates(), *reportManagerMock, storageMock, |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 134 | utils::convContainer<std::shared_ptr<interfaces::Metric>>( |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 135 | metricMocks), |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 136 | *reportFactoryMock, params.enabled(), std::move(clockFakePtr), |
| 137 | params.readings()); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 138 | } |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 139 | |
| 140 | template <class T> |
| 141 | static T getProperty(const std::string& path, const std::string& property) |
| 142 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 143 | return DbusEnvironment::getProperty<T>(path, Report::reportIfaceName, |
| 144 | property); |
| 145 | } |
| 146 | |
| 147 | template <class T> |
| 148 | static boost::system::error_code setProperty(const std::string& path, |
| 149 | const std::string& property, |
| 150 | const T& newValue) |
| 151 | { |
| 152 | return DbusEnvironment::setProperty<T>(path, Report::reportIfaceName, |
| 153 | property, newValue); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 156 | template <class T> |
| 157 | struct ChangePropertyParams |
| 158 | { |
| 159 | Matcher<T> valueBefore = _; |
| 160 | T newValue; |
| 161 | Matcher<boost::system::error_code> ec = |
| 162 | Eq(boost::system::errc::success); |
| 163 | Matcher<T> valueAfter = Eq(newValue); |
| 164 | }; |
| 165 | |
| 166 | template <class T> |
| 167 | static void changeProperty(const std::string& path, |
| 168 | const std::string& property, |
| 169 | ChangePropertyParams<T> p) |
| 170 | { |
| 171 | ASSERT_THAT(getProperty<T>(path, property), p.valueBefore); |
| 172 | ASSERT_THAT(setProperty<T>(path, property, p.newValue), p.ec); |
| 173 | EXPECT_THAT(getProperty<T>(path, property), p.valueAfter); |
| 174 | } |
| 175 | |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 176 | boost::system::error_code call(const std::string& path, |
| 177 | const std::string& interface, |
| 178 | const std::string& method) |
| 179 | { |
| 180 | std::promise<boost::system::error_code> methodPromise; |
| 181 | DbusEnvironment::getBus()->async_method_call( |
| 182 | [&methodPromise](boost::system::error_code ec) { |
| 183 | methodPromise.set_value(ec); |
| 184 | }, |
| 185 | DbusEnvironment::serviceName(), path, interface, method); |
| 186 | return DbusEnvironment::waitForFuture(methodPromise.get_future()); |
| 187 | } |
| 188 | |
| 189 | boost::system::error_code update(const std::string& path) |
| 190 | { |
| 191 | return call(path, Report::reportIfaceName, "Update"); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 194 | boost::system::error_code deleteReport(const std::string& path) |
| 195 | { |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 196 | return call(path, Report::deleteIfaceName, "Delete"); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 197 | } |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 198 | |
| 199 | static std::pair<std::string, std::vector<std::string>> |
| 200 | makeStateDetail(const std::string& detailType, |
| 201 | std::vector<std::string> detailArgs) |
| 202 | { |
| 203 | return make_pair(detailType, detailArgs); |
| 204 | } |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 205 | }; |
| 206 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 207 | TEST_F(TestReport, returnsId) |
| 208 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 209 | EXPECT_THAT(sut->getId(), Eq(defaultParams().reportId())); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 212 | TEST_F(TestReport, verifyIfPropertiesHaveValidValue) |
| 213 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 214 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Enabled"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 215 | Eq(defaultParams().enabled())); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 216 | EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "Interval"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 217 | Eq(defaultParams().interval().count())); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 218 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistency"), Eq(true)); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 219 | EXPECT_THAT( |
| 220 | getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 221 | Eq(utils::transform(defaultParams().reportActions(), [](const auto v) { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 222 | return utils::enumToString(v); |
| 223 | }))); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 224 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "EmitsReadingsUpdate"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 225 | Eq(utils::contains(defaultParams().reportActions(), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 226 | ReportAction::emitsReadingsUpdate))); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 227 | EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "AppendLimit"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 228 | Eq(defaultParams().appendLimit())); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 229 | EXPECT_THAT(getProperty<std::string>(sut->getPath(), "ReportingType"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 230 | Eq(utils::enumToString(defaultParams().reportingType()))); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 231 | EXPECT_THAT(getProperty<std::string>(sut->getPath(), "ReportUpdates"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 232 | Eq(utils::enumToString(defaultParams().reportUpdates()))); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 233 | EXPECT_THAT( |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 234 | getProperty<bool>(sut->getPath(), "LogToMetricReportsCollection"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 235 | Eq(utils::contains(defaultParams().reportActions(), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 236 | ReportAction::logToMetricReportsCollection))); |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 237 | EXPECT_THAT(getProperty<ReadingParameters>( |
| 238 | sut->getPath(), "ReadingParametersFutureVersion"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 239 | Eq(toReadingParameters(defaultParams().metricParameters()))); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 240 | EXPECT_THAT(getProperty<std::string>(sut->getPath(), "Name"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 241 | Eq(defaultParams().reportName())); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 242 | EXPECT_THAT( |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 243 | getProperty<std::vector<object_path>>(sut->getPath(), "Triggers"), |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 244 | IsEmpty()); |
| 245 | EXPECT_THAT( |
| 246 | getProperty<ErrorMessagesDbusType>(sut->getPath(), "ErrorMessages"), |
| 247 | IsEmpty()); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 248 | } |
| 249 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 250 | TEST_F(TestReport, readingsAreInitialyEmpty) |
| 251 | { |
| 252 | EXPECT_THAT(getProperty<Readings>(sut->getPath(), "Readings"), |
| 253 | Eq(Readings{})); |
| 254 | } |
| 255 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 256 | TEST_F(TestReport, setReadingParametersWithNewParams) |
| 257 | { |
| 258 | ReadingParameters newParams = toReadingParameters( |
| 259 | std::vector<LabeledMetricParameters>{{LabeledMetricParameters{ |
| 260 | {LabeledSensorInfo{"Service", |
| 261 | "/xyz/openbmc_project/sensors/power/psu", |
| 262 | "NewMetadata123"}}, |
| 263 | OperationType::avg, |
| 264 | "NewMetricId123", |
| 265 | CollectionTimeScope::startup, |
| 266 | CollectionDuration(250ms)}}}); |
| 267 | auto metrics = getMetricsFromReadingParams(newParams); |
| 268 | |
| 269 | EXPECT_CALL(*reportFactoryMock, updateMetrics(_, _, _)) |
| 270 | .WillOnce(SetArgReferee<0>(metrics)); |
| 271 | EXPECT_THAT( |
| 272 | setProperty(sut->getPath(), "ReadingParametersFutureVersion", newParams) |
| 273 | .value(), |
| 274 | Eq(boost::system::errc::success)); |
| 275 | EXPECT_THAT(getProperty<ReadingParameters>( |
| 276 | sut->getPath(), "ReadingParametersFutureVersion"), |
| 277 | Eq(newParams)); |
| 278 | } |
| 279 | |
| 280 | TEST_F(TestReport, setReportingTypeWithValidNewType) |
| 281 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 282 | changeProperty<std::string>( |
| 283 | sut->getPath(), "ReportingType", |
| 284 | {.valueBefore = Not(Eq(utils::enumToString(ReportingType::onRequest))), |
| 285 | .newValue = utils::enumToString(ReportingType::onRequest)}); |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | TEST_F(TestReport, setReportingTypeWithInvalidType) |
| 289 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 290 | const std::string currentValue = |
| 291 | utils::enumToString(defaultParams().reportingType()); |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 292 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 293 | changeProperty<std::string>( |
| 294 | sut->getPath(), "ReportingType", |
| 295 | {.valueBefore = Eq(currentValue), |
| 296 | .newValue = "Periodic_ABC", |
| 297 | .ec = Eq(boost::system::errc::invalid_argument), |
| 298 | .valueAfter = Eq(currentValue)}); |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | TEST_F(TestReport, setReportActionsWithValidNewActions) |
| 302 | { |
| 303 | std::vector<std::string> newActions = {"EmitsReadingsUpdate"}; |
| 304 | std::vector<std::string> currActions = |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 305 | utils::transform(defaultParams().reportActions(), |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 306 | [](const auto v) { return utils::enumToString(v); }); |
| 307 | |
| 308 | EXPECT_THAT(newActions, Ne(currActions)); |
| 309 | EXPECT_THAT( |
| 310 | setProperty(sut->getPath(), "ReportActions", newActions).value(), |
| 311 | Eq(boost::system::errc::success)); |
| 312 | EXPECT_THAT( |
| 313 | getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"), |
| 314 | UnorderedElementsAre("EmitsReadingsUpdate", |
| 315 | "LogToMetricReportsCollection")); |
| 316 | } |
| 317 | |
| 318 | TEST_F(TestReport, setReportActionsWithValidUnsortedActions) |
| 319 | { |
| 320 | std::vector<std::string> newActions = {"LogToMetricReportsCollection", |
| 321 | "EmitsReadingsUpdate"}; |
| 322 | std::vector<std::string> expectedActions = {"EmitsReadingsUpdate", |
| 323 | "LogToMetricReportsCollection"}; |
| 324 | std::vector<std::string> currActions = |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 325 | utils::transform(defaultParams().reportActions(), |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 326 | [](const auto v) { return utils::enumToString(v); }); |
| 327 | |
| 328 | EXPECT_THAT(newActions, Ne(currActions)); |
| 329 | EXPECT_THAT( |
| 330 | setProperty(sut->getPath(), "ReportActions", newActions).value(), |
| 331 | Eq(boost::system::errc::success)); |
| 332 | EXPECT_THAT( |
| 333 | getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"), |
| 334 | Eq(expectedActions)); |
| 335 | } |
| 336 | |
| 337 | TEST_F(TestReport, setReportActionsWithEmptyActions) |
| 338 | { |
| 339 | std::vector<std::string> newActions = {}; |
| 340 | std::vector<std::string> expectedActions = {"LogToMetricReportsCollection"}; |
| 341 | std::vector<std::string> currActions = |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 342 | utils::transform(defaultParams().reportActions(), |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 343 | [](const auto v) { return utils::enumToString(v); }); |
| 344 | |
| 345 | EXPECT_THAT(newActions, Ne(currActions)); |
| 346 | EXPECT_THAT( |
| 347 | setProperty(sut->getPath(), "ReportActions", newActions).value(), |
| 348 | Eq(boost::system::errc::success)); |
| 349 | EXPECT_THAT( |
| 350 | getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"), |
| 351 | Eq(expectedActions)); |
| 352 | } |
| 353 | |
| 354 | TEST_F(TestReport, setReportActionsWithInvalidActions) |
| 355 | { |
| 356 | std::vector<std::string> invalidActions = {"EmitsReadingsUpdate_1"}; |
| 357 | EXPECT_THAT( |
| 358 | setProperty(sut->getPath(), "ReportActions", invalidActions).value(), |
| 359 | Eq(boost::system::errc::invalid_argument)); |
| 360 | EXPECT_THAT( |
| 361 | getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 362 | Eq(utils::transform(defaultParams().reportActions(), [](const auto v) { |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 363 | return utils::enumToString(v); |
| 364 | }))); |
| 365 | } |
| 366 | |
| 367 | TEST_F(TestReport, createReportWithEmptyActions) |
| 368 | { |
| 369 | std::vector<std::string> expectedActions = {"LogToMetricReportsCollection"}; |
| 370 | |
| 371 | sut = makeReport(ReportParams().reportId("TestId_1").reportActions({})); |
| 372 | EXPECT_THAT( |
| 373 | getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"), |
| 374 | Eq(expectedActions)); |
| 375 | } |
| 376 | |
| 377 | TEST_F(TestReport, createReportWithValidUnsortedActions) |
| 378 | { |
| 379 | std::vector<std::string> newActions = {"LogToMetricReportsCollection", |
| 380 | "EmitsReadingsUpdate"}; |
| 381 | std::vector<std::string> expectedActions = {"EmitsReadingsUpdate", |
| 382 | "LogToMetricReportsCollection"}; |
| 383 | |
| 384 | sut = makeReport( |
| 385 | ReportParams() |
| 386 | .reportId("TestId_1") |
| 387 | .reportActions(utils::transform(newActions, [](const auto& action) { |
| 388 | return utils::toReportAction(action); |
| 389 | }))); |
| 390 | EXPECT_THAT( |
| 391 | getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"), |
| 392 | Eq(expectedActions)); |
| 393 | } |
| 394 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 395 | TEST_F(TestReport, setEnabledWithNewValue) |
| 396 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 397 | bool newValue = !defaultParams().enabled(); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 398 | EXPECT_THAT(setProperty(sut->getPath(), "Enabled", newValue).value(), |
| 399 | Eq(boost::system::errc::success)); |
| 400 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Enabled"), Eq(newValue)); |
| 401 | } |
| 402 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 403 | TEST_F(TestReport, setIntervalWithValidValue) |
| 404 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 405 | uint64_t newValue = ReportManager::minInterval.count() * 42; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 406 | EXPECT_THAT(setProperty(sut->getPath(), "Interval", newValue).value(), |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 407 | Eq(boost::system::errc::success)); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 408 | EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "Interval"), |
| 409 | Eq(newValue)); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 410 | } |
| 411 | |
Szymon Dompke | 3e2cc9d | 2021-12-14 12:00:52 +0100 | [diff] [blame] | 412 | TEST_F( |
| 413 | TestReport, |
| 414 | settingIntervalWithInvalidValueDoesNotChangePropertyAndReturnsInvalidArgument) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 415 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 416 | uint64_t newValue = ReportManager::minInterval.count() - 1; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 417 | EXPECT_THAT(setProperty(sut->getPath(), "Interval", newValue).value(), |
Szymon Dompke | 3e2cc9d | 2021-12-14 12:00:52 +0100 | [diff] [blame] | 418 | Eq(boost::system::errc::invalid_argument)); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 419 | EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "Interval"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 420 | Eq(defaultParams().interval().count())); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 421 | } |
| 422 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 423 | TEST_F(TestReport, settingInvalidReportingTypeCreatesErrorMessage) |
| 424 | { |
| 425 | auto report = makeReport(defaultParams() |
| 426 | .reportId("report2") |
| 427 | .reportingType(ReportingType::onRequest) |
| 428 | .interval(Milliseconds{0})); |
| 429 | |
| 430 | EXPECT_THAT( |
| 431 | setProperty<std::string>(report->getPath(), "ReportingType", "Periodic") |
| 432 | .value(), |
| 433 | Eq(boost::system::errc::success)); |
| 434 | |
| 435 | EXPECT_THAT(getProperty<std::string>(report->getPath(), "ReportingType"), |
| 436 | Eq("Periodic")); |
| 437 | EXPECT_THAT( |
| 438 | getProperty<ErrorMessagesDbusType>(report->getPath(), "ErrorMessages"), |
| 439 | UnorderedElementsAre( |
| 440 | ErrorMessageDbusType( |
| 441 | utils::enumToString(ErrorType::propertyConflict), "Interval"), |
| 442 | ErrorMessageDbusType( |
| 443 | utils::enumToString(ErrorType::propertyConflict), |
| 444 | "ReportingType"))); |
| 445 | } |
| 446 | |
| 447 | TEST_F(TestReport, settingValidReportingTypeRemovesErrors) |
| 448 | { |
| 449 | auto report = makeReport(defaultParams() |
| 450 | .reportId("report2") |
| 451 | .reportingType(ReportingType::onRequest) |
| 452 | .interval(Milliseconds{0})); |
| 453 | |
| 454 | EXPECT_THAT( |
| 455 | setProperty<std::string>(report->getPath(), "ReportingType", "Periodic") |
| 456 | .value(), |
| 457 | Eq(boost::system::errc::success)); |
| 458 | EXPECT_THAT(setProperty<std::string>(report->getPath(), "ReportingType", |
| 459 | "OnRequest") |
| 460 | .value(), |
| 461 | Eq(boost::system::errc::success)); |
| 462 | |
| 463 | EXPECT_THAT(getProperty<std::string>(report->getPath(), "ReportingType"), |
| 464 | Eq("OnRequest")); |
| 465 | EXPECT_THAT( |
| 466 | getProperty<ErrorMessagesDbusType>(report->getPath(), "ErrorMessages"), |
| 467 | IsEmpty()); |
| 468 | } |
| 469 | |
| 470 | TEST_F(TestReport, settingInvalidIntervalDisablesReport) |
| 471 | { |
| 472 | auto report = makeReport(defaultParams() |
| 473 | .reportId("report2") |
| 474 | .reportingType(ReportingType::periodic) |
| 475 | .interval(ReportManager::minInterval)); |
| 476 | |
| 477 | EXPECT_THAT(setProperty<uint64_t>(report->getPath(), "Interval", 0).value(), |
| 478 | Eq(boost::system::errc::success)); |
| 479 | |
| 480 | EXPECT_THAT(getProperty<uint64_t>(report->getPath(), "Interval"), Eq(0u)); |
| 481 | EXPECT_THAT( |
| 482 | getProperty<ErrorMessagesDbusType>(report->getPath(), "ErrorMessages"), |
| 483 | UnorderedElementsAre( |
| 484 | ErrorMessageDbusType( |
| 485 | utils::enumToString(ErrorType::propertyConflict), "Interval"), |
| 486 | ErrorMessageDbusType( |
| 487 | utils::enumToString(ErrorType::propertyConflict), |
| 488 | "ReportingType"))); |
| 489 | } |
| 490 | |
| 491 | TEST_F(TestReport, settingValidIntervalEnablesReport) |
| 492 | { |
| 493 | auto report = makeReport(defaultParams() |
| 494 | .reportId("report2") |
| 495 | .reportingType(ReportingType::periodic) |
| 496 | .interval(ReportManager::minInterval)); |
| 497 | |
| 498 | EXPECT_THAT(setProperty<uint64_t>(report->getPath(), "Interval", 0).value(), |
| 499 | Eq(boost::system::errc::success)); |
| 500 | EXPECT_THAT(setProperty<uint64_t>(report->getPath(), "Interval", |
| 501 | ReportManager::minInterval.count()) |
| 502 | .value(), |
| 503 | Eq(boost::system::errc::success)); |
| 504 | |
| 505 | EXPECT_THAT(getProperty<uint64_t>(report->getPath(), "Interval"), |
| 506 | Eq(ReportManager::minInterval.count())); |
| 507 | EXPECT_THAT( |
| 508 | getProperty<ErrorMessagesDbusType>(report->getPath(), "ErrorMessages"), |
| 509 | IsEmpty()); |
| 510 | } |
| 511 | |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 512 | TEST_F(TestReport, settingEmitsReadingsUpdateHaveNoEffect) |
| 513 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 514 | EXPECT_THAT( |
| 515 | setProperty(sut->getPath(), "EmitsReadingsUpdate", true).value(), |
| 516 | Eq(boost::system::errc::read_only_file_system)); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 517 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "EmitsReadingsUpdate"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 518 | Eq(utils::contains(defaultParams().reportActions(), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 519 | ReportAction::emitsReadingsUpdate))); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | TEST_F(TestReport, settingLogToMetricReportCollectionHaveNoEffect) |
| 523 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 524 | EXPECT_THAT( |
| 525 | setProperty(sut->getPath(), "LogToMetricReportsCollection", true) |
| 526 | .value(), |
| 527 | Eq(boost::system::errc::read_only_file_system)); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 528 | EXPECT_THAT( |
| 529 | getProperty<bool>(sut->getPath(), "LogToMetricReportsCollection"), |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 530 | Eq(utils::contains(defaultParams().reportActions(), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 531 | ReportAction::logToMetricReportsCollection))); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 532 | } |
| 533 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 534 | TEST_F(TestReport, settingPersistencyToFalseRemovesReportFromStorage) |
| 535 | { |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 536 | EXPECT_CALL(storageMock, store(_, _)).Times(0); |
| 537 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))) |
| 538 | .Times(AtLeast(1)); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 539 | |
| 540 | bool persistency = false; |
| 541 | EXPECT_THAT(setProperty(sut->getPath(), "Persistency", persistency).value(), |
| 542 | Eq(boost::system::errc::success)); |
| 543 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistency"), |
| 544 | Eq(persistency)); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | TEST_F(TestReport, deleteReport) |
| 548 | { |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 549 | EXPECT_CALL(*reportManagerMock, removeReport(sut.get())); |
| 550 | auto ec = deleteReport(sut->getPath()); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 551 | EXPECT_THAT(ec, Eq(boost::system::errc::success)); |
| 552 | } |
| 553 | |
| 554 | TEST_F(TestReport, deletingNonExistingReportReturnInvalidRequestDescriptor) |
| 555 | { |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 556 | auto ec = |
| 557 | deleteReport(utils::constants::reportDirPath.str + "NonExisting"s); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 558 | EXPECT_THAT(ec.value(), Eq(EBADR)); |
| 559 | } |
| 560 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 561 | TEST_F(TestReport, deleteReportExpectThatFileIsRemoveFromStorage) |
| 562 | { |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 563 | EXPECT_CALL(storageMock, store(_, _)).Times(0); |
| 564 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))) |
| 565 | .Times(AtLeast(1)); |
| 566 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 567 | auto ec = deleteReport(sut->getPath()); |
| 568 | EXPECT_THAT(ec, Eq(boost::system::errc::success)); |
| 569 | } |
| 570 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 571 | TEST_F(TestReport, updatesTriggerIdWhenTriggerIsAdded) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 572 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 573 | utils::Messanger messanger(DbusEnvironment::getIoc()); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 574 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 575 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 576 | messages::Presence::Exist, "trigger1", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 577 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 578 | messages::Presence::Exist, "trigger1", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 579 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 580 | messages::Presence::Exist, "trigger2", {"someOtherReport"}}); |
| 581 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 582 | messages::Presence::Exist, |
| 583 | "trigger3", |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 584 | {"someOtherReport", defaultParams().reportId()}}); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 585 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 586 | EXPECT_THAT( |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 587 | getProperty<std::vector<object_path>>(sut->getPath(), "Triggers"), |
| 588 | UnorderedElementsAre(utils::constants::triggerDirPath / "trigger1", |
| 589 | utils::constants::triggerDirPath / "trigger3")); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 590 | } |
| 591 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 592 | TEST_F(TestReport, updatesTriggerIdWhenTriggerIsRemoved) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 593 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 594 | utils::Messanger messanger(DbusEnvironment::getIoc()); |
| 595 | |
| 596 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 597 | messages::Presence::Exist, "trigger1", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 598 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 599 | messages::Presence::Exist, "trigger2", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 600 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 601 | messages::Presence::Exist, "trigger3", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 602 | |
| 603 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 604 | messages::Presence::Removed, "trigger1", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 605 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 606 | messages::Presence::Removed, "trigger2", {}}); |
| 607 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 608 | messages::Presence::Removed, "trigger1", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 609 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 610 | EXPECT_THAT( |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 611 | getProperty<std::vector<object_path>>(sut->getPath(), "Triggers"), |
| 612 | UnorderedElementsAre(utils::constants::triggerDirPath / "trigger3")); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 613 | } |
| 614 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 615 | TEST_F(TestReport, updatesTriggerIdWhenTriggerIsModified) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 616 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 617 | utils::Messanger messanger(DbusEnvironment::getIoc()); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 618 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 619 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 620 | messages::Presence::Exist, "trigger1", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 621 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 622 | messages::Presence::Exist, "trigger2", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 623 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 624 | messages::Presence::Exist, "trigger3", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 625 | |
| 626 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 627 | messages::Presence::Exist, "trigger1", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 628 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 629 | messages::Presence::Exist, "trigger2", {}}); |
| 630 | messanger.send(messages::TriggerPresenceChangedInd{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 631 | messages::Presence::Exist, "trigger3", {defaultParams().reportId()}}); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 632 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 633 | EXPECT_THAT( |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 634 | getProperty<std::vector<object_path>>(sut->getPath(), "Triggers"), |
| 635 | UnorderedElementsAre(utils::constants::triggerDirPath / "trigger1", |
| 636 | utils::constants::triggerDirPath / "trigger3")); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 637 | } |
| 638 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 639 | class TestReportStore : |
| 640 | public TestReport, |
| 641 | public WithParamInterface<std::pair<std::string, nlohmann::json>> |
| 642 | { |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 643 | void SetUp() override |
| 644 | {} |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 645 | }; |
| 646 | |
| 647 | INSTANTIATE_TEST_SUITE_P( |
| 648 | _, TestReportStore, |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 649 | Values( |
| 650 | std::make_pair("Enabled"s, nlohmann::json(defaultParams().enabled())), |
| 651 | std::make_pair("Version"s, nlohmann::json(6)), |
| 652 | std::make_pair("Id"s, nlohmann::json(defaultParams().reportId())), |
| 653 | std::make_pair("Name"s, nlohmann::json(defaultParams().reportName())), |
| 654 | std::make_pair("ReportingType", |
| 655 | nlohmann::json(defaultParams().reportingType())), |
| 656 | std::make_pair("ReportActions", nlohmann::json(utils::transform( |
| 657 | defaultParams().reportActions(), |
| 658 | [](const auto v) { |
| 659 | return utils::toUnderlying(v); |
| 660 | }))), |
| 661 | std::make_pair("Interval", |
| 662 | nlohmann::json(defaultParams().interval().count())), |
| 663 | std::make_pair("AppendLimit", |
| 664 | nlohmann::json(ReportParams().appendLimit())), |
| 665 | std::make_pair( |
| 666 | "ReadingParameters", |
| 667 | nlohmann::json( |
| 668 | {{{tstring::SensorPath::str(), |
| 669 | {{{tstring::Service::str(), "Service"}, |
| 670 | {tstring::Path::str(), |
| 671 | "/xyz/openbmc_project/sensors/power/p1"}, |
| 672 | {tstring::Metadata::str(), "metadata1"}}}}, |
| 673 | {tstring::OperationType::str(), OperationType::avg}, |
| 674 | {tstring::Id::str(), "MetricId1"}, |
| 675 | {tstring::CollectionTimeScope::str(), |
| 676 | CollectionTimeScope::point}, |
| 677 | {tstring::CollectionDuration::str(), 0}}, |
| 678 | {{tstring::SensorPath::str(), |
| 679 | {{{tstring::Service::str(), "Service"}, |
| 680 | {tstring::Path::str(), |
| 681 | "/xyz/openbmc_project/sensors/power/p2"}, |
| 682 | {tstring::Metadata::str(), "metadata2"}}}}, |
| 683 | {tstring::OperationType::str(), OperationType::avg}, |
| 684 | {tstring::Id::str(), "MetricId2"}, |
| 685 | {tstring::CollectionTimeScope::str(), |
| 686 | CollectionTimeScope::point}, |
| 687 | {tstring::CollectionDuration::str(), 0}}})))); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 688 | |
| 689 | TEST_P(TestReportStore, settingPersistencyToTrueStoresReport) |
| 690 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 691 | sut = makeReport(defaultParams()); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 692 | |
| 693 | { |
| 694 | InSequence seq; |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 695 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 696 | EXPECT_CALL(checkPoint, Call()); |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 697 | EXPECT_CALL(storageMock, store(to_file_path(sut->getId()), _)); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | setProperty(sut->getPath(), "Persistency", false); |
| 701 | checkPoint.Call(); |
| 702 | setProperty(sut->getPath(), "Persistency", true); |
| 703 | |
| 704 | const auto& [key, value] = GetParam(); |
| 705 | |
| 706 | ASSERT_THAT(storedConfiguration.at(key), Eq(value)); |
| 707 | } |
| 708 | |
| 709 | TEST_P(TestReportStore, reportIsSavedToStorageAfterCreated) |
| 710 | { |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 711 | EXPECT_CALL(storageMock, |
| 712 | store(to_file_path(defaultParams().reportId()), _)); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 713 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 714 | sut = makeReport(defaultParams()); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 715 | |
| 716 | const auto& [key, value] = GetParam(); |
| 717 | |
| 718 | ASSERT_THAT(storedConfiguration.at(key), Eq(value)); |
| 719 | } |
| 720 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 721 | class TestReportValidNames : |
| 722 | public TestReport, |
| 723 | public WithParamInterface<ReportParams> |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 724 | { |
| 725 | public: |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 726 | void SetUp() override |
| 727 | {} |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 728 | }; |
| 729 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 730 | INSTANTIATE_TEST_SUITE_P( |
| 731 | ValidNames, TestReportValidNames, |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 732 | Values(defaultParams().reportName("Valid_1"), |
| 733 | defaultParams().reportName("Valid_1/Valid_2"), |
| 734 | defaultParams().reportName("Valid_1/Valid_2/Valid_3"))); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 735 | |
| 736 | TEST_P(TestReportValidNames, reportCtorDoesNotThrowOnValidName) |
| 737 | { |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 738 | EXPECT_NO_THROW(makeReport(GetParam())); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 739 | } |
| 740 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 741 | class TestReportInvalidIds : |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 742 | public TestReport, |
| 743 | public WithParamInterface<ReportParams> |
| 744 | { |
| 745 | public: |
| 746 | void SetUp() override |
| 747 | {} |
| 748 | }; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 749 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 750 | INSTANTIATE_TEST_SUITE_P(InvalidNames, TestReportInvalidIds, |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 751 | Values(defaultParams().reportId("/"), |
| 752 | defaultParams().reportId("/Invalid"), |
| 753 | defaultParams().reportId("Invalid/"), |
| 754 | defaultParams().reportId("Invalid/Invalid/"), |
| 755 | defaultParams().reportId("Invalid?"))); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 756 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 757 | TEST_P(TestReportInvalidIds, failsToCreateReportWithInvalidName) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 758 | { |
| 759 | EXPECT_CALL(storageMock, store).Times(0); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 760 | |
| 761 | EXPECT_THROW(makeReport(GetParam()), sdbusplus::exception::SdBusError); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 762 | } |
| 763 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 764 | class TestReportAllReportTypes : |
| 765 | public TestReport, |
| 766 | public WithParamInterface<ReportParams> |
| 767 | { |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 768 | public: |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 769 | void SetUp() override |
| 770 | { |
| 771 | sut = makeReport(GetParam()); |
| 772 | } |
| 773 | }; |
| 774 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 775 | INSTANTIATE_TEST_SUITE_P( |
| 776 | _, TestReportAllReportTypes, |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 777 | Values(defaultParams().reportingType(ReportingType::onRequest), |
| 778 | defaultParams().reportingType(ReportingType::onChange), |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 779 | defaultParams() |
| 780 | .reportingType(ReportingType::periodic) |
| 781 | .interval(ReportManager::minInterval))); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 782 | |
| 783 | TEST_P(TestReportAllReportTypes, returnPropertValueOfReportType) |
| 784 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 785 | EXPECT_THAT(utils::toReportingType( |
| 786 | getProperty<std::string>(sut->getPath(), "ReportingType")), |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 787 | Eq(GetParam().reportingType())); |
| 788 | } |
| 789 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 790 | TEST_P(TestReportAllReportTypes, readingsAreUpdated) |
| 791 | { |
| 792 | clockFake.system.advance(10ms); |
| 793 | |
| 794 | messanger.send(messages::UpdateReportInd{{sut->getId()}}); |
| 795 | const auto [timestamp, readings] = |
| 796 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 797 | |
| 798 | EXPECT_THAT(Milliseconds{timestamp}, Eq(systemTimestamp + 10ms)); |
| 799 | } |
| 800 | |
| 801 | TEST_P(TestReportAllReportTypes, readingsAreNotUpdatedWhenReportIsDisabled) |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 802 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 803 | clockFake.system.advance(10ms); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 804 | |
| 805 | setProperty(sut->getPath(), "Enabled", false); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 806 | messanger.send(messages::UpdateReportInd{{sut->getId()}}); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 807 | const auto [timestamp, readings] = |
| 808 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 809 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 810 | EXPECT_THAT(Milliseconds{timestamp}, Eq(0ms)); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 811 | } |
| 812 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 813 | TEST_P(TestReportAllReportTypes, readingsAreNotUpdatedWhenReportIdDiffers) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 814 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 815 | clockFake.system.advance(10ms); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 816 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 817 | messanger.send(messages::UpdateReportInd{{sut->getId() + "x"s}}); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 818 | const auto [timestamp, readings] = |
| 819 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 820 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 821 | EXPECT_THAT(Milliseconds{timestamp}, Eq(0ms)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 822 | } |
| 823 | |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 824 | class TestReportOnRequestType : public TestReport |
| 825 | { |
| 826 | void SetUp() override |
| 827 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 828 | sut = |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 829 | makeReport(defaultParams().reportingType(ReportingType::onRequest)); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 830 | } |
| 831 | }; |
| 832 | |
| 833 | TEST_F(TestReportOnRequestType, updatesReadingTimestamp) |
| 834 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 835 | clockFake.system.advance(10ms); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 836 | |
| 837 | ASSERT_THAT(update(sut->getPath()), Eq(boost::system::errc::success)); |
| 838 | |
| 839 | const auto [timestamp, readings] = |
| 840 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 841 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 842 | EXPECT_THAT(Milliseconds{timestamp}, Eq(systemTimestamp + 10ms)); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | TEST_F(TestReportOnRequestType, updatesReadingWhenUpdateIsCalled) |
| 846 | { |
| 847 | ASSERT_THAT(update(sut->getPath()), Eq(boost::system::errc::success)); |
| 848 | |
| 849 | const auto [timestamp, readings] = |
| 850 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 851 | |
| 852 | EXPECT_THAT(readings, |
| 853 | ElementsAre(std::make_tuple("a"s, "b"s, 17.1, 114u), |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 854 | std::make_tuple("aa"s, "bb"s, 42.0, 74u))); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | class TestReportNonOnRequestType : |
| 858 | public TestReport, |
| 859 | public WithParamInterface<ReportParams> |
| 860 | { |
| 861 | void SetUp() override |
| 862 | { |
| 863 | sut = makeReport(GetParam()); |
| 864 | } |
| 865 | }; |
| 866 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 867 | INSTANTIATE_TEST_SUITE_P( |
| 868 | _, TestReportNonOnRequestType, |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 869 | Values(defaultParams().reportingType(ReportingType::periodic), |
| 870 | defaultParams().reportingType(ReportingType::onChange))); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 871 | |
| 872 | TEST_P(TestReportNonOnRequestType, readingsAreNotUpdateOnUpdateCall) |
| 873 | { |
| 874 | ASSERT_THAT(update(sut->getPath()), Eq(boost::system::errc::success)); |
| 875 | |
| 876 | EXPECT_THAT(getProperty<Readings>(sut->getPath(), "Readings"), |
| 877 | Eq(Readings{})); |
| 878 | } |
| 879 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 880 | class TestReportNonPeriodicReport : |
| 881 | public TestReport, |
| 882 | public WithParamInterface<ReportParams> |
| 883 | { |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 884 | public: |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 885 | void SetUp() override |
| 886 | { |
| 887 | sut = makeReport(GetParam()); |
| 888 | } |
| 889 | }; |
| 890 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 891 | INSTANTIATE_TEST_SUITE_P( |
| 892 | _, TestReportNonPeriodicReport, |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 893 | Values(defaultParams().reportingType(ReportingType::onRequest), |
| 894 | defaultParams().reportingType(ReportingType::onChange))); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 895 | |
| 896 | TEST_P(TestReportNonPeriodicReport, readingsAreNotUpdatedAfterIntervalExpires) |
| 897 | { |
| 898 | DbusEnvironment::sleepFor(ReportManager::minInterval + 1ms); |
| 899 | |
| 900 | EXPECT_THAT(getProperty<Readings>(sut->getPath(), "Readings"), |
| 901 | Eq(Readings{})); |
| 902 | } |
| 903 | |
| 904 | class TestReportPeriodicReport : public TestReport |
| 905 | { |
| 906 | void SetUp() override |
| 907 | { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 908 | sut = makeReport(defaultParams() |
| 909 | .reportingType(ReportingType::periodic) |
| 910 | .interval(ReportManager::minInterval)); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 911 | } |
| 912 | }; |
| 913 | |
| 914 | TEST_F(TestReportPeriodicReport, readingTimestampIsUpdatedAfterIntervalExpires) |
| 915 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 916 | clockFake.system.advance(10ms); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 917 | DbusEnvironment::sleepFor(ReportManager::minInterval + 1ms); |
| 918 | |
| 919 | const auto [timestamp, readings] = |
| 920 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 921 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 922 | EXPECT_THAT(Milliseconds{timestamp}, Eq(systemTimestamp + 10ms)); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | TEST_F(TestReportPeriodicReport, readingsAreUpdatedAfterIntervalExpires) |
| 926 | { |
| 927 | DbusEnvironment::sleepFor(ReportManager::minInterval + 1ms); |
| 928 | |
| 929 | const auto [timestamp, readings] = |
| 930 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 931 | |
| 932 | EXPECT_THAT(readings, |
| 933 | ElementsAre(std::make_tuple("a"s, "b"s, 17.1, 114u), |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 934 | std::make_tuple("aa"s, "bb"s, 42.0, 74u))); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 935 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 936 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 937 | struct ReportUpdatesReportParams |
| 938 | { |
| 939 | ReportParams reportParams; |
| 940 | std::vector<ReadingData> expectedReadings; |
| 941 | bool expectedEnabled; |
| 942 | }; |
| 943 | |
| 944 | class TestReportWithReportUpdatesAndLimit : |
| 945 | public TestReport, |
| 946 | public WithParamInterface<ReportUpdatesReportParams> |
| 947 | { |
| 948 | void SetUp() override |
| 949 | { |
| 950 | sut = makeReport(ReportParams(GetParam().reportParams) |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 951 | .reportingType(ReportingType::periodic) |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 952 | .interval(std::chrono::hours(1000))); |
| 953 | } |
| 954 | }; |
| 955 | |
| 956 | INSTANTIATE_TEST_SUITE_P( |
| 957 | _, TestReportWithReportUpdatesAndLimit, |
| 958 | Values( |
| 959 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 960 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 961 | .reportUpdates(ReportUpdates::appendWrapsWhenFull) |
| 962 | .appendLimit(5), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 963 | std::vector<ReadingData>{{std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 964 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 965 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 966 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 967 | std::make_tuple("a"s, "b"s, 17.1, 114u)}}, |
| 968 | true}, |
| 969 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 970 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 971 | .reportUpdates(ReportUpdates::appendWrapsWhenFull) |
| 972 | .appendLimit(4), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 973 | std::vector<ReadingData>{ |
| 974 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 975 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 976 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 977 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 978 | true}, |
| 979 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 980 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 981 | .reportUpdates(ReportUpdates::appendWrapsWhenFull) |
| 982 | .appendLimit(0), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 983 | std::vector<ReadingData>{}, true}, |
| 984 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 985 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 986 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 987 | .appendLimit(10), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 988 | std::vector<ReadingData>{ |
| 989 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 990 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 991 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 992 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 993 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 994 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 995 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 996 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 997 | true}, |
| 998 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 999 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1000 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 1001 | .appendLimit(5), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 1002 | std::vector<ReadingData>{{std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 1003 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 1004 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 1005 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 1006 | std::make_tuple("a"s, "b"s, 17.1, 114u)}}, |
| 1007 | false}, |
| 1008 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1009 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1010 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 1011 | .appendLimit(4), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 1012 | std::vector<ReadingData>{ |
| 1013 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 1014 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 1015 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 1016 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 1017 | false}, |
| 1018 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1019 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1020 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 1021 | .appendLimit(0), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 1022 | std::vector<ReadingData>{}, false}, |
| 1023 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1024 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1025 | .reportUpdates(ReportUpdates::overwrite) |
| 1026 | .appendLimit(500), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 1027 | std::vector<ReadingData>{ |
| 1028 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 1029 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 1030 | true}, |
| 1031 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1032 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1033 | .reportUpdates(ReportUpdates::overwrite) |
| 1034 | .appendLimit(1), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 1035 | std::vector<ReadingData>{ |
| 1036 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 1037 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 1038 | true}, |
| 1039 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1040 | defaultParams() |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1041 | .reportUpdates(ReportUpdates::overwrite) |
| 1042 | .appendLimit(0), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 1043 | std::vector<ReadingData>{ |
| 1044 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 1045 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 1046 | true})); |
| 1047 | |
| 1048 | TEST_P(TestReportWithReportUpdatesAndLimit, |
| 1049 | readingsAreUpdatedAfterIntervalExpires) |
| 1050 | { |
| 1051 | for (int i = 0; i < 4; i++) |
| 1052 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 1053 | messanger.send(messages::UpdateReportInd{{sut->getId()}}); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | const auto [timestamp, readings] = |
| 1057 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 1058 | const auto enabled = getProperty<bool>(sut->getPath(), "Enabled"); |
| 1059 | |
| 1060 | EXPECT_THAT(readings, ElementsAreArray(GetParam().expectedReadings)); |
| 1061 | EXPECT_EQ(enabled, GetParam().expectedEnabled); |
| 1062 | } |
| 1063 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 1064 | class TestReportInitialization : public TestReport |
| 1065 | { |
| 1066 | public: |
| 1067 | void SetUp() override |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1068 | { |
| 1069 | initMetricMocks(defaultParams().metricParameters()); |
| 1070 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 1071 | |
| 1072 | void monitorProc(sdbusplus::message::message& msg) |
| 1073 | { |
| 1074 | std::string iface; |
| 1075 | std::vector<std::pair<std::string, std::variant<Readings>>> |
| 1076 | changed_properties; |
| 1077 | std::vector<std::string> invalidated_properties; |
| 1078 | |
| 1079 | msg.read(iface, changed_properties, invalidated_properties); |
| 1080 | |
| 1081 | if (iface == Report::reportIfaceName) |
| 1082 | { |
| 1083 | for (const auto& [name, value] : changed_properties) |
| 1084 | { |
| 1085 | if (name == "Readings") |
| 1086 | { |
| 1087 | readingsUpdated.Call(); |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | void makeMonitor() |
| 1094 | { |
Patrick Williams | 3a62ee1 | 2021-12-03 10:13:25 -0600 | [diff] [blame] | 1095 | monitor = std::make_unique<sdbusplus::bus::match_t>( |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 1096 | *DbusEnvironment::getBus(), |
| 1097 | sdbusplus::bus::match::rules::propertiesChanged( |
| 1098 | sut->getPath(), Report::reportIfaceName), |
| 1099 | [this](auto& msg) { monitorProc(msg); }); |
| 1100 | } |
| 1101 | |
Patrick Williams | 3a62ee1 | 2021-12-03 10:13:25 -0600 | [diff] [blame] | 1102 | std::unique_ptr<sdbusplus::bus::match_t> monitor; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 1103 | MockFunction<void()> readingsUpdated; |
| 1104 | }; |
| 1105 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 1106 | TEST_F(TestReportInitialization, |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1107 | registersForMetricUpdatesWhenOnChangeReportCreated) |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 1108 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1109 | std::vector<const interfaces::MetricListener*> args; |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 1110 | for (auto& metric : metricMocks) |
| 1111 | { |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1112 | EXPECT_CALL(*metric, registerForUpdates(_)) |
| 1113 | .WillOnce(Invoke([&args](const interfaces::MetricListener& report) { |
| 1114 | args.emplace_back(&report); |
| 1115 | })); |
| 1116 | ; |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 1117 | } |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1118 | |
| 1119 | sut = makeReport(defaultParams().reportingType(ReportingType::onChange)); |
| 1120 | |
| 1121 | EXPECT_THAT(args, SizeIs(metricMocks.size())); |
| 1122 | for (const auto* reportPtr : args) |
| 1123 | { |
| 1124 | EXPECT_THAT(reportPtr, Eq(sut.get())); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | TEST_F(TestReportInitialization, |
| 1129 | deregistersForMetricUpdatesWhenOnChangeReportDestroyed) |
| 1130 | { |
| 1131 | sut = makeReport(defaultParams().reportingType(ReportingType::onChange)); |
| 1132 | |
| 1133 | for (auto& metric : metricMocks) |
| 1134 | { |
| 1135 | EXPECT_CALL(*metric, |
| 1136 | unregisterFromUpdates(Ref( |
| 1137 | static_cast<interfaces::MetricListener&>(*sut.get())))); |
| 1138 | } |
| 1139 | |
| 1140 | sut = nullptr; |
| 1141 | } |
| 1142 | |
| 1143 | TEST_F(TestReportInitialization, |
| 1144 | metricsAreInitializedWhenEnabledReportConstructed) |
| 1145 | { |
| 1146 | for (auto& metric : metricMocks) |
| 1147 | { |
| 1148 | EXPECT_CALL(*metric, initialize()); |
| 1149 | } |
| 1150 | sut = makeReport(defaultParams().enabled(true)); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 1151 | } |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 1152 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 1153 | TEST_F(TestReportInitialization, |
| 1154 | metricsAreNotInitializedWhenDisabledReportConstructed) |
| 1155 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 1156 | for (auto& metric : metricMocks) |
| 1157 | { |
| 1158 | EXPECT_CALL(*metric, initialize()).Times(0); |
| 1159 | } |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1160 | sut = makeReport(defaultParams().enabled(false)); |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 1161 | } |
| 1162 | |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 1163 | TEST_F(TestReportInitialization, |
| 1164 | emitReadingsUpdateIsTrueReadingsPropertiesChangedSingalEmits) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 1165 | { |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 1166 | EXPECT_CALL(readingsUpdated, Call()) |
| 1167 | .WillOnce( |
| 1168 | InvokeWithoutArgs(DbusEnvironment::setPromise("readingsUpdated"))); |
| 1169 | |
| 1170 | const auto elapsed = DbusEnvironment::measureTime([this] { |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 1171 | sut = makeReport(defaultParams() |
| 1172 | .reportingType(ReportingType::periodic) |
| 1173 | .reportActions({ReportAction::emitsReadingsUpdate}) |
| 1174 | .interval(ReportManager::minInterval)); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 1175 | makeMonitor(); |
| 1176 | EXPECT_TRUE(DbusEnvironment::waitForFuture("readingsUpdated")); |
| 1177 | }); |
| 1178 | |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 1179 | EXPECT_THAT(elapsed, AllOf(Ge(ReportManager::minInterval), |
| 1180 | Lt(ReportManager::minInterval * 2))); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | TEST_F(TestReportInitialization, |
| 1184 | emitReadingsUpdateIsFalseReadingsPropertiesChangesSigalDoesNotEmits) |
| 1185 | { |
| 1186 | EXPECT_CALL(readingsUpdated, Call()).Times(0); |
| 1187 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1188 | sut = makeReport(defaultParams() |
| 1189 | .reportingType(ReportingType::periodic) |
| 1190 | .reportActions({})); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 1191 | makeMonitor(); |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1192 | DbusEnvironment::sleepFor(defaultParams().interval() * 2); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 1193 | } |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 1194 | |
| 1195 | TEST_F(TestReportInitialization, appendLimitDeducedProperly) |
| 1196 | { |
| 1197 | sut = makeReport( |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1198 | defaultParams().appendLimit(std::numeric_limits<uint64_t>::max())); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 1199 | auto appendLimit = getProperty<uint64_t>(sut->getPath(), "AppendLimit"); |
| 1200 | EXPECT_EQ(appendLimit, 2ull); |
| 1201 | } |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 1202 | |
| 1203 | TEST_F(TestReportInitialization, appendLimitSetToUintMaxIsStoredCorrectly) |
| 1204 | { |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 1205 | sut = makeReport( |
| 1206 | ReportParams().appendLimit(std::numeric_limits<uint64_t>::max())); |
| 1207 | |
| 1208 | ASSERT_THAT(storedConfiguration.at("AppendLimit"), |
| 1209 | Eq(std::numeric_limits<uint64_t>::max())); |
| 1210 | } |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 1211 | |
| 1212 | TEST_F(TestReportInitialization, triggerIdsPropertyIsInitialzed) |
| 1213 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 1214 | for (const auto& triggerId : {"trigger1", "trigger2"}) |
| 1215 | { |
| 1216 | messanger.on_receive<messages::CollectTriggerIdReq>( |
Szymon Dompke | e0ed508 | 2022-05-20 10:54:25 +0200 | [diff] [blame] | 1217 | [this, triggerId](const auto& msg) { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 1218 | messanger.send(messages::CollectTriggerIdResp{triggerId}); |
| 1219 | }); |
| 1220 | } |
| 1221 | |
| 1222 | sut = makeReport(ReportParams()); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 1223 | |
| 1224 | EXPECT_THAT( |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 1225 | getProperty<std::vector<object_path>>(sut->getPath(), "Triggers"), |
| 1226 | UnorderedElementsAre(utils::constants::triggerDirPath / "trigger1", |
| 1227 | utils::constants::triggerDirPath / "trigger2")); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 1228 | } |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1229 | |
Krzysztof Grobelny | 493e62e | 2022-02-14 10:55:50 +0100 | [diff] [blame] | 1230 | TEST_F(TestReportInitialization, |
| 1231 | metricValuesAreNotStoredForReportUpdatesDifferentThanAppendStopsWhenFull) |
| 1232 | { |
| 1233 | sut = makeReport(ReportParams() |
| 1234 | .reportingType(ReportingType::periodic) |
| 1235 | .interval(1h) |
| 1236 | .reportUpdates(ReportUpdates::appendWrapsWhenFull) |
| 1237 | .readings(Readings{{}, {{}}})); |
| 1238 | |
| 1239 | ASSERT_THAT(storedConfiguration.find("MetricValues"), |
| 1240 | Eq(storedConfiguration.end())); |
| 1241 | } |
| 1242 | |
| 1243 | TEST_F(TestReportInitialization, metricValuesAreNotStoredForOnRequestReport) |
| 1244 | { |
| 1245 | sut = makeReport(ReportParams() |
| 1246 | .reportingType(ReportingType::onRequest) |
| 1247 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 1248 | .readings(Readings{{}, {{}}})); |
| 1249 | |
| 1250 | ASSERT_THAT(storedConfiguration.find("MetricValues"), |
| 1251 | Eq(storedConfiguration.end())); |
| 1252 | } |
| 1253 | |
| 1254 | TEST_F(TestReportInitialization, |
| 1255 | metricValuesAreStoredForNonOnRequestReportWithAppendStopsWhenFull) |
| 1256 | { |
| 1257 | const auto readings = Readings{{}, {{}}}; |
| 1258 | |
| 1259 | sut = makeReport(ReportParams() |
| 1260 | .reportingType(ReportingType::periodic) |
| 1261 | .interval(1h) |
| 1262 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 1263 | .readings(readings)); |
| 1264 | |
| 1265 | ASSERT_THAT(storedConfiguration.at("MetricValues").get<LabeledReadings>(), |
| 1266 | Eq(utils::toLabeledReadings(readings))); |
| 1267 | } |
| 1268 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 1269 | class TestReportInitializationOnChangeReport : public TestReportInitialization |
| 1270 | { |
| 1271 | public: |
| 1272 | void SetUp() override |
| 1273 | { |
| 1274 | initMetricMocks(params.metricParameters()); |
| 1275 | } |
| 1276 | |
| 1277 | ReportParams params = defaultOnChangeParams(); |
| 1278 | }; |
| 1279 | |
| 1280 | TEST_F(TestReportInitializationOnChangeReport, |
| 1281 | doesntUpdateReadingsWhenNotRequired) |
| 1282 | { |
| 1283 | EXPECT_CALL(*metricMocks[0], updateReadings(_)).Times(0); |
| 1284 | |
| 1285 | ON_CALL(*metricMocks[0], isTimerRequired()).WillByDefault(Return(false)); |
| 1286 | |
| 1287 | sut = makeReport(params); |
| 1288 | |
| 1289 | DbusEnvironment::sleepFor(500ms); |
| 1290 | } |
| 1291 | |
| 1292 | TEST_F(TestReportInitializationOnChangeReport, updatesReadingsWhenRequired) |
| 1293 | { |
| 1294 | EXPECT_CALL(*metricMocks[0], updateReadings(_)) |
| 1295 | .WillOnce(Return()) |
| 1296 | .WillOnce( |
| 1297 | InvokeWithoutArgs(DbusEnvironment::setPromise("readingsUpdated"))) |
| 1298 | .WillRepeatedly(Return()); |
| 1299 | |
| 1300 | ON_CALL(*metricMocks[0], isTimerRequired()).WillByDefault(Return(true)); |
| 1301 | |
| 1302 | sut = makeReport(params); |
| 1303 | |
| 1304 | DbusEnvironment::waitForFuture("readingsUpdated"); |
| 1305 | } |