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 /web/server/h2o/libh2o/deps/libyrmcds/t/t.h | |
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 'web/server/h2o/libh2o/deps/libyrmcds/t/t.h')
-rw-r--r-- | web/server/h2o/libh2o/deps/libyrmcds/t/t.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/deps/libyrmcds/t/t.h b/web/server/h2o/libh2o/deps/libyrmcds/t/t.h new file mode 100644 index 000000000..fd79d59cd --- /dev/null +++ b/web/server/h2o/libh2o/deps/libyrmcds/t/t.h @@ -0,0 +1,75 @@ +// test utilities + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <yrmcds.h> + +static int n_failures = 0; + +static void check_error(yrmcds_error e) { + if( e == YRMCDS_OK ) + return; + + fprintf(stderr, "yrmcds error: %s\n", yrmcds_strerror(e)); + exit(1); +} + +static yrmcds* get_yrmcds(yrmcds* c) { + const char* host = getenv("YRMCDS_HOST"); + if( host == NULL ) { + return NULL; + } + uint16_t port = 11211; + if( getenv("YRMCDS_PORT") ) { + port = (uint16_t)atoi(getenv("YRMCDS_PORT")); + } + + check_error( yrmcds_connect(c, host, port) ); + return c; +} + +static void test_main(yrmcds* c); + +#define TEST_MAIN() static void test_main(yrmcds* c) + +int main(int argc, char** argv) { + yrmcds c_; + yrmcds* c = get_yrmcds(&c_); + if( c == NULL ) { + fprintf(stderr, "No YRMCDS_HOST. Skipped.\n"); + return 0; + } + + test_main(c); + yrmcds_close(c); + + if( n_failures > 0 ) { + fprintf(stderr, "%d tests failed.\n", n_failures); + return 1; + } + fprintf(stderr, "Passed.\n"); + return 0; +} + +#define DEF_TEST(name) void test_##name(yrmcds* c) + +#define CALL_TEST(name) \ + fprintf(stderr, "[%s]\n", #name); \ + test_##name(c); \ + uint32_t serial_##name; \ + check_error( yrmcds_flush(c, 0, 0, &serial_##name) ); \ + while( 1 ) { \ + yrmcds_response r; \ + check_error( yrmcds_recv(c, &r) ); \ + if( r.serial == serial_##name ) break; \ + } \ + sleep(1) + +#define ASSERT(expr, to_return) \ + if( ! (expr) ) { \ + fprintf(stderr, "assertion failure at line %d: %s\n", \ + __LINE__, #expr); \ + n_failures++; \ + if( to_return ) return; \ + } |