|
7 | 7 | #include <fluent-bit/flb_network.h> |
8 | 8 | #include <fluent-bit/flb_socket.h> |
9 | 9 | #include <fluent-bit/flb_time.h> |
| 10 | +#include <fluent-bit/flb_coro.h> |
| 11 | +#include <fluent-bit/flb_downstream.h> |
10 | 12 |
|
11 | 13 | #include <time.h> |
12 | 14 | #include "flb_tests_internal.h" |
|
19 | 21 | #define TEST_EV_CLIENT MK_EVENT_NOTIFICATION |
20 | 22 | #define TEST_EV_SERVER MK_EVENT_CUSTOM |
21 | 23 |
|
| 24 | +struct parent_callback_context { |
| 25 | + struct flb_connection connection; |
| 26 | + struct flb_coro *parent_coro; |
| 27 | + int callback_on_parent; |
| 28 | + int callback_result; |
| 29 | + int coroutine_done; |
| 30 | +}; |
| 31 | + |
| 32 | +static int parent_callback(void *data) |
| 33 | +{ |
| 34 | + struct parent_callback_context *context; |
| 35 | + |
| 36 | + context = data; |
| 37 | + context->callback_on_parent = flb_coro_get() == context->parent_coro; |
| 38 | + |
| 39 | + return 73; |
| 40 | +} |
| 41 | + |
| 42 | +static void parent_callback_coro(void) |
| 43 | +{ |
| 44 | + struct flb_coro *coro; |
| 45 | + struct parent_callback_context *context; |
| 46 | + |
| 47 | + coro = flb_coro_get(); |
| 48 | + context = coro->data; |
| 49 | + |
| 50 | + context->callback_result = flb_downstream_conn_event_call_parent( |
| 51 | + &context->connection, |
| 52 | + parent_callback, |
| 53 | + context); |
| 54 | + context->coroutine_done = FLB_TRUE; |
| 55 | + |
| 56 | + while (FLB_TRUE) { |
| 57 | + flb_coro_yield(coro, FLB_FALSE); |
| 58 | + } |
| 59 | +} |
| 60 | + |
22 | 61 | static int socket_check_ok(flb_sockfd_t fd) |
23 | 62 | { |
24 | 63 | int ret; |
@@ -201,10 +240,55 @@ void test_accept_empty_nonblocking_listener() |
201 | 240 | flb_socket_close(fd_server); |
202 | 241 | } |
203 | 242 |
|
| 243 | +void test_downstream_event_callback_runs_on_parent_stack() |
| 244 | +{ |
| 245 | + size_t stack_size; |
| 246 | + struct flb_coro *coro; |
| 247 | + struct parent_callback_context context; |
| 248 | + |
| 249 | + memset(&context, 0, sizeof(context)); |
| 250 | + |
| 251 | + flb_coro_thread_init(); |
| 252 | + |
| 253 | + coro = flb_coro_create(&context); |
| 254 | + if (!TEST_CHECK(coro != NULL)) { |
| 255 | + return; |
| 256 | + } |
| 257 | + |
| 258 | + coro->caller = co_active(); |
| 259 | + coro->callee = co_create(test_env_config->coro_stack_size, |
| 260 | + parent_callback_coro, |
| 261 | + &stack_size); |
| 262 | + if (!TEST_CHECK(coro->callee != NULL)) { |
| 263 | + flb_coro_destroy(coro); |
| 264 | + return; |
| 265 | + } |
| 266 | + |
| 267 | +#ifdef FLB_HAVE_VALGRIND |
| 268 | + coro->valgrind_stack_id = VALGRIND_STACK_REGISTER( |
| 269 | + coro->callee, |
| 270 | + ((char *) coro->callee) + stack_size); |
| 271 | +#endif |
| 272 | + |
| 273 | + context.parent_coro = flb_coro_get(); |
| 274 | + context.connection.event_coroutine = coro; |
| 275 | + |
| 276 | + flb_downstream_conn_event_resume(&context.connection); |
| 277 | + |
| 278 | + TEST_CHECK(context.callback_on_parent == FLB_TRUE); |
| 279 | + TEST_CHECK(context.callback_result == 73); |
| 280 | + TEST_CHECK(context.coroutine_done == FLB_TRUE); |
| 281 | + |
| 282 | + context.connection.event_coroutine = NULL; |
| 283 | + flb_coro_destroy(coro); |
| 284 | +} |
| 285 | + |
204 | 286 | TEST_LIST = { |
205 | 287 | { "ipv4_client_server", test_ipv4_client_server}, |
206 | 288 | { "ipv6_client_server", test_ipv6_client_server}, |
207 | 289 | { "ipv6_bracketed_listen", test_ipv6_bracketed_listen}, |
208 | 290 | { "accept_empty_nonblocking_listener", test_accept_empty_nonblocking_listener}, |
| 291 | + { "downstream_event_callback_runs_on_parent_stack", |
| 292 | + test_downstream_event_callback_runs_on_parent_stack }, |
209 | 293 | { 0 } |
210 | 294 | }; |
0 commit comments