diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:20:02 +0000 |
commit | 58daab21cd043e1dc37024a7f99b396788372918 (patch) | |
tree | 96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /fluent-bit/lib/monkey/fuzz/mk_check.c | |
parent | Releasing debian version 1.43.2-1. (diff) | |
download | netdata-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/lib/monkey/fuzz/mk_check.c')
-rw-r--r-- | fluent-bit/lib/monkey/fuzz/mk_check.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/fluent-bit/lib/monkey/fuzz/mk_check.c b/fluent-bit/lib/monkey/fuzz/mk_check.c new file mode 100644 index 000000000..acae6cba0 --- /dev/null +++ b/fluent-bit/lib/monkey/fuzz/mk_check.c @@ -0,0 +1,113 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +#include <monkey/mk_lib.h> + +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include <unistd.h> + +#define API_ADDR "127.0.0.1" +#define API_PORT "8080" + +/* Main context set as global so the signal handler can use it */ +mk_ctx_t *ctx; + +void cb_main(mk_request_t *request, void *data) +{ + (void) data; + + mk_http_status(request, 200); + mk_http_header(request, "X-Monkey", 8, "OK", 2); + + mk_http_send(request, ":)\n", 3, NULL); + mk_http_done(request); +} + +void cb_test_chunks(mk_request_t *request, void *data) +{ + int i = 0; + int len; + char tmp[32]; + (void) data; + + mk_http_status(request, 200); + mk_http_header(request, "X-Monkey", 8, "OK", 2); + + for (i = 0; i < 1000; i++) { + len = snprintf(tmp, sizeof(tmp) -1, "test-chunk %6i\n ", i); + mk_http_send(request, tmp, len, NULL); + } + mk_http_done(request); +} + +void cb_test_big_chunk(mk_request_t *request, void *data) +{ + size_t chunk_size = 1024000000; + char *chunk; + (void) data; + + mk_http_status(request, 200); + mk_http_header(request, "X-Monkey", 8, "OK", 2); + + chunk = calloc(1, chunk_size); + mk_http_send(request, chunk, chunk_size, NULL); + free(chunk); + mk_http_done(request); +} + + +static void signal_handler(int signal) +{ + write(STDERR_FILENO, "[engine] caught signal\n", 23); + + switch (signal) { + case SIGTERM: + case SIGINT: + mk_stop(ctx); + mk_destroy(ctx); + _exit(EXIT_SUCCESS); + default: + break; + } +} + +static void signal_init() +{ + signal(SIGINT, &signal_handler); + signal(SIGTERM, &signal_handler); +} + +int main() +{ + int vid; + + signal_init(); + + ctx = mk_create(); + if (!ctx) { + return -1; + } + + mk_config_set(ctx, + "Listen", API_PORT, + NULL); + + vid = mk_vhost_create(ctx, NULL); + mk_vhost_set(ctx, vid, + "Name", "monotop", + NULL); + mk_vhost_handler(ctx, vid, "/test_chunks", cb_test_chunks, NULL); + mk_vhost_handler(ctx, vid, "/test_big_chunk", cb_test_big_chunk, NULL); + mk_vhost_handler(ctx, vid, "/", cb_main, NULL); + + mk_info("Service: http://%s:%s/test_chunks", API_ADDR, API_PORT); + mk_start(ctx); + + sleep(3600); + + mk_stop(ctx); + mk_destroy(ctx); + + return 0; +} |