X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Funit%2Ftest_utils_compat_poll.cpp;h=eb6d94a5eedb876bb39d25deb1645c7c2cc68733;hp=697440963c58279514129e0515b00d425d75eb61;hb=HEAD;hpb=1524f98c04431d04e50796f83a9dd29184b3a8a4 diff --git a/tests/unit/test_utils_compat_poll.cpp b/tests/unit/test_utils_compat_poll.cpp index 697440963..6c865b298 100644 --- a/tests/unit/test_utils_compat_poll.cpp +++ b/tests/unit/test_utils_compat_poll.cpp @@ -9,27 +9,27 @@ * */ +#include +#include +#include +#include + #include #include #include -#include #include #include - #include - -#include -#include -#include -#include +#include /* Verification without trashing test order in the child process */ -#define childok(e, test, ...) do { \ - if (!(e)) { \ - diag(test, ## __VA_ARGS__); \ - _exit(EXIT_FAILURE); \ - } \ -} while(0) +#define childok(e, test, ...) \ + do { \ + if (!(e)) { \ + diag(test, ##__VA_ARGS__); \ + _exit(EXIT_FAILURE); \ + } \ + } while (0) /* For error.h */ int lttng_opt_quiet = 1; @@ -56,8 +56,7 @@ int lttng_opt_mi; #define CLOE_VALUE FD_CLOEXEC #endif -static -void test_epoll_compat(void) +static void test_epoll_compat() { /* * Type conversion present to disable warning of anonymous enum from @@ -67,14 +66,14 @@ void test_epoll_compat(void) } #endif -static void test_alloc(void) +static void test_alloc() { struct lttng_poll_event poll_events; lttng_poll_init(&poll_events); /* Null pointer */ - ok(lttng_poll_create(NULL, 1, 0) != 0, "Create over NULL pointer fails"); + ok(lttng_poll_create(nullptr, 1, 0) != 0, "Create over NULL pointer fails"); /* Size 0 */ ok(lttng_poll_create(&poll_events, 0, 0) != 0, "Create with size 0 fails"); /* without CLOEXEC */ @@ -88,19 +87,20 @@ static void test_alloc(void) } /* Tests stuff related to what would be handled with epoll_ctl. */ -static void test_add_del(void) +static void test_add_del() { struct lttng_poll_event poll_events; lttng_poll_init(&poll_events); - ok(lttng_poll_add(NULL, 1, LPOLLIN) != 0, "Adding to NULL set fails"); - ok(lttng_poll_add(&poll_events, 1, LPOLLIN) != 0, "Adding to uninitialized structure fails"); + ok(lttng_poll_add(nullptr, 1, LPOLLIN) != 0, "Adding to NULL set fails"); + ok(lttng_poll_add(&poll_events, 1, LPOLLIN) != 0, + "Adding to uninitialized structure fails"); ok(lttng_poll_add(&poll_events, -1, LPOLLIN) != 0, "Adding invalid FD fails"); ok(lttng_poll_create(&poll_events, 1, 0) == 0, "Create a poll set succeeds"); ok(LTTNG_POLL_GETNB(&poll_events) == 0, "Set created empty"); - ok(lttng_poll_add(NULL, 1, LPOLLIN) != 0, "Adding to NULL set fails"); + ok(lttng_poll_add(nullptr, 1, LPOLLIN) != 0, "Adding to NULL set fails"); ok(LTTNG_POLL_GETNB(&poll_events) == 0, "Set still empty"); ok(lttng_poll_add(&poll_events, -1, LPOLLIN) != 0, "Adding invalid FD fails"); ok(LTTNG_POLL_GETNB(&poll_events) == 0, "Set still empty"); @@ -108,7 +108,7 @@ static void test_add_del(void) ok(lttng_poll_add(&poll_events, 1, LPOLLIN) == 0, "Adding valid FD succeeds"); ok(LTTNG_POLL_GETNB(&poll_events) == 1, "Nb of elements incremented"); - ok(lttng_poll_del(NULL, 1) != 0, "Removing from NULL set fails"); + ok(lttng_poll_del(nullptr, 1) != 0, "Removing from NULL set fails"); ok(LTTNG_POLL_GETNB(&poll_events) == 1, "Number of FD in set unchanged"); ok(lttng_poll_del(&poll_events, -1) != 0, "Removing from negative FD fails"); @@ -126,7 +126,7 @@ static void test_add_del(void) lttng_poll_clean(&poll_events); } -static void test_mod_wait(void) +static void test_mod_wait() { struct lttng_poll_event poll_events; struct lttng_poll_event cpoll_events; @@ -144,13 +144,20 @@ static void test_mod_wait(void) cpid = fork(); if (cpid == 0) { - childok(lttng_poll_create(&cpoll_events, 1, 0) == 0, "Create valid poll set succeeds"); - childok(lttng_poll_mod(NULL, infd[0], LPOLLIN) == -1, "lttng_poll_mod with invalid input returns an error"); - childok(lttng_poll_mod(&cpoll_events, infd[0], LPOLLIN) == -1, "lttng_poll_mod with invalid input returns an error"); - childok(lttng_poll_add(&cpoll_events, infd[0], LPOLLIN) == 0, "Add valid FD succeeds"); - childok(lttng_poll_mod(&cpoll_events, -1, LPOLLIN) == -1, "lttng_poll_mod with invalid input returns an error"); - childok(lttng_poll_mod(&cpoll_events, hupfd[0], LPOLLIN) == 0, "lttng_poll_mod on unincluded FD goes on"); - childok(lttng_poll_mod(&cpoll_events, infd[0], LPOLLIN) == 0, "Modify event type succeeds"); + childok(lttng_poll_create(&cpoll_events, 1, 0) == 0, + "Create valid poll set succeeds"); + childok(lttng_poll_mod(nullptr, infd[0], LPOLLIN) == -1, + "lttng_poll_mod with invalid input returns an error"); + childok(lttng_poll_mod(&cpoll_events, infd[0], LPOLLIN) == -1, + "lttng_poll_mod with invalid input returns an error"); + childok(lttng_poll_add(&cpoll_events, infd[0], LPOLLIN) == 0, + "Add valid FD succeeds"); + childok(lttng_poll_mod(&cpoll_events, -1, LPOLLIN) == -1, + "lttng_poll_mod with invalid input returns an error"); + childok(lttng_poll_mod(&cpoll_events, hupfd[0], LPOLLIN) == 0, + "lttng_poll_mod on unincluded FD goes on"); + childok(lttng_poll_mod(&cpoll_events, infd[0], LPOLLIN) == 0, + "Modify event type succeeds"); childok(close(infd[1]) == 0, "Close valid FD succeeds"); childok(lttng_poll_wait(&cpoll_events, -1) == 1, "Wait on close times out"); childok(lttng_read(infd[0], &rbuf, 1) == 1, "Data is present in the pipe"); @@ -165,10 +172,12 @@ static void test_mod_wait(void) ok(close(hupfd[1]) == 0, "Close valid FD succeeds"); ok(close(infd[0]) == 0, "Close valid FD succeeds"); - ok(lttng_poll_wait(NULL, -1) == -1, "lttng_poll_wait call with invalid input returns error"); + ok(lttng_poll_wait(nullptr, -1) == -1, + "lttng_poll_wait call with invalid input returns error"); ok(lttng_poll_create(&poll_events, 1, 0) == 0, "Create valid poll set succeeds"); - ok(lttng_poll_wait(&poll_events, -1) == -1, "lttng_poll_wait call with invalid input returns error"); + ok(lttng_poll_wait(&poll_events, -1) == -1, + "lttng_poll_wait call with invalid input returns error"); ok(lttng_poll_add(&poll_events, hupfd[0], LPOLLIN) == 0, "Add valid FD succeeds"); ok(lttng_write(infd[1], &tbuf, 1) == 1, "Write to pipe succeeds"); ok(lttng_poll_wait(&poll_events, -1) == 1, "Wakes up on one event"); @@ -187,23 +196,21 @@ static void destroy_pipe(void *pipe) lttng_pipe_destroy((lttng_pipe *) pipe); } -static int run_active_set_combination(unsigned int fd_count, - unsigned int active_fds_mask) +static int run_active_set_combination(unsigned int fd_count, unsigned int active_fds_mask) { int ret = 0; unsigned int i; const unsigned int active_fds_count = __builtin_popcount(active_fds_mask); struct lttng_poll_event poll_events; struct lttng_dynamic_pointer_array pipes; - struct lttng_pipe *pipe = NULL; + struct lttng_pipe *pipe = nullptr; lttng_poll_init(&poll_events); lttng_dynamic_pointer_array_init(&pipes, destroy_pipe); ret = lttng_poll_create(&poll_events, fd_count, 0); if (ret) { - diag("Failed to create poll set for %u file descriptors", - fd_count); + diag("Failed to create poll set for %u file descriptors", fd_count); goto end; } @@ -216,8 +223,7 @@ static int run_active_set_combination(unsigned int fd_count, goto end; } - ret = lttng_poll_add(&poll_events, lttng_pipe_get_readfd(pipe), - LPOLLIN); + ret = lttng_poll_add(&poll_events, lttng_pipe_get_readfd(pipe), LPOLLIN); if (ret) { diag("Failed to add file descriptor to poll set"); ret = -1; @@ -232,7 +238,7 @@ static int run_active_set_combination(unsigned int fd_count, } /* Ownership transferred to the pointer array. */ - pipe = NULL; + pipe = nullptr; } /* Write one byte for all active fds that should be active. */ @@ -244,13 +250,10 @@ static int run_active_set_combination(unsigned int fd_count, continue; } - borrowed_pipe = - (lttng_pipe *) lttng_dynamic_pointer_array_get_pointer( - &pipes, i); + borrowed_pipe = (lttng_pipe *) lttng_dynamic_pointer_array_get_pointer(&pipes, i); char c = 'a'; - ret = lttng_pipe_write( - borrowed_pipe, &c, sizeof(char)); + ret = lttng_pipe_write(borrowed_pipe, &c, sizeof(char)); if (ret != sizeof(char)) { diag("Failed to write to pipe"); ret = -1; @@ -261,7 +264,8 @@ static int run_active_set_combination(unsigned int fd_count, ret = lttng_poll_wait(&poll_events, 0); if (ret != active_fds_count) { diag("lttng_poll_wait returned %d, expected %u active file descriptors", - ret, active_fds_count); + ret, + active_fds_count); ret = -1; goto end; } else { @@ -301,7 +305,7 @@ fail: fail("Test all combinations of active file descriptors for %u file descriptors", fd_count); } -static void test_func_def(void) +static void test_func_def() { #ifdef LTTNG_POLL_GETFD #define PASS_GETFD 1 @@ -328,14 +332,14 @@ static void test_func_def(void) #endif ok(lttng_poll_reset == lttng_poll_reset, "lttng_poll_reset is defined"); - ok(lttng_poll_init == lttng_poll_init , "lttng_poll_init is defined"); + ok(lttng_poll_init == lttng_poll_init, "lttng_poll_init is defined"); ok(PASS_GETFD, "GETFD is defined"); ok(PASS_GETEV, "GETEV is defined"); ok(PASS_GETSZ, "GETSZ is defined"); ok(PASS_GET_PREV_FD, "GET_PREV_FD is defined"); } -int main(void) +int main() { plan_tests(NUM_TESTS); #ifdef HAVE_EPOLL