|
| 1 | +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | + |
| 3 | +/* Fluent Bit |
| 4 | + * ========== |
| 5 | + * Copyright (C) 2015-2026 The Fluent Bit Authors |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#include <fluent-bit/flb_config.h> |
| 21 | +#include <fluent-bit/flb_pipe.h> |
| 22 | +#include <fluent-bit/flb_scheduler.h> |
| 23 | + |
| 24 | +#include "flb_tests_internal.h" |
| 25 | + |
| 26 | +static void test_scheduler_event_channel_cleanup(void) |
| 27 | +{ |
| 28 | + int ret; |
| 29 | + char data = '\0'; |
| 30 | + flb_pipefd_t read_fd; |
| 31 | + flb_pipefd_t write_fd; |
| 32 | + struct flb_sched *sched; |
| 33 | + struct flb_config *config; |
| 34 | +#ifdef FLB_SYSTEM_WINDOWS |
| 35 | + WSADATA wsa_data; |
| 36 | + |
| 37 | + ret = WSAStartup(MAKEWORD(2, 2), &wsa_data); |
| 38 | + if (!TEST_CHECK(ret == 0)) { |
| 39 | + return; |
| 40 | + } |
| 41 | +#endif |
| 42 | + |
| 43 | + config = flb_config_init(); |
| 44 | + if (!TEST_CHECK(config != NULL)) { |
| 45 | + goto socket_cleanup; |
| 46 | + } |
| 47 | + |
| 48 | + config->evl = mk_event_loop_create(8); |
| 49 | + if (!TEST_CHECK(config->evl != NULL)) { |
| 50 | + flb_config_exit(config); |
| 51 | + goto socket_cleanup; |
| 52 | + } |
| 53 | + |
| 54 | + sched = flb_sched_create(config, config->evl); |
| 55 | + if (!TEST_CHECK(sched != NULL)) { |
| 56 | + flb_config_exit(config); |
| 57 | + goto socket_cleanup; |
| 58 | + } |
| 59 | + config->sched = sched; |
| 60 | + |
| 61 | + read_fd = sched->ch_events[0]; |
| 62 | + write_fd = sched->ch_events[1]; |
| 63 | + |
| 64 | + flb_sched_destroy(sched); |
| 65 | + config->sched = NULL; |
| 66 | + |
| 67 | + ret = flb_pipe_w(write_fd, &data, sizeof(data)); |
| 68 | + TEST_CHECK(ret == -1); |
| 69 | + |
| 70 | + ret = flb_pipe_r(read_fd, &data, sizeof(data)); |
| 71 | + TEST_CHECK(ret == -1); |
| 72 | + |
| 73 | + flb_config_exit(config); |
| 74 | + |
| 75 | +socket_cleanup: |
| 76 | + (void) ret; |
| 77 | +#ifdef FLB_SYSTEM_WINDOWS |
| 78 | + WSACleanup(); |
| 79 | +#endif |
| 80 | +} |
| 81 | + |
| 82 | +TEST_LIST = { |
| 83 | + {"event_channel_cleanup", test_scheduler_event_channel_cleanup}, |
| 84 | + {NULL, NULL} |
| 85 | +}; |
0 commit comments