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" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 9 | #include "mocks/report_manager_mock.hpp" |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 10 | #include "params/report_params.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 11 | #include "report.hpp" |
| 12 | #include "report_manager.hpp" |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 13 | #include "utils/clock.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 14 | #include "utils/contains.hpp" |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 15 | #include "utils/conv_container.hpp" |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 16 | #include "utils/messanger.hpp" |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 17 | #include "utils/transform.hpp" |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 18 | #include "utils/tstring.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 19 | |
| 20 | #include <sdbusplus/exception.hpp> |
| 21 | |
| 22 | using namespace testing; |
| 23 | using namespace std::literals::string_literals; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 24 | using namespace std::chrono_literals; |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 25 | namespace tstring = utils::tstring; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 26 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 27 | constexpr Milliseconds systemTimestamp = 55ms; |
| 28 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 29 | class TestReport : public Test |
| 30 | { |
| 31 | public: |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 32 | ReportParams defaultParams; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 33 | |
| 34 | std::unique_ptr<ReportManagerMock> reportManagerMock = |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 35 | std::make_unique<NiceMock<ReportManagerMock>>(); |
| 36 | testing::NiceMock<StorageMock> storageMock; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 37 | std::vector<std::shared_ptr<MetricMock>> metricMocks; |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 38 | std::unique_ptr<ClockFake> clockFakePtr = std::make_unique<ClockFake>(); |
| 39 | ClockFake& clockFake = *clockFakePtr; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 40 | std::unique_ptr<Report> sut; |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 41 | utils::Messanger messanger; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 42 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 43 | MockFunction<void()> checkPoint; |
| 44 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 45 | TestReport() : messanger(DbusEnvironment::getIoc()) |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 46 | { |
| 47 | clockFake.system.set(systemTimestamp); |
| 48 | } |
| 49 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 50 | void initMetricMocks( |
| 51 | const std::vector<LabeledMetricParameters>& metricParameters) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 52 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 53 | for (auto i = metricMocks.size(); i < metricParameters.size(); ++i) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 54 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 55 | metricMocks.emplace_back(std::make_shared<NiceMock<MetricMock>>()); |
| 56 | } |
| 57 | metricMocks.resize(metricParameters.size()); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 58 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 59 | std::vector<MetricValue> readings{{MetricValue{"a", "b", 17.1, 114}, |
| 60 | MetricValue{"aa", "bb", 42.0, 74}}}; |
| 61 | readings.resize(metricParameters.size()); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 62 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 63 | for (size_t i = 0; i < metricParameters.size(); ++i) |
| 64 | { |
| 65 | ON_CALL(*metricMocks[i], getReadings()) |
Krzysztof Grobelny | 8069771 | 2021-03-04 09:49:27 +0000 | [diff] [blame] | 66 | .WillByDefault(Return(std::vector({readings[i]}))); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 67 | ON_CALL(*metricMocks[i], dumpConfiguration()) |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 68 | .WillByDefault(Return(metricParameters[i])); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 72 | void SetUp() override |
| 73 | { |
| 74 | sut = makeReport(ReportParams()); |
| 75 | } |
| 76 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 77 | static interfaces::JsonStorage::FilePath to_file_path(std::string id) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 78 | { |
| 79 | return interfaces::JsonStorage::FilePath( |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 80 | std::to_string(std::hash<std::string>{}(id))); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 83 | std::unique_ptr<Report> makeReport(const ReportParams& params) |
| 84 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 85 | initMetricMocks(params.metricParameters()); |
| 86 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 87 | return std::make_unique<Report>( |
| 88 | DbusEnvironment::getIoc(), DbusEnvironment::getObjServer(), |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 89 | params.reportId(), params.reportName(), params.reportingType(), |
| 90 | params.reportActions(), params.interval(), params.appendLimit(), |
| 91 | params.reportUpdates(), *reportManagerMock, storageMock, |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 92 | utils::convContainer<std::shared_ptr<interfaces::Metric>>( |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 93 | metricMocks), |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 94 | params.enabled(), std::move(clockFakePtr)); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 95 | } |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 96 | |
| 97 | template <class T> |
| 98 | static T getProperty(const std::string& path, const std::string& property) |
| 99 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 100 | return DbusEnvironment::getProperty<T>(path, Report::reportIfaceName, |
| 101 | property); |
| 102 | } |
| 103 | |
| 104 | template <class T> |
| 105 | static boost::system::error_code setProperty(const std::string& path, |
| 106 | const std::string& property, |
| 107 | const T& newValue) |
| 108 | { |
| 109 | return DbusEnvironment::setProperty<T>(path, Report::reportIfaceName, |
| 110 | property, newValue); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | boost::system::error_code call(const std::string& path, |
| 114 | const std::string& interface, |
| 115 | const std::string& method) |
| 116 | { |
| 117 | std::promise<boost::system::error_code> methodPromise; |
| 118 | DbusEnvironment::getBus()->async_method_call( |
| 119 | [&methodPromise](boost::system::error_code ec) { |
| 120 | methodPromise.set_value(ec); |
| 121 | }, |
| 122 | DbusEnvironment::serviceName(), path, interface, method); |
| 123 | return DbusEnvironment::waitForFuture(methodPromise.get_future()); |
| 124 | } |
| 125 | |
| 126 | boost::system::error_code update(const std::string& path) |
| 127 | { |
| 128 | return call(path, Report::reportIfaceName, "Update"); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 129 | } |
| 130 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 131 | boost::system::error_code deleteReport(const std::string& path) |
| 132 | { |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 133 | return call(path, Report::deleteIfaceName, "Delete"); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 134 | } |
| 135 | }; |
| 136 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 137 | TEST_F(TestReport, returnsId) |
| 138 | { |
| 139 | EXPECT_THAT(sut->getId(), Eq(defaultParams.reportId())); |
| 140 | } |
| 141 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 142 | TEST_F(TestReport, verifyIfPropertiesHaveValidValue) |
| 143 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 144 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Enabled"), |
| 145 | Eq(defaultParams.enabled())); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 146 | EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "Interval"), |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 147 | Eq(defaultParams.interval().count())); |
| 148 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistency"), Eq(true)); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 149 | EXPECT_THAT( |
| 150 | getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"), |
| 151 | Eq(utils::transform(defaultParams.reportActions(), [](const auto v) { |
| 152 | return utils::enumToString(v); |
| 153 | }))); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 154 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "EmitsReadingsUpdate"), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 155 | Eq(utils::contains(defaultParams.reportActions(), |
| 156 | ReportAction::emitsReadingsUpdate))); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 157 | EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "AppendLimit"), |
| 158 | Eq(defaultParams.appendLimit())); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 159 | EXPECT_THAT(getProperty<std::string>(sut->getPath(), "ReportingType"), |
| 160 | Eq(utils::enumToString(defaultParams.reportingType()))); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 161 | EXPECT_THAT(getProperty<std::string>(sut->getPath(), "ReportUpdates"), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 162 | Eq(utils::enumToString(defaultParams.reportUpdates()))); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 163 | EXPECT_THAT( |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 164 | getProperty<bool>(sut->getPath(), "LogToMetricReportsCollection"), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 165 | Eq(utils::contains(defaultParams.reportActions(), |
| 166 | ReportAction::logToMetricReportsCollection))); |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 167 | EXPECT_THAT(getProperty<ReadingParameters>( |
| 168 | sut->getPath(), "ReadingParametersFutureVersion"), |
| 169 | Eq(toReadingParameters(defaultParams.metricParameters()))); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 170 | EXPECT_THAT(getProperty<std::string>(sut->getPath(), "Name"), |
| 171 | Eq(defaultParams.reportName())); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 172 | EXPECT_THAT( |
| 173 | getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"), |
| 174 | Eq(std::vector<std::string>())); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 177 | TEST_F(TestReport, readingsAreInitialyEmpty) |
| 178 | { |
| 179 | EXPECT_THAT(getProperty<Readings>(sut->getPath(), "Readings"), |
| 180 | Eq(Readings{})); |
| 181 | } |
| 182 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 183 | TEST_F(TestReport, setEnabledWithNewValue) |
| 184 | { |
| 185 | bool newValue = !defaultParams.enabled(); |
| 186 | EXPECT_THAT(setProperty(sut->getPath(), "Enabled", newValue).value(), |
| 187 | Eq(boost::system::errc::success)); |
| 188 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Enabled"), Eq(newValue)); |
| 189 | } |
| 190 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 191 | TEST_F(TestReport, setIntervalWithValidValue) |
| 192 | { |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 193 | uint64_t newValue = defaultParams.interval().count() + 1; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 194 | EXPECT_THAT(setProperty(sut->getPath(), "Interval", newValue).value(), |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 195 | Eq(boost::system::errc::success)); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 196 | EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "Interval"), |
| 197 | Eq(newValue)); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Szymon Dompke | 3e2cc9d | 2021-12-14 12:00:52 +0100 | [diff] [blame] | 200 | TEST_F( |
| 201 | TestReport, |
| 202 | settingIntervalWithInvalidValueDoesNotChangePropertyAndReturnsInvalidArgument) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 203 | { |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 204 | uint64_t newValue = defaultParams.interval().count() - 1; |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 205 | EXPECT_THAT(setProperty(sut->getPath(), "Interval", newValue).value(), |
Szymon Dompke | 3e2cc9d | 2021-12-14 12:00:52 +0100 | [diff] [blame] | 206 | Eq(boost::system::errc::invalid_argument)); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 207 | EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "Interval"), |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 208 | Eq(defaultParams.interval().count())); |
| 209 | } |
| 210 | |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 211 | TEST_F(TestReport, settingEmitsReadingsUpdateHaveNoEffect) |
| 212 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 213 | EXPECT_THAT( |
| 214 | setProperty(sut->getPath(), "EmitsReadingsUpdate", true).value(), |
| 215 | Eq(boost::system::errc::read_only_file_system)); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 216 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "EmitsReadingsUpdate"), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 217 | Eq(utils::contains(defaultParams.reportActions(), |
| 218 | ReportAction::emitsReadingsUpdate))); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | TEST_F(TestReport, settingLogToMetricReportCollectionHaveNoEffect) |
| 222 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 223 | EXPECT_THAT( |
| 224 | setProperty(sut->getPath(), "LogToMetricReportsCollection", true) |
| 225 | .value(), |
| 226 | Eq(boost::system::errc::read_only_file_system)); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 227 | EXPECT_THAT( |
| 228 | getProperty<bool>(sut->getPath(), "LogToMetricReportsCollection"), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 229 | Eq(utils::contains(defaultParams.reportActions(), |
| 230 | ReportAction::logToMetricReportsCollection))); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 233 | TEST_F(TestReport, settingPersistencyToFalseRemovesReportFromStorage) |
| 234 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 235 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 236 | |
| 237 | bool persistency = false; |
| 238 | EXPECT_THAT(setProperty(sut->getPath(), "Persistency", persistency).value(), |
| 239 | Eq(boost::system::errc::success)); |
| 240 | EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistency"), |
| 241 | Eq(persistency)); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | TEST_F(TestReport, deleteReport) |
| 245 | { |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 246 | EXPECT_CALL(*reportManagerMock, removeReport(sut.get())); |
| 247 | auto ec = deleteReport(sut->getPath()); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 248 | EXPECT_THAT(ec, Eq(boost::system::errc::success)); |
| 249 | } |
| 250 | |
| 251 | TEST_F(TestReport, deletingNonExistingReportReturnInvalidRequestDescriptor) |
| 252 | { |
| 253 | auto ec = deleteReport(Report::reportDir + "NonExisting"s); |
| 254 | EXPECT_THAT(ec.value(), Eq(EBADR)); |
| 255 | } |
| 256 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 257 | TEST_F(TestReport, deleteReportExpectThatFileIsRemoveFromStorage) |
| 258 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 259 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 260 | auto ec = deleteReport(sut->getPath()); |
| 261 | EXPECT_THAT(ec, Eq(boost::system::errc::success)); |
| 262 | } |
| 263 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 264 | TEST_F(TestReport, updatesTriggerIdWhenTriggerIsAdded) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 265 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 266 | utils::Messanger messanger(DbusEnvironment::getIoc()); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 267 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 268 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 269 | messages::Presence::Exist, "trigger1", {defaultParams.reportId()}}); |
| 270 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 271 | messages::Presence::Exist, "trigger1", {defaultParams.reportId()}}); |
| 272 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 273 | messages::Presence::Exist, "trigger2", {"someOtherReport"}}); |
| 274 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 275 | messages::Presence::Exist, |
| 276 | "trigger3", |
| 277 | {"someOtherReport", defaultParams.reportId()}}); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 278 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 279 | EXPECT_THAT( |
| 280 | getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"), |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 281 | UnorderedElementsAre("trigger1", "trigger3")); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 284 | TEST_F(TestReport, updatesTriggerIdWhenTriggerIsRemoved) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 285 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 286 | utils::Messanger messanger(DbusEnvironment::getIoc()); |
| 287 | |
| 288 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 289 | messages::Presence::Exist, "trigger1", {defaultParams.reportId()}}); |
| 290 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 291 | messages::Presence::Exist, "trigger2", {defaultParams.reportId()}}); |
| 292 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 293 | messages::Presence::Exist, "trigger3", {defaultParams.reportId()}}); |
| 294 | |
| 295 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 296 | messages::Presence::Removed, "trigger1", {defaultParams.reportId()}}); |
| 297 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 298 | messages::Presence::Removed, "trigger2", {}}); |
| 299 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 300 | messages::Presence::Removed, "trigger1", {defaultParams.reportId()}}); |
| 301 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 302 | EXPECT_THAT( |
| 303 | getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"), |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 304 | UnorderedElementsAre("trigger3")); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 305 | } |
| 306 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 307 | TEST_F(TestReport, updatesTriggerIdWhenTriggerIsModified) |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 308 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 309 | utils::Messanger messanger(DbusEnvironment::getIoc()); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 310 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 311 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 312 | messages::Presence::Exist, "trigger1", {defaultParams.reportId()}}); |
| 313 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 314 | messages::Presence::Exist, "trigger2", {defaultParams.reportId()}}); |
| 315 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 316 | messages::Presence::Exist, "trigger3", {defaultParams.reportId()}}); |
| 317 | |
| 318 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 319 | messages::Presence::Exist, "trigger1", {defaultParams.reportId()}}); |
| 320 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 321 | messages::Presence::Exist, "trigger2", {}}); |
| 322 | messanger.send(messages::TriggerPresenceChangedInd{ |
| 323 | messages::Presence::Exist, "trigger3", {defaultParams.reportId()}}); |
| 324 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 325 | EXPECT_THAT( |
| 326 | getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"), |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 327 | UnorderedElementsAre("trigger1", "trigger3")); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 328 | } |
| 329 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 330 | class TestReportStore : |
| 331 | public TestReport, |
| 332 | public WithParamInterface<std::pair<std::string, nlohmann::json>> |
| 333 | { |
| 334 | public: |
| 335 | void SetUp() override |
| 336 | {} |
| 337 | |
| 338 | nlohmann::json storedConfiguration; |
| 339 | }; |
| 340 | |
| 341 | INSTANTIATE_TEST_SUITE_P( |
| 342 | _, TestReportStore, |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 343 | Values(std::make_pair("Enabled"s, nlohmann::json(ReportParams().enabled())), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 344 | std::make_pair("Version"s, nlohmann::json(6)), |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 345 | std::make_pair("Id"s, nlohmann::json(ReportParams().reportId())), |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 346 | std::make_pair("Name"s, nlohmann::json(ReportParams().reportName())), |
| 347 | std::make_pair("ReportingType", |
| 348 | nlohmann::json(ReportParams().reportingType())), |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 349 | std::make_pair("ReportActions", nlohmann::json(utils::transform( |
| 350 | ReportParams().reportActions(), |
| 351 | [](const auto v) { |
| 352 | return utils::toUnderlying( |
| 353 | v); |
| 354 | }))), |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 355 | std::make_pair("Interval", |
| 356 | nlohmann::json(ReportParams().interval().count())), |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 357 | std::make_pair("AppendLimit", |
| 358 | nlohmann::json(ReportParams().appendLimit())), |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 359 | std::make_pair( |
| 360 | "ReadingParameters", |
| 361 | nlohmann::json( |
| 362 | {{{tstring::SensorPath::str(), |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 363 | {{{tstring::Service::str(), "Service"}, |
| 364 | {tstring::Path::str(), |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 365 | "/xyz/openbmc_project/sensors/power/p1"}, |
| 366 | {tstring::Metadata::str(), "metadata1"}}}}, |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 367 | {tstring::OperationType::str(), OperationType::single}, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 368 | {tstring::Id::str(), "MetricId1"}, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 369 | {tstring::CollectionTimeScope::str(), |
| 370 | CollectionTimeScope::point}, |
| 371 | {tstring::CollectionDuration::str(), 0}}, |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 372 | {{tstring::SensorPath::str(), |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 373 | {{{tstring::Service::str(), "Service"}, |
| 374 | {tstring::Path::str(), |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 375 | "/xyz/openbmc_project/sensors/power/p2"}, |
| 376 | {tstring::Metadata::str(), "metadata2"}}}}, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 377 | {tstring::OperationType::str(), OperationType::single}, |
| 378 | {tstring::Id::str(), "MetricId2"}, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 379 | {tstring::CollectionTimeScope::str(), |
| 380 | CollectionTimeScope::point}, |
| 381 | {tstring::CollectionDuration::str(), 0}}})))); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 382 | |
| 383 | TEST_P(TestReportStore, settingPersistencyToTrueStoresReport) |
| 384 | { |
| 385 | sut = makeReport(ReportParams()); |
| 386 | |
| 387 | { |
| 388 | InSequence seq; |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 389 | EXPECT_CALL(storageMock, remove(to_file_path(sut->getId()))); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 390 | EXPECT_CALL(checkPoint, Call()); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 391 | EXPECT_CALL(storageMock, store(to_file_path(sut->getId()), _)) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 392 | .WillOnce(SaveArg<1>(&storedConfiguration)); |
| 393 | } |
| 394 | |
| 395 | setProperty(sut->getPath(), "Persistency", false); |
| 396 | checkPoint.Call(); |
| 397 | setProperty(sut->getPath(), "Persistency", true); |
| 398 | |
| 399 | const auto& [key, value] = GetParam(); |
| 400 | |
| 401 | ASSERT_THAT(storedConfiguration.at(key), Eq(value)); |
| 402 | } |
| 403 | |
| 404 | TEST_P(TestReportStore, reportIsSavedToStorageAfterCreated) |
| 405 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 406 | EXPECT_CALL(storageMock, store(to_file_path(ReportParams().reportId()), _)) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 407 | .WillOnce(SaveArg<1>(&storedConfiguration)); |
| 408 | |
| 409 | sut = makeReport(ReportParams()); |
| 410 | |
| 411 | const auto& [key, value] = GetParam(); |
| 412 | |
| 413 | ASSERT_THAT(storedConfiguration.at(key), Eq(value)); |
| 414 | } |
| 415 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 416 | class TestReportValidNames : |
| 417 | public TestReport, |
| 418 | public WithParamInterface<ReportParams> |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 419 | { |
| 420 | public: |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 421 | void SetUp() override |
| 422 | {} |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 423 | }; |
| 424 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 425 | INSTANTIATE_TEST_SUITE_P( |
| 426 | ValidNames, TestReportValidNames, |
| 427 | Values(ReportParams().reportName("Valid_1"), |
| 428 | ReportParams().reportName("Valid_1/Valid_2"), |
| 429 | ReportParams().reportName("Valid_1/Valid_2/Valid_3"))); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 430 | |
| 431 | TEST_P(TestReportValidNames, reportCtorDoesNotThrowOnValidName) |
| 432 | { |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 433 | EXPECT_NO_THROW(makeReport(GetParam())); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 434 | } |
| 435 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 436 | class TestReportInvalidIds : |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 437 | public TestReport, |
| 438 | public WithParamInterface<ReportParams> |
| 439 | { |
| 440 | public: |
| 441 | void SetUp() override |
| 442 | {} |
| 443 | }; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 444 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 445 | INSTANTIATE_TEST_SUITE_P(InvalidNames, TestReportInvalidIds, |
| 446 | Values(ReportParams().reportId("/"), |
| 447 | ReportParams().reportId("/Invalid"), |
| 448 | ReportParams().reportId("Invalid/"), |
| 449 | ReportParams().reportId("Invalid/Invalid/"), |
| 450 | ReportParams().reportId("Invalid?"))); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 451 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 452 | TEST_P(TestReportInvalidIds, failsToCreateReportWithInvalidName) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 453 | { |
| 454 | EXPECT_CALL(storageMock, store).Times(0); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 455 | |
| 456 | EXPECT_THROW(makeReport(GetParam()), sdbusplus::exception::SdBusError); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 457 | } |
| 458 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 459 | class TestReportAllReportTypes : |
| 460 | public TestReport, |
| 461 | public WithParamInterface<ReportParams> |
| 462 | { |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 463 | public: |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 464 | void SetUp() override |
| 465 | { |
| 466 | sut = makeReport(GetParam()); |
| 467 | } |
| 468 | }; |
| 469 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 470 | INSTANTIATE_TEST_SUITE_P( |
| 471 | _, TestReportAllReportTypes, |
| 472 | Values(ReportParams().reportingType(ReportingType::onRequest), |
| 473 | ReportParams().reportingType(ReportingType::onChange), |
| 474 | ReportParams().reportingType(ReportingType::periodic))); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 475 | |
| 476 | TEST_P(TestReportAllReportTypes, returnPropertValueOfReportType) |
| 477 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 478 | EXPECT_THAT(utils::toReportingType( |
| 479 | getProperty<std::string>(sut->getPath(), "ReportingType")), |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 480 | Eq(GetParam().reportingType())); |
| 481 | } |
| 482 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 483 | TEST_P(TestReportAllReportTypes, readingsAreUpdated) |
| 484 | { |
| 485 | clockFake.system.advance(10ms); |
| 486 | |
| 487 | messanger.send(messages::UpdateReportInd{{sut->getId()}}); |
| 488 | const auto [timestamp, readings] = |
| 489 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 490 | |
| 491 | EXPECT_THAT(Milliseconds{timestamp}, Eq(systemTimestamp + 10ms)); |
| 492 | } |
| 493 | |
| 494 | TEST_P(TestReportAllReportTypes, readingsAreNotUpdatedWhenReportIsDisabled) |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 495 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 496 | clockFake.system.advance(10ms); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 497 | |
| 498 | setProperty(sut->getPath(), "Enabled", false); |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 499 | messanger.send(messages::UpdateReportInd{{sut->getId()}}); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 500 | const auto [timestamp, readings] = |
| 501 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 502 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 503 | EXPECT_THAT(Milliseconds{timestamp}, Eq(0ms)); |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 504 | } |
| 505 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 506 | TEST_P(TestReportAllReportTypes, readingsAreNotUpdatedWhenReportIdDiffers) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 507 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 508 | clockFake.system.advance(10ms); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 509 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 510 | messanger.send(messages::UpdateReportInd{{sut->getId() + "x"s}}); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 511 | const auto [timestamp, readings] = |
| 512 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 513 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 514 | EXPECT_THAT(Milliseconds{timestamp}, Eq(0ms)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 515 | } |
| 516 | |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 517 | class TestReportOnRequestType : public TestReport |
| 518 | { |
| 519 | void SetUp() override |
| 520 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 521 | sut = |
| 522 | makeReport(ReportParams().reportingType(ReportingType::onRequest)); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 523 | } |
| 524 | }; |
| 525 | |
| 526 | TEST_F(TestReportOnRequestType, updatesReadingTimestamp) |
| 527 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 528 | clockFake.system.advance(10ms); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 529 | |
| 530 | ASSERT_THAT(update(sut->getPath()), Eq(boost::system::errc::success)); |
| 531 | |
| 532 | const auto [timestamp, readings] = |
| 533 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 534 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 535 | EXPECT_THAT(Milliseconds{timestamp}, Eq(systemTimestamp + 10ms)); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | TEST_F(TestReportOnRequestType, updatesReadingWhenUpdateIsCalled) |
| 539 | { |
| 540 | ASSERT_THAT(update(sut->getPath()), Eq(boost::system::errc::success)); |
| 541 | |
| 542 | const auto [timestamp, readings] = |
| 543 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 544 | |
| 545 | EXPECT_THAT(readings, |
| 546 | ElementsAre(std::make_tuple("a"s, "b"s, 17.1, 114u), |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 547 | std::make_tuple("aa"s, "bb"s, 42.0, 74u))); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | class TestReportNonOnRequestType : |
| 551 | public TestReport, |
| 552 | public WithParamInterface<ReportParams> |
| 553 | { |
| 554 | void SetUp() override |
| 555 | { |
| 556 | sut = makeReport(GetParam()); |
| 557 | } |
| 558 | }; |
| 559 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 560 | INSTANTIATE_TEST_SUITE_P( |
| 561 | _, TestReportNonOnRequestType, |
| 562 | Values(ReportParams().reportingType(ReportingType::periodic), |
| 563 | ReportParams().reportingType(ReportingType::onChange))); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 564 | |
| 565 | TEST_P(TestReportNonOnRequestType, readingsAreNotUpdateOnUpdateCall) |
| 566 | { |
| 567 | ASSERT_THAT(update(sut->getPath()), Eq(boost::system::errc::success)); |
| 568 | |
| 569 | EXPECT_THAT(getProperty<Readings>(sut->getPath(), "Readings"), |
| 570 | Eq(Readings{})); |
| 571 | } |
| 572 | |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 573 | class TestReportNonPeriodicReport : |
| 574 | public TestReport, |
| 575 | public WithParamInterface<ReportParams> |
| 576 | { |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 577 | public: |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 578 | void SetUp() override |
| 579 | { |
| 580 | sut = makeReport(GetParam()); |
| 581 | } |
| 582 | }; |
| 583 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 584 | INSTANTIATE_TEST_SUITE_P( |
| 585 | _, TestReportNonPeriodicReport, |
| 586 | Values(ReportParams().reportingType(ReportingType::onRequest), |
| 587 | ReportParams().reportingType(ReportingType::onChange))); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 588 | |
| 589 | TEST_P(TestReportNonPeriodicReport, readingsAreNotUpdatedAfterIntervalExpires) |
| 590 | { |
| 591 | DbusEnvironment::sleepFor(ReportManager::minInterval + 1ms); |
| 592 | |
| 593 | EXPECT_THAT(getProperty<Readings>(sut->getPath(), "Readings"), |
| 594 | Eq(Readings{})); |
| 595 | } |
| 596 | |
| 597 | class TestReportPeriodicReport : public TestReport |
| 598 | { |
| 599 | void SetUp() override |
| 600 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 601 | sut = makeReport(ReportParams().reportingType(ReportingType::periodic)); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 602 | } |
| 603 | }; |
| 604 | |
| 605 | TEST_F(TestReportPeriodicReport, readingTimestampIsUpdatedAfterIntervalExpires) |
| 606 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 607 | clockFake.system.advance(10ms); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 608 | DbusEnvironment::sleepFor(ReportManager::minInterval + 1ms); |
| 609 | |
| 610 | const auto [timestamp, readings] = |
| 611 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 612 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 613 | EXPECT_THAT(Milliseconds{timestamp}, Eq(systemTimestamp + 10ms)); |
Krzysztof Grobelny | c8e3a64 | 2020-10-23 12:29:16 +0200 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | TEST_F(TestReportPeriodicReport, readingsAreUpdatedAfterIntervalExpires) |
| 617 | { |
| 618 | DbusEnvironment::sleepFor(ReportManager::minInterval + 1ms); |
| 619 | |
| 620 | const auto [timestamp, readings] = |
| 621 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 622 | |
| 623 | EXPECT_THAT(readings, |
| 624 | ElementsAre(std::make_tuple("a"s, "b"s, 17.1, 114u), |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 625 | std::make_tuple("aa"s, "bb"s, 42.0, 74u))); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 626 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 627 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 628 | struct ReportUpdatesReportParams |
| 629 | { |
| 630 | ReportParams reportParams; |
| 631 | std::vector<ReadingData> expectedReadings; |
| 632 | bool expectedEnabled; |
| 633 | }; |
| 634 | |
| 635 | class TestReportWithReportUpdatesAndLimit : |
| 636 | public TestReport, |
| 637 | public WithParamInterface<ReportUpdatesReportParams> |
| 638 | { |
| 639 | void SetUp() override |
| 640 | { |
| 641 | sut = makeReport(ReportParams(GetParam().reportParams) |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 642 | .reportingType(ReportingType::periodic) |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 643 | .interval(std::chrono::hours(1000))); |
| 644 | } |
| 645 | }; |
| 646 | |
| 647 | INSTANTIATE_TEST_SUITE_P( |
| 648 | _, TestReportWithReportUpdatesAndLimit, |
| 649 | Values( |
| 650 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 651 | ReportParams() |
| 652 | .reportUpdates(ReportUpdates::appendWrapsWhenFull) |
| 653 | .appendLimit(5), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 654 | std::vector<ReadingData>{{std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 655 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 656 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 657 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 658 | std::make_tuple("a"s, "b"s, 17.1, 114u)}}, |
| 659 | true}, |
| 660 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 661 | ReportParams() |
| 662 | .reportUpdates(ReportUpdates::appendWrapsWhenFull) |
| 663 | .appendLimit(4), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 664 | std::vector<ReadingData>{ |
| 665 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 666 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 667 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 668 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 669 | true}, |
| 670 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 671 | ReportParams() |
| 672 | .reportUpdates(ReportUpdates::appendWrapsWhenFull) |
| 673 | .appendLimit(0), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 674 | std::vector<ReadingData>{}, true}, |
| 675 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 676 | ReportParams() |
| 677 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 678 | .appendLimit(10), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 679 | std::vector<ReadingData>{ |
| 680 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 681 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 682 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 683 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 684 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 685 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 686 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 687 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 688 | true}, |
| 689 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 690 | ReportParams() |
| 691 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 692 | .appendLimit(5), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 693 | std::vector<ReadingData>{{std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 694 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 695 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 696 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 697 | std::make_tuple("a"s, "b"s, 17.1, 114u)}}, |
| 698 | false}, |
| 699 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 700 | ReportParams() |
| 701 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 702 | .appendLimit(4), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 703 | std::vector<ReadingData>{ |
| 704 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 705 | std::make_tuple("aa"s, "bb"s, 42.0, 74u), |
| 706 | std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 707 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 708 | false}, |
| 709 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 710 | ReportParams() |
| 711 | .reportUpdates(ReportUpdates::appendStopsWhenFull) |
| 712 | .appendLimit(0), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 713 | std::vector<ReadingData>{}, false}, |
| 714 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 715 | ReportParams() |
| 716 | .reportUpdates(ReportUpdates::overwrite) |
| 717 | .appendLimit(500), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 718 | std::vector<ReadingData>{ |
| 719 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 720 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 721 | true}, |
| 722 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 723 | ReportParams() |
| 724 | .reportUpdates(ReportUpdates::overwrite) |
| 725 | .appendLimit(1), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 726 | std::vector<ReadingData>{ |
| 727 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 728 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 729 | true}, |
| 730 | ReportUpdatesReportParams{ |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 731 | ReportParams() |
| 732 | .reportUpdates(ReportUpdates::overwrite) |
| 733 | .appendLimit(0), |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 734 | std::vector<ReadingData>{ |
| 735 | {std::make_tuple("a"s, "b"s, 17.1, 114u), |
| 736 | std::make_tuple("aa"s, "bb"s, 42.0, 74u)}}, |
| 737 | true})); |
| 738 | |
| 739 | TEST_P(TestReportWithReportUpdatesAndLimit, |
| 740 | readingsAreUpdatedAfterIntervalExpires) |
| 741 | { |
| 742 | for (int i = 0; i < 4; i++) |
| 743 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 744 | messanger.send(messages::UpdateReportInd{{sut->getId()}}); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | const auto [timestamp, readings] = |
| 748 | getProperty<Readings>(sut->getPath(), "Readings"); |
| 749 | const auto enabled = getProperty<bool>(sut->getPath(), "Enabled"); |
| 750 | |
| 751 | EXPECT_THAT(readings, ElementsAreArray(GetParam().expectedReadings)); |
| 752 | EXPECT_EQ(enabled, GetParam().expectedEnabled); |
| 753 | } |
| 754 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 755 | class TestReportInitialization : public TestReport |
| 756 | { |
| 757 | public: |
| 758 | void SetUp() override |
| 759 | {} |
| 760 | |
| 761 | void monitorProc(sdbusplus::message::message& msg) |
| 762 | { |
| 763 | std::string iface; |
| 764 | std::vector<std::pair<std::string, std::variant<Readings>>> |
| 765 | changed_properties; |
| 766 | std::vector<std::string> invalidated_properties; |
| 767 | |
| 768 | msg.read(iface, changed_properties, invalidated_properties); |
| 769 | |
| 770 | if (iface == Report::reportIfaceName) |
| 771 | { |
| 772 | for (const auto& [name, value] : changed_properties) |
| 773 | { |
| 774 | if (name == "Readings") |
| 775 | { |
| 776 | readingsUpdated.Call(); |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | void makeMonitor() |
| 783 | { |
Patrick Williams | 3a62ee1 | 2021-12-03 10:13:25 -0600 | [diff] [blame] | 784 | monitor = std::make_unique<sdbusplus::bus::match_t>( |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 785 | *DbusEnvironment::getBus(), |
| 786 | sdbusplus::bus::match::rules::propertiesChanged( |
| 787 | sut->getPath(), Report::reportIfaceName), |
| 788 | [this](auto& msg) { monitorProc(msg); }); |
| 789 | } |
| 790 | |
Patrick Williams | 3a62ee1 | 2021-12-03 10:13:25 -0600 | [diff] [blame] | 791 | std::unique_ptr<sdbusplus::bus::match_t> monitor; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 792 | MockFunction<void()> readingsUpdated; |
| 793 | }; |
| 794 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 795 | TEST_F(TestReportInitialization, |
| 796 | metricsAreInitializedWhenEnabledReportConstructed) |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 797 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 798 | initMetricMocks(defaultParams.metricParameters()); |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 799 | for (auto& metric : metricMocks) |
| 800 | { |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 801 | EXPECT_CALL(*metric, initialize()).Times(1); |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 802 | } |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 803 | sut = makeReport(defaultParams.enabled(true)); |
| 804 | } |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 805 | |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 806 | TEST_F(TestReportInitialization, |
| 807 | metricsAreNotInitializedWhenDisabledReportConstructed) |
| 808 | { |
| 809 | initMetricMocks(defaultParams.metricParameters()); |
| 810 | for (auto& metric : metricMocks) |
| 811 | { |
| 812 | EXPECT_CALL(*metric, initialize()).Times(0); |
| 813 | } |
| 814 | sut = makeReport(defaultParams.enabled(false)); |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 815 | } |
| 816 | |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 817 | TEST_F(TestReportInitialization, |
| 818 | emitReadingsUpdateIsTrueReadingsPropertiesChangedSingalEmits) |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 819 | { |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 820 | EXPECT_CALL(readingsUpdated, Call()) |
| 821 | .WillOnce( |
| 822 | InvokeWithoutArgs(DbusEnvironment::setPromise("readingsUpdated"))); |
| 823 | |
| 824 | const auto elapsed = DbusEnvironment::measureTime([this] { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 825 | sut = |
| 826 | makeReport(defaultParams.reportingType(ReportingType::periodic) |
| 827 | .reportActions({ReportAction::emitsReadingsUpdate})); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 828 | makeMonitor(); |
| 829 | EXPECT_TRUE(DbusEnvironment::waitForFuture("readingsUpdated")); |
| 830 | }); |
| 831 | |
| 832 | EXPECT_THAT(elapsed, AllOf(Ge(defaultParams.interval()), |
| 833 | Lt(defaultParams.interval() * 2))); |
| 834 | } |
| 835 | |
| 836 | TEST_F(TestReportInitialization, |
| 837 | emitReadingsUpdateIsFalseReadingsPropertiesChangesSigalDoesNotEmits) |
| 838 | { |
| 839 | EXPECT_CALL(readingsUpdated, Call()).Times(0); |
| 840 | |
| 841 | sut = makeReport( |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 842 | defaultParams.reportingType(ReportingType::periodic).reportActions({})); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 843 | makeMonitor(); |
Wludzik, Jozef | b1ff1f6 | 2020-10-23 13:20:52 +0200 | [diff] [blame] | 844 | DbusEnvironment::sleepFor(defaultParams.interval() * 2); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 845 | } |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 846 | |
| 847 | TEST_F(TestReportInitialization, appendLimitDeducedProperly) |
| 848 | { |
| 849 | sut = makeReport( |
| 850 | ReportParams().appendLimit(std::numeric_limits<uint64_t>::max())); |
| 851 | auto appendLimit = getProperty<uint64_t>(sut->getPath(), "AppendLimit"); |
| 852 | EXPECT_EQ(appendLimit, 2ull); |
| 853 | } |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 854 | |
| 855 | TEST_F(TestReportInitialization, appendLimitSetToUintMaxIsStoredCorrectly) |
| 856 | { |
| 857 | nlohmann::json storedConfiguration; |
| 858 | |
| 859 | EXPECT_CALL(storageMock, store(to_file_path(ReportParams().reportId()), _)) |
| 860 | .WillOnce(SaveArg<1>(&storedConfiguration)); |
| 861 | |
| 862 | sut = makeReport( |
| 863 | ReportParams().appendLimit(std::numeric_limits<uint64_t>::max())); |
| 864 | |
| 865 | ASSERT_THAT(storedConfiguration.at("AppendLimit"), |
| 866 | Eq(std::numeric_limits<uint64_t>::max())); |
| 867 | } |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 868 | |
| 869 | TEST_F(TestReportInitialization, triggerIdsPropertyIsInitialzed) |
| 870 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame^] | 871 | for (const auto& triggerId : {"trigger1", "trigger2"}) |
| 872 | { |
| 873 | messanger.on_receive<messages::CollectTriggerIdReq>( |
| 874 | [&](const auto& msg) { |
| 875 | messanger.send(messages::CollectTriggerIdResp{triggerId}); |
| 876 | }); |
| 877 | } |
| 878 | |
| 879 | sut = makeReport(ReportParams()); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 880 | |
| 881 | EXPECT_THAT( |
| 882 | getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"), |
| 883 | UnorderedElementsAre("trigger1", "trigger2")); |
| 884 | } |