|
| 1 | +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | + |
| 3 | +#include <fluent-bit/flb_info.h> |
| 4 | +#include <fluent-bit/flb_mem.h> |
| 5 | +#include <fluent-bit/flb_error.h> |
| 6 | +#include <fluent-bit/flb_socket.h> |
| 7 | +#include <fluent-bit/flb_task.h> |
| 8 | + |
| 9 | +#include "flb_tests_internal.h" |
| 10 | + |
| 11 | +#define TASK_COUNT_LIMIT (FLB_CONFIG_DEFAULT_TASK_MAP_SIZE_LIMIT + 1) |
| 12 | + |
| 13 | +struct test_ctx { |
| 14 | + struct flb_config *config; |
| 15 | +}; |
| 16 | + |
| 17 | +struct test_ctx* test_ctx_create() |
| 18 | +{ |
| 19 | + struct test_ctx *ret_ctx = NULL; |
| 20 | + |
| 21 | + ret_ctx = flb_calloc(1, sizeof(struct test_ctx)); |
| 22 | + if (!TEST_CHECK(ret_ctx != NULL)) { |
| 23 | + flb_errno(); |
| 24 | + TEST_MSG("flb_malloc(test_ctx) failed"); |
| 25 | + return NULL; |
| 26 | + } |
| 27 | + |
| 28 | + ret_ctx->config = flb_config_init(); |
| 29 | + if(!TEST_CHECK(ret_ctx->config != NULL)) { |
| 30 | + TEST_MSG("flb_config_init failed"); |
| 31 | + flb_free(ret_ctx); |
| 32 | + return NULL; |
| 33 | + } |
| 34 | + |
| 35 | + return ret_ctx; |
| 36 | +} |
| 37 | + |
| 38 | +int test_ctx_destroy(struct test_ctx* ctx) |
| 39 | +{ |
| 40 | + if (!TEST_CHECK(ctx != NULL)) { |
| 41 | + return -1; |
| 42 | + } |
| 43 | + |
| 44 | + if (ctx->config) { |
| 45 | + flb_config_exit(ctx->config); |
| 46 | + } |
| 47 | + |
| 48 | + flb_free(ctx); |
| 49 | + return 0; |
| 50 | +} |
| 51 | + |
| 52 | +void test_task_map_limit() |
| 53 | +{ |
| 54 | + struct test_ctx *ctx; |
| 55 | + ssize_t index; |
| 56 | + struct flb_task *tasks[TASK_COUNT_LIMIT]; |
| 57 | + int failure_detected; |
| 58 | + |
| 59 | + ctx = test_ctx_create(); |
| 60 | + |
| 61 | + if (!TEST_CHECK(ctx != NULL)) { |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + failure_detected = FLB_FALSE; |
| 66 | + |
| 67 | + for (index = 0 ; index < TASK_COUNT_LIMIT ; index++) { |
| 68 | + tasks[index] = task_alloc(ctx->config); |
| 69 | + |
| 70 | + if (tasks[index] == NULL) { |
| 71 | + failure_detected = FLB_TRUE; |
| 72 | + |
| 73 | + break; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + if (TEST_CHECK(failure_detected == FLB_TRUE)) { |
| 78 | + TEST_CHECK(index == FLB_CONFIG_DEFAULT_TASK_MAP_SIZE_LIMIT); |
| 79 | + } |
| 80 | + |
| 81 | + while (index >= 0) { |
| 82 | + if (tasks[index] != NULL) { |
| 83 | + flb_task_destroy(tasks[index], FLB_TRUE); |
| 84 | + } |
| 85 | + index--; |
| 86 | + } |
| 87 | + |
| 88 | + test_ctx_destroy(ctx); |
| 89 | +} |
| 90 | + |
| 91 | +TEST_LIST = { |
| 92 | + { "task_map_limit" , test_task_map_limit}, |
| 93 | + { 0 } |
| 94 | +}; |
0 commit comments