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