summaryrefslogtreecommitdiffstats
path: root/src/fluent-bit/tests/runtime/out_plot.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:19:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:07:37 +0000
commitb485aab7e71c1625cfc27e0f92c9509f42378458 (patch)
treeae9abe108601079d1679194de237c9a435ae5b55 /src/fluent-bit/tests/runtime/out_plot.c
parentAdding upstream version 1.44.3. (diff)
downloadnetdata-b485aab7e71c1625cfc27e0f92c9509f42378458.tar.xz
netdata-b485aab7e71c1625cfc27e0f92c9509f42378458.zip
Adding upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/fluent-bit/tests/runtime/out_plot.c')
-rw-r--r--src/fluent-bit/tests/runtime/out_plot.c157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/fluent-bit/tests/runtime/out_plot.c b/src/fluent-bit/tests/runtime/out_plot.c
new file mode 100644
index 000000000..67c841f2c
--- /dev/null
+++ b/src/fluent-bit/tests/runtime/out_plot.c
@@ -0,0 +1,157 @@
+/* -*- 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 */
+
+/* Test functions */
+void flb_test_plot_json_invalid(void);
+void flb_test_plot_json_multiple(void);
+void flb_test_plot_key_mismatch(void);
+
+/* Test list */
+TEST_LIST = {
+ {"json_invalid", flb_test_plot_json_invalid },
+ {"json_multiple", flb_test_plot_json_multiple },
+ {"key_mismatch", flb_test_plot_key_mismatch },
+ {NULL, NULL}
+};
+
+#define TEST_LOGFILE "flb_test_plot_dummy.log"
+#define TEST_TIMEOUT 5
+
+void flb_test_plot_json_invalid(void)
+{
+ int i;
+ int ret;
+ int bytes;
+ char *p = (char *) JSON_INVALID;
+ flb_ctx_t *ctx;
+ int in_ffd;
+ int out_ffd;
+
+ ctx = flb_create();
+
+ 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 *) "plot", NULL);
+ TEST_CHECK(out_ffd >= 0);
+ flb_output_set(ctx, out_ffd, "match", "test", NULL);
+
+ ret = flb_start(ctx);
+ TEST_CHECK(ret == 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);
+ }
+
+ flb_stop(ctx);
+ flb_destroy(ctx);
+}
+
+void flb_test_plot_json_multiple(void)
+{
+ int i;
+ int ret;
+ int bytes;
+ char p[100];
+ flb_ctx_t *ctx;
+ int in_ffd;
+ int out_ffd;
+ FILE *fp;
+
+ remove(TEST_LOGFILE);
+
+ ctx = flb_create();
+
+ 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 *) "plot", NULL);
+ TEST_CHECK(out_ffd >= 0);
+ flb_output_set(ctx, out_ffd, "match", "test", NULL);
+ flb_output_set(ctx, out_ffd, "key", "val", NULL);
+ flb_output_set(ctx, out_ffd, "file", TEST_LOGFILE, NULL);
+
+ ret = flb_start(ctx);
+ TEST_CHECK(ret == 0);
+
+ for (i = 0; i < 256; i++) {
+ memset(p, '\0', sizeof(p));
+ snprintf(p, sizeof(p), "[%d, {\"val\": %d,\"END_KEY\": \"JSON_END\"}]", i, (i * i));
+ bytes = flb_lib_push(ctx, in_ffd, p, strlen(p));
+ TEST_CHECK(bytes == strlen(p));
+ }
+
+ ret = wait_for_file(TEST_LOGFILE, 1, TEST_TIMEOUT);
+ TEST_CHECK(ret == 0);
+
+ flb_stop(ctx);
+ flb_destroy(ctx);
+
+ fp = fopen(TEST_LOGFILE, "r");
+ TEST_CHECK(fp != NULL);
+ if (fp != NULL) {
+ fseek(fp, 0L ,SEEK_END);
+ TEST_CHECK(ftell(fp) > 0); /* file_size > 0 */
+ fclose(fp);
+ remove(TEST_LOGFILE);
+ }
+}
+
+void flb_test_plot_key_mismatch(void)
+{
+ int i;
+ int ret;
+ int bytes;
+ char p[100];
+ flb_ctx_t *ctx;
+ int in_ffd;
+ int out_ffd;
+ FILE *fp;
+
+ remove(TEST_LOGFILE);
+
+ ctx = flb_create();
+
+ 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 *) "plot", NULL);
+ TEST_CHECK(out_ffd >= 0);
+ flb_output_set(ctx, out_ffd, "match", "test", NULL);
+ flb_output_set(ctx, out_ffd, "key", "xxx", NULL);
+ flb_output_set(ctx, out_ffd, "file", TEST_LOGFILE, NULL);
+
+ ret = flb_start(ctx);
+ TEST_CHECK(ret == 0);
+
+ for (i = 0; i < 256; i++) {
+ memset(p, '\0', sizeof(p));
+ snprintf(p, sizeof(p), "[%d, {\"val\": %d,\"END_KEY\": \"JSON_END\"}]", i, (i * i));
+ bytes = flb_lib_push(ctx, in_ffd, p, strlen(p));
+ TEST_CHECK(bytes == strlen(p));
+ }
+
+ ret = wait_for_file(TEST_LOGFILE, 1, TEST_TIMEOUT);
+ TEST_CHECK(ret == 0);
+
+ flb_stop(ctx);
+ flb_destroy(ctx);
+
+ fp = fopen(TEST_LOGFILE, "r");
+ TEST_CHECK(fp != NULL);
+ if (fp != NULL) {
+ fseek(fp, 0L ,SEEK_END);
+ TEST_CHECK(ftell(fp) == 0); /* file_size == 0 */
+ fclose(fp);
+ remove(TEST_LOGFILE);
+ }
+}