summaryrefslogtreecommitdiffstats
path: root/fluent-bit/tests/runtime/out_stdout.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:20:02 +0000
commit58daab21cd043e1dc37024a7f99b396788372918 (patch)
tree96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /fluent-bit/tests/runtime/out_stdout.c
parentReleasing debian version 1.43.2-1. (diff)
downloadnetdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz
netdata-58daab21cd043e1dc37024a7f99b396788372918.zip
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fluent-bit/tests/runtime/out_stdout.c')
-rw-r--r--fluent-bit/tests/runtime/out_stdout.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/fluent-bit/tests/runtime/out_stdout.c b/fluent-bit/tests/runtime/out_stdout.c
new file mode 100644
index 000000000..26182fbe9
--- /dev/null
+++ b/fluent-bit/tests/runtime/out_stdout.c
@@ -0,0 +1,138 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+#include <fluent-bit.h>
+#include "flb_tests_runtime.h"
+
+/* Test data */
+#include "data/common/json_invalid.h" /* JSON_INVALID */
+#include "data/common/json_long.h" /* JSON_LONG */
+#include "data/common/json_small.h" /* JSON_SMALL */
+
+/* Test functions */
+void flb_test_stdout_json_invalid(void);
+void flb_test_stdout_json_long(void);
+void flb_test_stdout_json_small(void);
+
+/* Test list */
+TEST_LIST = {
+ {"json_invalid", flb_test_stdout_json_invalid },
+ {"json_long", flb_test_stdout_json_long },
+ {"json_small", flb_test_stdout_json_small },
+ {NULL, NULL}
+};
+
+
+void flb_test_stdout_json_invalid(void)
+{
+ int i;
+ int ret;
+ int total;
+ int bytes;
+ char *p = (char *) JSON_INVALID;
+ flb_ctx_t *ctx;
+ int in_ffd;
+ int out_ffd;
+
+ ctx = flb_create();
+ flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
+
+ in_ffd = flb_input(ctx, (char *) "lib", NULL);
+ TEST_CHECK(in_ffd >= 0);
+ flb_input_set(ctx, in_ffd, "tag", "test", NULL);
+
+ out_ffd = flb_output(ctx, (char *) "stdout", NULL);
+ TEST_CHECK(out_ffd >= 0);
+ flb_output_set(ctx, out_ffd, "match", "test", NULL);
+
+ ret = flb_start(ctx);
+ TEST_CHECK(ret == 0);
+
+ total = 0;
+ for (i = 0; i < (int) sizeof(JSON_INVALID) - 1; i++) {
+ bytes = flb_lib_push(ctx, in_ffd, p + i, 1);
+ TEST_CHECK(bytes == 1);
+ total++;
+ }
+
+ sleep(1); /* waiting flush */
+
+ flb_stop(ctx);
+ flb_destroy(ctx);
+}
+
+/* It writes a very long JSON map (> 100KB) byte by byte */
+void flb_test_stdout_json_long(void)
+{
+ int i;
+ int ret;
+ int total;
+ int bytes;
+ char *p = (char *) JSON_LONG;
+ flb_ctx_t *ctx;
+ int in_ffd;
+ int out_ffd;
+
+ ctx = flb_create();
+ flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
+
+ in_ffd = flb_input(ctx, (char *) "lib", NULL);
+ TEST_CHECK(in_ffd >= 0);
+ flb_input_set(ctx, in_ffd, "tag", "test", NULL);
+
+ out_ffd = flb_output(ctx, (char *) "stdout", NULL);
+ TEST_CHECK(out_ffd >= 0);
+ flb_output_set(ctx, out_ffd, "match", "test", NULL);
+
+ ret = flb_start(ctx);
+ TEST_CHECK(ret == 0);
+
+ total = 0;
+ for (i = 0; i < (int) sizeof(JSON_LONG) - 1; i++) {
+ bytes = flb_lib_push(ctx, in_ffd, p + i, 1);
+ TEST_CHECK(bytes == 1);
+ total++;
+ }
+
+ sleep(1); /* waiting flush */
+
+ flb_stop(ctx);
+ flb_destroy(ctx);
+}
+
+void flb_test_stdout_json_small(void)
+{
+ int i;
+ int ret;
+ int total;
+ int bytes;
+ char *p = (char *) JSON_SMALL;
+ flb_ctx_t *ctx;
+ int in_ffd;
+ int out_ffd;
+
+ ctx = flb_create();
+ flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
+
+ in_ffd = flb_input(ctx, (char *) "lib", NULL);
+ TEST_CHECK(in_ffd >= 0);
+ flb_input_set(ctx, in_ffd, "tag", "test", NULL);
+
+ out_ffd = flb_output(ctx, (char *) "stdout", NULL);
+ TEST_CHECK(out_ffd >= 0);
+ flb_output_set(ctx, out_ffd, "match", "test", NULL);
+
+ ret = flb_start(ctx);
+ TEST_CHECK(ret == 0);
+
+ total = 0;
+ for (i = 0; i < (int) sizeof(JSON_SMALL) - 1; i++) {
+ bytes = flb_lib_push(ctx, in_ffd, p + i, 1);
+ TEST_CHECK(bytes == 1);
+ total++;
+ }
+
+ sleep(1); /* waiting flush */
+
+ flb_stop(ctx);
+ flb_destroy(ctx);
+}