From 8cf6fa0ce2d12e7bcdd944267869937585beb396 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Thu, 22 Jan 2026 13:20:17 +0300 Subject: [PATCH 1/2] tests: internal: input_chunk_routes: Windows support Signed-off-by: Marat Abrarov --- tests/include/flb_tests_tmpdir.h | 79 ++++++++++++++++++++++++++ tests/internal/flb_tests_internal.h.in | 2 + tests/internal/input_chunk_routes.c | 53 +++++++++++++---- 3 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 tests/include/flb_tests_tmpdir.h diff --git a/tests/include/flb_tests_tmpdir.h b/tests/include/flb_tests_tmpdir.h new file mode 100644 index 00000000000..34c69e1f697 --- /dev/null +++ b/tests/include/flb_tests_tmpdir.h @@ -0,0 +1,79 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Fluent Bit + * ========== + * Copyright (C) 2015-2026 The Fluent Bit Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLB_TESTS_TMPDIR_H +#define FLB_TESTS_TMPDIR_H + +#include +#include +#include +#include + +static inline char* flb_test_env_tmpdir() +{ + char *env; + + /* Unix */ + env = getenv("TMPDIR"); + if (env) { + return flb_strdup(env); + } + + /* Windows */ + env = getenv("TEMP"); + if (env) { + return flb_strdup(env); + } + env = getenv("TMP"); + if (env) { + return flb_strdup(env); + } + + /* Fallback */ + return flb_strdup("/tmp"); +} + +static inline char* flb_test_tmpdir_cat(const char *postfix) +{ + char *tmpdir; + char *ret; + size_t tmpdir_len; + size_t postfix_len; + + tmpdir = flb_test_env_tmpdir(); + if (!tmpdir) { + return NULL; + } + + tmpdir_len = strlen(tmpdir); + postfix_len = strlen(postfix); + ret = (char *) flb_malloc(tmpdir_len + postfix_len + 1); + if (!ret) { + flb_free(tmpdir); + return NULL; + } + + memcpy(ret, tmpdir, tmpdir_len); + flb_free(tmpdir); + memcpy(ret + tmpdir_len, postfix, postfix_len); + ret[tmpdir_len + postfix_len] = '\0'; + return ret; +} + +#endif diff --git a/tests/internal/flb_tests_internal.h.in b/tests/internal/flb_tests_internal.h.in index 82a8cd8ccc5..859624ae0bb 100644 --- a/tests/internal/flb_tests_internal.h.in +++ b/tests/internal/flb_tests_internal.h.in @@ -37,6 +37,8 @@ static inline void fini_nop() {}; #define TEST_FINI { flb_test_env_config_destroy(); } #endif +#include "../include/flb_tests_tmpdir.h" + #include "../lib/acutest/acutest.h" #define FLB_TESTS_DATA_PATH "@FLB_TESTS_DATA_PATH@" diff --git a/tests/internal/input_chunk_routes.c b/tests/internal/input_chunk_routes.c index acd1ae2dd8e..7c26ba1e808 100644 --- a/tests/internal/input_chunk_routes.c +++ b/tests/internal/input_chunk_routes.c @@ -30,9 +30,9 @@ #include -#define TEST_STREAM_PATH "/tmp/flb-chunk-direct-test" -#define TEST_STREAM_PATH_MATCH "/tmp/flb-chunk-direct-test-match" -#define TEST_STREAM_PATH_NULL "/tmp/flb-chunk-direct-test-null" +#define TEST_STREAM_PATH "/flb-chunk-direct-test" +#define TEST_STREAM_PATH_MATCH "/flb-chunk-direct-test-match" +#define TEST_STREAM_PATH_NULL "/flb-chunk-direct-test-null" static int write_test_log_payload(struct cio_chunk *chunk) { @@ -341,6 +341,7 @@ static void test_chunk_metadata_direct_routes() struct flb_input_chunk ic; struct flb_chunk_direct_route output_routes[2]; struct flb_chunk_direct_route *loaded_routes; + char *stream_path; char *content_buf; const char *tag_buf; const char *tag_string; @@ -353,18 +354,25 @@ static void test_chunk_metadata_direct_routes() size_t content_size; size_t payload_size; + stream_path = flb_test_tmpdir_cat(TEST_STREAM_PATH); + TEST_CHECK(stream_path != NULL); + if (!stream_path) { + return; + } + payload_size = sizeof(payload) - 1; tag_string = "test.tag"; expected_tag_len = strlen(tag_string); - cio_utils_recursive_delete(TEST_STREAM_PATH); + cio_utils_recursive_delete(stream_path); memset(&opts, 0, sizeof(opts)); cio_options_init(&opts); - opts.root_path = TEST_STREAM_PATH; + opts.root_path = stream_path; opts.flags = CIO_OPEN; ctx = cio_create(&opts); TEST_CHECK(ctx != NULL); if (!ctx) { + flb_free(stream_path); return; } @@ -372,6 +380,7 @@ static void test_chunk_metadata_direct_routes() TEST_CHECK(stream != NULL); if (!stream) { cio_destroy(ctx); + flb_free(stream_path); return; } @@ -379,6 +388,7 @@ static void test_chunk_metadata_direct_routes() TEST_CHECK(chunk != NULL); if (!chunk) { cio_destroy(ctx); + flb_free(stream_path); return; } @@ -478,7 +488,8 @@ static void test_chunk_metadata_direct_routes() cio_chunk_close(chunk, CIO_TRUE); cio_destroy(ctx); - cio_utils_recursive_delete(TEST_STREAM_PATH); + cio_utils_recursive_delete(stream_path); + flb_free(stream_path); } static void test_chunk_restore_alias_plugin_match_multiple() @@ -497,12 +508,19 @@ static void test_chunk_restore_alias_plugin_match_multiple() struct flb_output_plugin stdout_plugin; struct flb_output_plugin http_plugin; struct flb_chunk_direct_route route; + char *stream_path; const char *tag_string; int tag_len; int ret; int err; int config_ready; + stream_path = flb_test_tmpdir_cat(TEST_STREAM_PATH_MATCH); + TEST_CHECK(stream_path != NULL); + if (!stream_path) { + return; + } + ctx = NULL; stream = NULL; chunk = NULL; @@ -511,15 +529,16 @@ static void test_chunk_restore_alias_plugin_match_multiple() tag_string = "test.tag"; tag_len = (int) strlen(tag_string); - cio_utils_recursive_delete(TEST_STREAM_PATH_MATCH); + cio_utils_recursive_delete(stream_path); memset(&opts, 0, sizeof(opts)); cio_options_init(&opts); - opts.root_path = TEST_STREAM_PATH_MATCH; + opts.root_path = stream_path; opts.flags = CIO_OPEN; ctx = cio_create(&opts); TEST_CHECK(ctx != NULL); if (!ctx) { + flb_free(stream_path); return; } @@ -639,7 +658,8 @@ static void test_chunk_restore_alias_plugin_match_multiple() cleanup: cleanup_test_routing_scenario(ic, &stdout_one, &stdout_two, &http_out, &in, &config, chunk, ctx, config_ready, - TEST_STREAM_PATH_MATCH); + stream_path); + flb_free(stream_path); } static void test_chunk_restore_alias_plugin_null_matches_all() @@ -658,12 +678,19 @@ static void test_chunk_restore_alias_plugin_null_matches_all() struct flb_output_plugin stdout_plugin; struct flb_output_plugin http_plugin; struct flb_chunk_direct_route route; + char *stream_path; const char *tag_string; int tag_len; int ret; int err; int config_ready; + stream_path = flb_test_tmpdir_cat(TEST_STREAM_PATH_NULL); + TEST_CHECK(stream_path != NULL); + if (!stream_path) { + return; + } + ctx = NULL; stream = NULL; chunk = NULL; @@ -672,15 +699,16 @@ static void test_chunk_restore_alias_plugin_null_matches_all() tag_string = "test.tag"; tag_len = (int) strlen(tag_string); - cio_utils_recursive_delete(TEST_STREAM_PATH_NULL); + cio_utils_recursive_delete(stream_path); memset(&opts, 0, sizeof(opts)); cio_options_init(&opts); - opts.root_path = TEST_STREAM_PATH_NULL; + opts.root_path = stream_path; opts.flags = CIO_OPEN; ctx = cio_create(&opts); TEST_CHECK(ctx != NULL); if (!ctx) { + flb_free(stream_path); return; } @@ -800,7 +828,8 @@ static void test_chunk_restore_alias_plugin_null_matches_all() cleanup: cleanup_test_routing_scenario(ic, &stdout_one, &stdout_two, &http_out, &in, &config, chunk, ctx, config_ready, - TEST_STREAM_PATH_NULL); + stream_path); + flb_free(stream_path); } TEST_LIST = { From a340cc5265ddfd392e4833d39f19d74ae4455bc5 Mon Sep 17 00:00:00 2001 From: Marat Abrarov Date: Mon, 26 Jan 2026 12:32:42 +0300 Subject: [PATCH 2/2] tests: internal: input_chunk: Windows support when generating temporary dir Signed-off-by: Marat Abrarov --- tests/internal/input_chunk.c | 42 +++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/tests/internal/input_chunk.c b/tests/internal/input_chunk.c index 773eb03cf9c..99f8826635a 100644 --- a/tests/internal/input_chunk.c +++ b/tests/internal/input_chunk.c @@ -162,8 +162,18 @@ void do_test(char *system, const char *target, ...) int out_ffd; char path[PATH_MAX]; struct tail_test_result result = {0}; + char *tmpdir; char storage_path[PATH_MAX]; + tmpdir = flb_test_env_tmpdir(); + TEST_CHECK(tmpdir != NULL); + if (!tmpdir) { + return; + } + snprintf(storage_path, sizeof(storage_path) - 1, "%s/input-chunk-test-%s", + tmpdir, target); + flb_free(tmpdir); + result.nMatched = 0; result.target = target; @@ -176,8 +186,6 @@ void do_test(char *system, const char *target, ...) ctx = flb_create(); - snprintf(storage_path, sizeof(storage_path) - 1, "/tmp/input-chunk-test-%s", target); - /* create chunks in /tmp folder */ ret = flb_service_set(ctx, "Parsers_File", DPATH "parser.conf", @@ -258,6 +266,13 @@ void flb_test_input_chunk_dropping_chunks() struct mk_list *head; struct flb_input_chunk *ic; struct flb_task *task; + char *storage_path; + + storage_path = flb_test_tmpdir_cat("/input-chunk-test/"); + TEST_CHECK(storage_path != NULL); + if (!storage_path) { + return; + } /* Create context, flush every second (some checks omitted here) */ ctx = flb_create(); @@ -265,7 +280,7 @@ void flb_test_input_chunk_dropping_chunks() /* create chunks in /tmp folder */ ret = flb_service_set(ctx, "flush", "2", "grace", "1", - "storage.path", "/tmp/input-chunk-test/", + "storage.path", storage_path, "Log_Level", "error", NULL); @@ -307,6 +322,7 @@ void flb_test_input_chunk_dropping_chunks() flb_time_msleep(2100); flb_stop(ctx); flb_destroy(ctx); + flb_free(storage_path); } static int gen_buf(msgpack_sbuffer *mp_sbuf, char *buf, size_t buf_size) @@ -365,6 +381,13 @@ void flb_test_input_chunk_fs_chunks_size_real() char buf[262144]; struct mk_event_loop *evl; struct cio_options opts = {0}; + char *root_path; + + root_path = flb_test_tmpdir_cat("/input-chunk-fs_chunks-size_real"); + TEST_CHECK(root_path != NULL); + if (!root_path) { + return; + } flb_init_env(); cfg = flb_config_init(); @@ -380,7 +403,7 @@ void flb_test_input_chunk_fs_chunks_size_real() cio_options_init(&opts); - opts.root_path = "/tmp/input-chunk-fs_chunks-size_real"; + opts.root_path = root_path; opts.log_cb = log_cb; opts.log_level = CIO_LOG_DEBUG; opts.flags = CIO_OPEN; @@ -455,6 +478,7 @@ void flb_test_input_chunk_fs_chunks_size_real() flb_input_exit_all(cfg); flb_output_exit(cfg); flb_config_exit(cfg); + flb_free(root_path); } /* This tests uses the subsystems of the engine directly @@ -475,6 +499,13 @@ void flb_test_input_chunk_correct_total_records(void) char buf[262144]; struct mk_event_loop *evl; struct cio_options opts = {0}; + char *root_path; + + root_path = flb_test_tmpdir_cat("/input-chunk-fs_chunks-size_real"); + TEST_CHECK(root_path != NULL); + if (!root_path) { + return; + } flb_init_env(); cfg = flb_config_init(); @@ -490,7 +521,7 @@ void flb_test_input_chunk_correct_total_records(void) cio_options_init(&opts); - opts.root_path = "/tmp/input-chunk-fs_chunks-size_real"; + opts.root_path = root_path; opts.log_cb = log_cb; opts.log_level = CIO_LOG_DEBUG; opts.flags = CIO_OPEN; @@ -541,6 +572,7 @@ void flb_test_input_chunk_correct_total_records(void) flb_input_exit_all(cfg); flb_output_exit(cfg); flb_config_exit(cfg); + flb_free(root_path); }