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