Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 1 | #ifndef _AOS_EVENTS_EVENT_LOOP_PARAM_TEST_H_ |
| 2 | #define _AOS_EVENTS_EVENT_LOOP_PARAM_TEST_H_ |
| 3 | |
Brian Silverman | 4f4e061 | 2020-08-12 19:54:41 -0700 | [diff] [blame] | 4 | #include <initializer_list> |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 5 | #include <string_view> |
Neil Balch | 229001a | 2018-01-07 18:22:52 -0800 | [diff] [blame] | 6 | #include <vector> |
| 7 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 8 | #include "gtest/gtest.h" |
| 9 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 10 | #include "aos/events/event_loop.h" |
Brian Silverman | 4f4e061 | 2020-08-12 19:54:41 -0700 | [diff] [blame] | 11 | #include "aos/events/test_message_generated.h" |
Austin Schuh | a9df9ad | 2021-06-16 14:49:39 -0700 | [diff] [blame] | 12 | #include "aos/events/test_message_schema.h" |
| 13 | #include "aos/events/timing_report_schema.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 14 | #include "aos/flatbuffers.h" |
| 15 | #include "aos/json_to_flatbuffer.h" |
Austin Schuh | a9df9ad | 2021-06-16 14:49:39 -0700 | [diff] [blame] | 16 | #include "aos/logging/log_message_schema.h" |
| 17 | #include "aos/network/message_bridge_client_schema.h" |
| 18 | #include "aos/network/message_bridge_server_schema.h" |
| 19 | #include "aos/network/timestamp_schema.h" |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 20 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 21 | namespace aos::testing { |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 22 | |
| 23 | class EventLoopTestFactory { |
| 24 | public: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 25 | EventLoopTestFactory() |
Austin Schuh | a9df9ad | 2021-06-16 14:49:39 -0700 | [diff] [blame] | 26 | : flatbuffer_(configuration::AddSchema( |
| 27 | R"config({ |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 28 | "channels": [ |
| 29 | { |
| 30 | "name": "/aos", |
| 31 | "type": "aos.logging.LogMessageFbs" |
| 32 | }, |
| 33 | { |
| 34 | "name": "/aos", |
| 35 | "type": "aos.timing.Report" |
| 36 | }, |
| 37 | { |
| 38 | "name": "/test", |
milind | 945708b | 2021-07-03 13:30:15 -0700 | [diff] [blame] | 39 | "type": "aos.TestMessage", |
| 40 | "frequency": 800 |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 41 | }, |
| 42 | { |
| 43 | "name": "/test1", |
| 44 | "type": "aos.TestMessage" |
| 45 | }, |
| 46 | { |
| 47 | "name": "/test2", |
| 48 | "type": "aos.TestMessage" |
Austin Schuh | dda6db7 | 2023-06-21 17:02:34 -0700 | [diff] [blame] | 49 | }, |
| 50 | { |
| 51 | "name": "/test3", |
| 52 | "type": "aos.TestMessage", |
| 53 | "channel_storage_duration": 10000000000 |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 54 | } |
| 55 | ] |
Austin Schuh | a9df9ad | 2021-06-16 14:49:39 -0700 | [diff] [blame] | 56 | })config", |
| 57 | {aos::FlatbufferSpan<reflection::Schema>( |
| 58 | logging::LogMessageFbsSchema()), |
| 59 | aos::FlatbufferSpan<reflection::Schema>(timing::ReportSchema()), |
| 60 | aos::FlatbufferSpan<reflection::Schema>(TestMessageSchema())})) {} |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 61 | |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 62 | virtual ~EventLoopTestFactory() {} |
| 63 | |
Austin Schuh | 44019f9 | 2019-05-19 19:58:27 -0700 | [diff] [blame] | 64 | // Makes a connected event loop. |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 65 | virtual std::unique_ptr<EventLoop> Make(std::string_view name) = 0; |
Austin Schuh | 44019f9 | 2019-05-19 19:58:27 -0700 | [diff] [blame] | 66 | // Makes a primary event loop. This is the one the tests will try to use for |
| 67 | // anything blocking. |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 68 | virtual std::unique_ptr<EventLoop> MakePrimary(std::string_view name) = 0; |
Austin Schuh | 44019f9 | 2019-05-19 19:58:27 -0700 | [diff] [blame] | 69 | |
| 70 | // Runs the loops until they quit. |
| 71 | virtual void Run() = 0; |
Austin Schuh | 52d325c | 2019-06-23 18:59:06 -0700 | [diff] [blame] | 72 | |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 73 | // Quits the loops. |
| 74 | virtual void Exit() = 0; |
| 75 | |
Austin Schuh | 52d325c | 2019-06-23 18:59:06 -0700 | [diff] [blame] | 76 | // Advances time by sleeping. Can't be called from inside a loop. |
| 77 | virtual void SleepFor(::std::chrono::nanoseconds duration) = 0; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 78 | |
Austin Schuh | d54780b | 2020-10-03 16:26:02 -0700 | [diff] [blame] | 79 | // Sets the config to a config with a max size with an invalid alignment. |
| 80 | void InvalidChannelAlignment() { |
Austin Schuh | a9df9ad | 2021-06-16 14:49:39 -0700 | [diff] [blame] | 81 | flatbuffer_ = configuration::AddSchema( |
| 82 | R"config({ |
Austin Schuh | d54780b | 2020-10-03 16:26:02 -0700 | [diff] [blame] | 83 | "channels": [ |
| 84 | { |
| 85 | "name": "/aos", |
| 86 | "type": "aos.logging.LogMessageFbs" |
| 87 | }, |
| 88 | { |
| 89 | "name": "/aos", |
| 90 | "type": "aos.timing.Report" |
| 91 | }, |
| 92 | { |
| 93 | "name": "/test", |
| 94 | "type": "aos.TestMessage", |
| 95 | "max_size": 13 |
| 96 | }, |
| 97 | { |
| 98 | "name": "/test1", |
| 99 | "type": "aos.TestMessage" |
| 100 | }, |
| 101 | { |
| 102 | "name": "/test2", |
| 103 | "type": "aos.TestMessage" |
Austin Schuh | dda6db7 | 2023-06-21 17:02:34 -0700 | [diff] [blame] | 104 | }, |
| 105 | { |
| 106 | "name": "/test3", |
| 107 | "type": "aos.TestMessage", |
| 108 | "channel_storage_duration": 10000000000 |
Austin Schuh | d54780b | 2020-10-03 16:26:02 -0700 | [diff] [blame] | 109 | } |
| 110 | ] |
Austin Schuh | a9df9ad | 2021-06-16 14:49:39 -0700 | [diff] [blame] | 111 | })config", |
| 112 | {aos::FlatbufferSpan<reflection::Schema>( |
| 113 | logging::LogMessageFbsSchema()), |
| 114 | aos::FlatbufferSpan<reflection::Schema>(timing::ReportSchema()), |
| 115 | aos::FlatbufferSpan<reflection::Schema>(TestMessageSchema())}); |
Austin Schuh | d54780b | 2020-10-03 16:26:02 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 118 | void PinReads() { |
| 119 | static const std::string kJson = R"config({ |
| 120 | "channels": [ |
| 121 | { |
| 122 | "name": "/aos", |
| 123 | "type": "aos.logging.LogMessageFbs", |
| 124 | "read_method": "PIN", |
| 125 | "num_readers": 10 |
| 126 | }, |
| 127 | { |
| 128 | "name": "/aos", |
| 129 | "type": "aos.timing.Report", |
| 130 | "read_method": "PIN", |
| 131 | "num_readers": 10 |
| 132 | }, |
| 133 | { |
| 134 | "name": "/test", |
| 135 | "type": "aos.TestMessage", |
| 136 | "read_method": "PIN", |
milind | 945708b | 2021-07-03 13:30:15 -0700 | [diff] [blame] | 137 | "num_readers": 10, |
| 138 | "frequency": 800 |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 139 | }, |
| 140 | { |
| 141 | "name": "/test1", |
| 142 | "type": "aos.TestMessage", |
| 143 | "read_method": "PIN", |
| 144 | "num_readers": 10 |
| 145 | }, |
| 146 | { |
| 147 | "name": "/test2", |
| 148 | "type": "aos.TestMessage", |
| 149 | "read_method": "PIN", |
| 150 | "num_readers": 10 |
Austin Schuh | dda6db7 | 2023-06-21 17:02:34 -0700 | [diff] [blame] | 151 | }, |
| 152 | { |
| 153 | "name": "/test3", |
| 154 | "type": "aos.TestMessage", |
| 155 | "read_method": "PIN", |
| 156 | "num_readers": 10, |
| 157 | "channel_storage_duration": 10000000000 |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 158 | } |
| 159 | ] |
| 160 | })config"; |
| 161 | |
Austin Schuh | a9df9ad | 2021-06-16 14:49:39 -0700 | [diff] [blame] | 162 | flatbuffer_ = configuration::AddSchema( |
| 163 | kJson, {aos::FlatbufferSpan<reflection::Schema>( |
| 164 | logging::LogMessageFbsSchema()), |
| 165 | aos::FlatbufferSpan<reflection::Schema>(timing::ReportSchema()), |
| 166 | aos::FlatbufferSpan<reflection::Schema>(TestMessageSchema())}); |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 169 | void EnableNodes(std::string_view my_node) { |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 170 | static const std::string kJson = R"config({ |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 171 | "channels": [ |
| 172 | { |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 173 | "name": "/me/aos", |
Tyler Chatow | 67ddb03 | 2020-01-12 14:30:04 -0800 | [diff] [blame] | 174 | "type": "aos.logging.LogMessageFbs", |
| 175 | "source_node": "me" |
| 176 | }, |
| 177 | { |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 178 | "name": "/them/aos", |
Tyler Chatow | 67ddb03 | 2020-01-12 14:30:04 -0800 | [diff] [blame] | 179 | "type": "aos.logging.LogMessageFbs", |
| 180 | "source_node": "them" |
| 181 | }, |
| 182 | { |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 183 | "name": "/me/aos", |
| 184 | "type": "aos.message_bridge.Timestamp", |
| 185 | "source_node": "me", |
| 186 | "destination_nodes": [ |
| 187 | { |
| 188 | "name": "them" |
| 189 | } |
| 190 | ] |
| 191 | }, |
| 192 | { |
| 193 | "name": "/them/aos", |
| 194 | "type": "aos.message_bridge.Timestamp", |
| 195 | "source_node": "them", |
| 196 | "destination_nodes": [ |
| 197 | { |
| 198 | "name": "me" |
| 199 | } |
| 200 | ] |
| 201 | }, |
| 202 | { |
| 203 | "name": "/me/aos", |
| 204 | "type": "aos.message_bridge.ServerStatistics", |
| 205 | "source_node": "me", |
| 206 | "frequency": 2 |
| 207 | }, |
| 208 | { |
| 209 | "name": "/them/aos", |
| 210 | "type": "aos.message_bridge.ServerStatistics", |
| 211 | "source_node": "them", |
| 212 | "frequency": 2 |
| 213 | }, |
| 214 | { |
| 215 | "name": "/me/aos", |
| 216 | "type": "aos.message_bridge.ClientStatistics", |
| 217 | "source_node": "me", |
| 218 | "frequency": 2 |
| 219 | }, |
| 220 | { |
| 221 | "name": "/them/aos", |
| 222 | "type": "aos.message_bridge.ClientStatistics", |
| 223 | "source_node": "them", |
| 224 | "frequency": 2 |
| 225 | }, |
| 226 | { |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 227 | "name": "/aos", |
| 228 | "type": "aos.timing.Report", |
| 229 | "source_node": "me" |
| 230 | }, |
| 231 | { |
| 232 | "name": "/test", |
| 233 | "type": "aos.TestMessage", |
| 234 | "source_node": "me" |
| 235 | }, |
| 236 | { |
| 237 | "name": "/test1", |
| 238 | "type": "aos.TestMessage", |
| 239 | "source_node": "me" |
| 240 | }, |
| 241 | { |
| 242 | "name": "/test2", |
| 243 | "type": "aos.TestMessage", |
| 244 | "source_node": "me" |
Brian Silverman | 631b626 | 2021-11-10 12:25:08 -0800 | [diff] [blame] | 245 | }, |
| 246 | { |
| 247 | "name": "/test_forward", |
| 248 | "type": "aos.TestMessage", |
| 249 | "source_node": "them", |
| 250 | "destination_nodes": [ |
| 251 | { |
| 252 | "name": "me" |
| 253 | } |
| 254 | ] |
| 255 | }, |
| 256 | { |
| 257 | "name": "/test_noforward", |
| 258 | "type": "aos.TestMessage", |
| 259 | "source_node": "them" |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 260 | } |
| 261 | ], |
| 262 | "nodes": [ |
| 263 | { |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 264 | "name": "me", |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 265 | "hostname": "myhostname" |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 266 | }, |
| 267 | { |
| 268 | "name": "them", |
| 269 | "hostname": "themhostname" |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 270 | } |
Tyler Chatow | 67ddb03 | 2020-01-12 14:30:04 -0800 | [diff] [blame] | 271 | ], |
| 272 | "maps": [ |
| 273 | { |
| 274 | "match": { |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 275 | "name": "/aos*", |
Tyler Chatow | 67ddb03 | 2020-01-12 14:30:04 -0800 | [diff] [blame] | 276 | "source_node": "me" |
| 277 | }, |
| 278 | "rename": { |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 279 | "name": "/me/aos" |
Tyler Chatow | 67ddb03 | 2020-01-12 14:30:04 -0800 | [diff] [blame] | 280 | } |
| 281 | }, |
| 282 | { |
| 283 | "match": { |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 284 | "name": "/aos*", |
Tyler Chatow | 67ddb03 | 2020-01-12 14:30:04 -0800 | [diff] [blame] | 285 | "source_node": "them" |
| 286 | }, |
| 287 | "rename": { |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 288 | "name": "/them/aos" |
Tyler Chatow | 67ddb03 | 2020-01-12 14:30:04 -0800 | [diff] [blame] | 289 | } |
| 290 | } |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 291 | ] |
| 292 | })config"; |
| 293 | |
Austin Schuh | 4c3b970 | 2020-08-30 11:34:55 -0700 | [diff] [blame] | 294 | flatbuffer_ = configuration::MergeConfiguration( |
Austin Schuh | a9df9ad | 2021-06-16 14:49:39 -0700 | [diff] [blame] | 295 | configuration::MergeConfiguration( |
| 296 | aos::FlatbufferDetachedBuffer<Configuration>( |
| 297 | JsonToFlatbuffer<Configuration>(kJson))), |
| 298 | {aos::FlatbufferSpan<reflection::Schema>( |
| 299 | logging::LogMessageFbsSchema()), |
| 300 | aos::FlatbufferSpan<reflection::Schema>(timing::ReportSchema()), |
| 301 | aos::FlatbufferSpan<reflection::Schema>(TestMessageSchema()), |
| 302 | aos::FlatbufferSpan<reflection::Schema>( |
| 303 | message_bridge::ClientStatisticsSchema()), |
| 304 | aos::FlatbufferSpan<reflection::Schema>( |
| 305 | message_bridge::ServerStatisticsSchema()), |
| 306 | aos::FlatbufferSpan<reflection::Schema>( |
| 307 | message_bridge::TimestampSchema())}); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 308 | |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 309 | my_node_ = configuration::GetNode(&flatbuffer_.message(), my_node); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 312 | const Node *my_node() const { return my_node_; } |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 313 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 314 | const Configuration *configuration() { return &flatbuffer_.message(); } |
| 315 | |
| 316 | private: |
| 317 | FlatbufferDetachedBuffer<Configuration> flatbuffer_; |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 318 | |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 319 | const Node *my_node_ = nullptr; |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 320 | }; |
| 321 | |
Austin Schuh | 6bae825 | 2021-02-07 22:01:49 -0800 | [diff] [blame] | 322 | enum class DoTimingReports { kYes, kNo }; |
| 323 | |
Brian Silverman | 4f4e061 | 2020-08-12 19:54:41 -0700 | [diff] [blame] | 324 | class AbstractEventLoopTest |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 325 | : public ::testing::TestWithParam< |
Austin Schuh | 6bae825 | 2021-02-07 22:01:49 -0800 | [diff] [blame] | 326 | std::tuple<std::function<EventLoopTestFactory *()>, ReadMethod, |
| 327 | DoTimingReports>> { |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 328 | public: |
Brian Silverman | 4f4e061 | 2020-08-12 19:54:41 -0700 | [diff] [blame] | 329 | AbstractEventLoopTest() : factory_(std::get<0>(GetParam())()) { |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 330 | if (read_method() == ReadMethod::PIN) { |
| 331 | factory_->PinReads(); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | ReadMethod read_method() const { return std::get<1>(GetParam()); } |
Austin Schuh | 6bae825 | 2021-02-07 22:01:49 -0800 | [diff] [blame] | 336 | DoTimingReports do_timing_reports() const { return std::get<2>(GetParam()); } |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 337 | |
Brian Silverman | 4f4e061 | 2020-08-12 19:54:41 -0700 | [diff] [blame] | 338 | ::std::unique_ptr<EventLoop> Make(std::string_view name = ""); |
| 339 | |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 340 | ::std::unique_ptr<EventLoop> MakePrimary(std::string_view name = "primary") { |
| 341 | ++event_loop_count_; |
Austin Schuh | 6bae825 | 2021-02-07 22:01:49 -0800 | [diff] [blame] | 342 | auto result = factory_->MakePrimary(name); |
| 343 | if (do_timing_reports() == DoTimingReports::kNo) { |
| 344 | result->SkipTimingReport(); |
| 345 | } |
| 346 | return result; |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 347 | } |
Austin Schuh | 44019f9 | 2019-05-19 19:58:27 -0700 | [diff] [blame] | 348 | |
Austin Schuh | d54780b | 2020-10-03 16:26:02 -0700 | [diff] [blame] | 349 | void InvalidChannelAlignment() { factory_->InvalidChannelAlignment(); } |
| 350 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 351 | void EnableNodes(std::string_view my_node) { factory_->EnableNodes(my_node); } |
| 352 | |
Austin Schuh | 44019f9 | 2019-05-19 19:58:27 -0700 | [diff] [blame] | 353 | void Run() { return factory_->Run(); } |
Austin Schuh | 52d325c | 2019-06-23 18:59:06 -0700 | [diff] [blame] | 354 | |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 355 | void Exit() { return factory_->Exit(); } |
| 356 | |
Austin Schuh | 52d325c | 2019-06-23 18:59:06 -0700 | [diff] [blame] | 357 | void SleepFor(::std::chrono::nanoseconds duration) { |
| 358 | return factory_->SleepFor(duration); |
| 359 | } |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 360 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 361 | const Configuration *configuration() { return factory_->configuration(); } |
| 362 | |
Austin Schuh | ac0771c | 2020-01-07 18:36:30 -0800 | [diff] [blame] | 363 | const Node *my_node() const { return factory_->my_node(); } |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 364 | |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 365 | // Ends the given event loop at the given time from now. |
| 366 | void EndEventLoop(EventLoop *loop, ::std::chrono::milliseconds duration) { |
| 367 | auto end_timer = loop->AddTimer([this]() { this->Exit(); }); |
Philipp Schrader | a671252 | 2023-07-05 20:25:11 -0700 | [diff] [blame] | 368 | end_timer->Schedule(loop->monotonic_now() + duration); |
Austin Schuh | 39788ff | 2019-12-01 18:22:57 -0800 | [diff] [blame] | 369 | end_timer->set_name("end"); |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Brian Silverman | 4f4e061 | 2020-08-12 19:54:41 -0700 | [diff] [blame] | 372 | // Verifies that the buffer_index values for all of the given objects are |
| 373 | // consistent. |
| 374 | void VerifyBuffers( |
| 375 | int number_buffers, |
| 376 | std::vector<std::reference_wrapper<const Fetcher<TestMessage>>> fetchers, |
| 377 | std::vector<std::reference_wrapper<const Sender<TestMessage>>> senders); |
| 378 | |
Eric Schmiedeberg | ef44b8a | 2022-02-28 17:30:38 -0700 | [diff] [blame] | 379 | // Helper function for testing the sent too fast check using a PhasedLoop with |
| 380 | // an interval that sends exactly at the frequency of the channel |
| 381 | void TestSentTooFastCheckEdgeCase( |
| 382 | const std::function<RawSender::Error(int, int)> expected_err, |
| 383 | const bool send_twice_at_end); |
| 384 | |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 385 | private: |
Brian Silverman | 7716297 | 2020-08-12 19:52:40 -0700 | [diff] [blame] | 386 | const ::std::unique_ptr<EventLoopTestFactory> factory_; |
Austin Schuh | 5f1cc5c | 2019-12-01 18:01:11 -0800 | [diff] [blame] | 387 | |
| 388 | int event_loop_count_ = 0; |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 389 | }; |
| 390 | |
Brian Silverman | 4f4e061 | 2020-08-12 19:54:41 -0700 | [diff] [blame] | 391 | using AbstractEventLoopDeathTest = AbstractEventLoopTest; |
Austin Schuh | 6b6dfa5 | 2019-06-12 20:16:20 -0700 | [diff] [blame] | 392 | |
Eric Schmiedeberg | ef44b8a | 2022-02-28 17:30:38 -0700 | [diff] [blame] | 393 | // Returns the frequency of the /test TestMessage channel |
| 394 | int TestChannelFrequency(EventLoop *event_loop); |
| 395 | // Returns the queue size of the /test TestMessage channel |
| 396 | int TestChannelQueueSize(EventLoop *event_loop); |
| 397 | // Sends a test message with value 0 with the given sender |
| 398 | RawSender::Error SendTestMessage(aos::Sender<TestMessage> &sender); |
| 399 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 400 | } // namespace aos::testing |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 401 | |
| 402 | #endif // _AOS_EVENTS_EVENT_LOOP_PARAM_TEST_H_ |