X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Funit%2Ftest_fd_tracker.cpp;h=d86cb4126b0584c53f0a2a41d002a391521a0905;hb=28ab034a2c3582d07d3423d2d746731f87d3969f;hp=63f3d0afa31921ab78a2b3086d3c1292e6bb97a5;hpb=52e345b9ac912d033c2a2c25a170a01cf209839d;p=lttng-tools.git diff --git a/tests/unit/test_fd_tracker.cpp b/tests/unit/test_fd_tracker.cpp index 63f3d0afa..d86cb4126 100644 --- a/tests/unit/test_fd_tracker.cpp +++ b/tests/unit/test_fd_tracker.cpp @@ -5,28 +5,26 @@ * */ -#include +#include +#include +#include +#include +#include + +#include +#include #include -#include -#include #include -#include -#include -#include +#include #include -#include -#include +#include +#include #include #include - +#include +#include #include -#include -#include -#include -#include -#include - /* For error.h */ int lttng_opt_quiet = 1; int lttng_opt_verbose; @@ -35,9 +33,9 @@ int lttng_opt_mi; /* Number of TAP tests in this file */ #define NUM_TESTS 61 /* 3 for stdin, stdout, and stderr */ -#define STDIO_FD_COUNT 3 -#define TRACKER_FD_LIMIT 50 -#define TMP_DIR_PATTERN "/tmp/fd-tracker-XXXXXX" +#define STDIO_FD_COUNT 3 +#define TRACKER_FD_LIMIT 50 +#define TMP_DIR_PATTERN "/tmp/fd-tracker-XXXXXX" #define TEST_UNLINK_DIRECTORY_NAME "unlinked_files" #ifdef __linux__ @@ -56,13 +54,12 @@ int lttng_opt_mi; int unknown_fds_count; const char file_contents[] = "Bacon ipsum dolor amet jerky drumstick sirloin " - "strip steak venison boudin filet mignon picanha doner shoulder. " - "Strip steak brisket alcatra, venison beef chuck cupim pastrami. " - "Landjaeger tri-tip salami leberkas ball tip, ham hock chuck sausage " - "flank jerky cupim. Pig bacon chuck pancetta andouille."; + "strip steak venison boudin filet mignon picanha doner shoulder. " + "Strip steak brisket alcatra, venison beef chuck cupim pastrami. " + "Landjaeger tri-tip salami leberkas ball tip, ham hock chuck sausage " + "flank jerky cupim. Pig bacon chuck pancetta andouille."; -static -void get_temporary_directories(char **_test_directory, char **_unlink_directory) +static void get_temporary_directories(char **_test_directory, char **_unlink_directory) { int ret; char tmp_path_pattern[] = TMP_DIR_PATTERN; @@ -70,22 +67,19 @@ void get_temporary_directories(char **_test_directory, char **_unlink_directory) output_dir = mkdtemp(tmp_path_pattern); if (!output_dir) { - diag("Failed to create temporary path of the form %s", - TMP_DIR_PATTERN); + diag("Failed to create temporary path of the form %s", TMP_DIR_PATTERN); abort(); } *_test_directory = strdup(output_dir); LTTNG_ASSERT(*_test_directory); - ret = asprintf(_unlink_directory, "%s/%s", output_dir, - TEST_UNLINK_DIRECTORY_NAME); + ret = asprintf(_unlink_directory, "%s/%s", output_dir, TEST_UNLINK_DIRECTORY_NAME); if (ret < 0) { abort(); } } -static -int fd_count(void) +static int fd_count(void) { DIR *dir; struct dirent *entry; @@ -93,7 +87,8 @@ int fd_count(void) dir = opendir(SELF_FD_DIR); if (!dir) { - perror("# Failed to enumerate " SELF_FD_DIR " to count the number of used file descriptors"); + perror("# Failed to enumerate " SELF_FD_DIR + " to count the number of used file descriptors"); count = -1; goto end; } @@ -107,41 +102,42 @@ int fd_count(void) /* Don't account for the file descriptor opened by opendir(). */ count--; if (closedir(dir)) { - perror("# Failed to close test program's " SELF_FD_DIR " directory file descriptor"); + perror("# Failed to close test program's " SELF_FD_DIR + " directory file descriptor"); } end: return count; } -static -void check_fd_count(int expected_count) +static void check_fd_count(int expected_count) { int count = 0; count = fd_count(); - ok(count == expected_count, "Expected %d open file descriptors (%d are open)", - expected_count, count); + ok(count == expected_count, + "Expected %d open file descriptors (%d are open)", + expected_count, + count); } -static -int noop_open(void *data, int *fds) +static int noop_open(void *data, int *fds) { *fds = *((int *) data); return 0; } -static -int noop_close(void *data __attribute__((unused)), - int *fds __attribute__((unused))) +static int noop_close(void *data __attribute__((unused)), int *fds __attribute__((unused))) { return 0; } -static -void track_std_fds(struct fd_tracker *tracker) +static void track_std_fds(struct fd_tracker *tracker) { int i; - struct { int fd; const char *name; } files[] = { + struct { + int fd; + const char *name; + } files[] = { { .fd = fileno(stdin), .name = "stdin" }, { .fd = fileno(stdout), .name = "stdout" }, { .fd = fileno(stderr), .name = "stderr" }, @@ -150,20 +146,21 @@ void track_std_fds(struct fd_tracker *tracker) for (i = 0; i < sizeof(files) / sizeof(*files); i++) { int out_fd, ret; - ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, - &files[i].name, 1, noop_open, &files[i].fd); + ret = fd_tracker_open_unsuspendable_fd( + tracker, &out_fd, &files[i].name, 1, noop_open, &files[i].fd); LTTNG_ASSERT(out_fd == files[i].fd); - ok(ret == 0, "Track unsuspendable fd %d (%s)", files[i].fd, - files[i].name); + ok(ret == 0, "Track unsuspendable fd %d (%s)", files[i].fd, files[i].name); } } -static -void untrack_std_fds(struct fd_tracker *tracker) +static void untrack_std_fds(struct fd_tracker *tracker) { int i; - struct { int fd; const char *name; } files[] = { + struct { + int fd; + const char *name; + } files[] = { { .fd = fileno(stdin), .name = "stdin" }, { .fd = fileno(stdout), .name = "stdout" }, { .fd = fileno(stderr), .name = "stderr" }, @@ -171,19 +168,17 @@ void untrack_std_fds(struct fd_tracker *tracker) for (i = 0; i < sizeof(files) / sizeof(*files); i++) { int fd = files[i].fd; - int ret = fd_tracker_close_unsuspendable_fd(tracker, - &files[i].fd, 1, noop_close, NULL); + int ret = fd_tracker_close_unsuspendable_fd( + tracker, &files[i].fd, 1, noop_close, NULL); - ok(ret == 0, "Untrack unsuspendable fd %d (%s)", fd, - files[i].name); + ok(ret == 0, "Untrack unsuspendable fd %d (%s)", fd, files[i].name); } } /* - * Basic test opening and closing three unsuspendable fds. + * Basic test opening and closing three unsuspendable fds. */ -static -void test_unsuspendable_basic(void) +static void test_unsuspendable_basic(void) { int ret; struct fd_tracker *tracker; @@ -192,8 +187,9 @@ void test_unsuspendable_basic(void) get_temporary_directories(&test_directory, &unlinked_files_directory); tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT); - ok(tracker, "Created an fd tracker with a limit of %d simulateously opened file descriptors", - TRACKER_FD_LIMIT); + ok(tracker, + "Created an fd tracker with a limit of %d simulateously opened file descriptors", + TRACKER_FD_LIMIT); if (!tracker) { goto end; } @@ -209,14 +205,12 @@ end: free(unlinked_files_directory); } -static -int error_open(void *data, int *fds __attribute__((unused))) +static int error_open(void *data, int *fds __attribute__((unused))) { return *((int *) data); } -static -int error_close(void *data, int *fds __attribute__((unused))) +static int error_close(void *data, int *fds __attribute__((unused))) { return *((int *) data); } @@ -225,8 +219,7 @@ int error_close(void *data, int *fds __attribute__((unused))) * Validate that user callback return values are returned to the * caller of the fd tracker. */ -static -void test_unsuspendable_cb_return(void) +static void test_unsuspendable_cb_return(void) { int ret, stdout_fd = fileno(stdout), out_fd = 42; struct fd_tracker *tracker; @@ -239,25 +232,28 @@ void test_unsuspendable_cb_return(void) LTTNG_ASSERT(tracker); /* The error_open callback should fail and return 'expected_error'. */ - ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, - NULL, 1, error_open, &expected_error); - ok(ret == expected_error, "fd_tracker_open_unsuspendable_fd() forwards the user callback's error code"); - ok(out_fd == 42, "Output fd parameter is unaffected on error of fd_tracker_open_unsuspendable_fd()"); + ret = fd_tracker_open_unsuspendable_fd( + tracker, &out_fd, NULL, 1, error_open, &expected_error); + ok(ret == expected_error, + "fd_tracker_open_unsuspendable_fd() forwards the user callback's error code"); + ok(out_fd == 42, + "Output fd parameter is unaffected on error of fd_tracker_open_unsuspendable_fd()"); /* * Track a valid fd since we don't want the tracker to fail with an * invalid fd error for this test. */ - ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, - NULL, 1, noop_open, &stdout_fd); - ok(out_fd == stdout_fd, "fd_tracker_open_unsuspendable_fd() sets the output fd parameter to the newly-tracked fd's value"); + ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd); + ok(out_fd == stdout_fd, + "fd_tracker_open_unsuspendable_fd() sets the output fd parameter to the newly-tracked fd's value"); LTTNG_ASSERT(!ret); - ret = fd_tracker_close_unsuspendable_fd(tracker, - &stdout_fd, 1, error_close, &expected_error); - ok(ret == expected_error, "fd_tracker_close_unsuspendable_fd() forwards the user callback's error code"); - ret = fd_tracker_close_unsuspendable_fd(tracker, - &stdout_fd, 1, noop_close, &expected_error); + ret = fd_tracker_close_unsuspendable_fd( + tracker, &stdout_fd, 1, error_close, &expected_error); + ok(ret == expected_error, + "fd_tracker_close_unsuspendable_fd() forwards the user callback's error code"); + ret = fd_tracker_close_unsuspendable_fd( + tracker, &stdout_fd, 1, noop_close, &expected_error); LTTNG_ASSERT(!ret); fd_tracker_destroy(tracker); @@ -271,8 +267,7 @@ void test_unsuspendable_cb_return(void) * Validate that the tracker refuses to track two identical unsuspendable * file descriptors. */ -static -void test_unsuspendable_duplicate(void) +static void test_unsuspendable_duplicate(void) { int ret, stdout_fd = fileno(stdout), out_fd; struct fd_tracker *tracker; @@ -283,15 +278,12 @@ void test_unsuspendable_duplicate(void) tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT); LTTNG_ASSERT(tracker); - ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, - NULL, 1, noop_open, &stdout_fd); + ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd); LTTNG_ASSERT(!ret); - ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, - NULL, 1, noop_open, &stdout_fd); + ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd); ok(ret == -EEXIST, "EEXIST reported on open of an already tracked file descriptor"); - ret = fd_tracker_close_unsuspendable_fd(tracker, - &stdout_fd, 1, noop_close, NULL); + ret = fd_tracker_close_unsuspendable_fd(tracker, &stdout_fd, 1, noop_close, NULL); LTTNG_ASSERT(!ret); fd_tracker_destroy(tracker); @@ -301,8 +293,7 @@ void test_unsuspendable_duplicate(void) free(unlinked_files_directory); } -static -int open_pipes(void *data __attribute__((unused)), int *out_fds) +static int open_pipes(void *data __attribute__((unused)), int *out_fds) { unsigned int i; const unsigned int pipe_count = TRACKER_FD_LIMIT / 2; @@ -317,8 +308,7 @@ int open_pipes(void *data __attribute__((unused)), int *out_fds) return 0; } -static -int close_pipes(void *data __attribute__((unused)), int *fds) +static int close_pipes(void *data __attribute__((unused)), int *fds) { int i; int *pipes = fds; @@ -337,8 +327,7 @@ int close_pipes(void *data __attribute__((unused)), int *fds) * Validate that the tracker enforces the open file descriptor limit * when unsuspendable file descriptors are being opened. */ -static -void test_unsuspendable_limit(void) +static void test_unsuspendable_limit(void) { struct fd_tracker *tracker; int ret, stdout_fd = fileno(stdout), out_fd; @@ -353,17 +342,17 @@ void test_unsuspendable_limit(void) tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT); LTTNG_ASSERT(tracker); - ret = fd_tracker_open_unsuspendable_fd(tracker, fds, - NULL, TRACKER_FD_LIMIT, open_pipes, NULL); - ok(ret == 0, "File descriptor tracker allowed the user to meet its limit with unsuspendable file descriptors (%d)", - TRACKER_FD_LIMIT); + ret = fd_tracker_open_unsuspendable_fd( + tracker, fds, NULL, TRACKER_FD_LIMIT, open_pipes, NULL); + ok(ret == 0, + "File descriptor tracker allowed the user to meet its limit with unsuspendable file descriptors (%d)", + TRACKER_FD_LIMIT); - ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, - NULL, 1, noop_open, &stdout_fd); - ok(ret == -EMFILE, "EMFILE reported when exceeding the file descriptor limit while opening an unsuspendable fd"); + ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd); + ok(ret == -EMFILE, + "EMFILE reported when exceeding the file descriptor limit while opening an unsuspendable fd"); - ret = fd_tracker_close_unsuspendable_fd(tracker, - fds, TRACKER_FD_LIMIT, close_pipes, NULL); + ret = fd_tracker_close_unsuspendable_fd(tracker, fds, TRACKER_FD_LIMIT, close_pipes, NULL); LTTNG_ASSERT(!ret); fd_tracker_destroy(tracker); @@ -377,8 +366,7 @@ void test_unsuspendable_limit(void) * Validate that the tracker refuses to track two identical unsuspendable * file descriptors. */ -static -void test_unsuspendable_close_untracked(void) +static void test_unsuspendable_close_untracked(void) { int ret, stdout_fd = fileno(stdout), unknown_fds[2], out_fd; struct fd_tracker *tracker; @@ -388,7 +376,8 @@ void test_unsuspendable_close_untracked(void) tracker = fd_tracker_create(unlinked_files_directory, TRACKER_FD_LIMIT); if (!tracker) { - goto end;; + goto end; + ; } ret = pipe(unknown_fds); @@ -398,16 +387,13 @@ void test_unsuspendable_close_untracked(void) ret = close(unknown_fds[1]); LTTNG_ASSERT(ret == 0); - ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, - NULL, 1, noop_open, &stdout_fd); + ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd, NULL, 1, noop_open, &stdout_fd); LTTNG_ASSERT(!ret); - ret = fd_tracker_close_unsuspendable_fd(tracker, - unknown_fds, 1, noop_close, NULL); + ret = fd_tracker_close_unsuspendable_fd(tracker, unknown_fds, 1, noop_close, NULL); ok(ret == -EINVAL, "EINVAL reported on close of an untracked file descriptor"); - ret = fd_tracker_close_unsuspendable_fd(tracker, - &stdout_fd, 1, noop_close, NULL); + ret = fd_tracker_close_unsuspendable_fd(tracker, &stdout_fd, 1, noop_close, NULL); LTTNG_ASSERT(!ret); fd_tracker_destroy(tracker); @@ -419,10 +405,10 @@ end: } static int open_files(struct fd_tracker *tracker, - struct lttng_directory_handle *directory, - unsigned int count, - struct fs_handle **handles, - char **file_paths) + struct lttng_directory_handle *directory, + unsigned int count, + struct fs_handle **handles, + char **file_paths) { int ret = 0; unsigned int i; @@ -437,8 +423,8 @@ static int open_files(struct fd_tracker *tracker, LTTNG_ASSERT(p_ret >= 0); file_paths[i] = file_path; - handle = fd_tracker_open_fs_handle(tracker, directory, file_path, - O_RDWR | O_CREAT, &mode); + handle = fd_tracker_open_fs_handle( + tracker, directory, file_path, O_RDWR | O_CREAT, &mode); if (!handle) { ret = -1; break; @@ -449,10 +435,10 @@ static int open_files(struct fd_tracker *tracker, } static int open_same_file(struct fd_tracker *tracker, - struct lttng_directory_handle *directory, - const char *file, - unsigned int count, - struct fs_handle **handles) + struct lttng_directory_handle *directory, + const char *file, + unsigned int count, + struct fs_handle **handles) { int ret = 0; unsigned int i; @@ -461,8 +447,8 @@ static int open_same_file(struct fd_tracker *tracker, struct fs_handle *handle; mode_t mode = S_IWUSR | S_IRUSR; - handle = fd_tracker_open_fs_handle(tracker, directory, file, - O_RDWR | O_CREAT, &mode); + handle = fd_tracker_open_fs_handle( + tracker, directory, file, O_RDWR | O_CREAT, &mode); if (!handle) { ret = -1; break; @@ -472,11 +458,11 @@ static int open_same_file(struct fd_tracker *tracker, return ret; } -static -int cleanup_files(struct fd_tracker *tracker __attribute__((unused)), - const char *dir __attribute__((unused)), - unsigned int count, struct fs_handle **handles, - char **file_paths) +static int cleanup_files(struct fd_tracker *tracker __attribute__((unused)), + const char *dir __attribute__((unused)), + unsigned int count, + struct fs_handle **handles, + char **file_paths) { int ret = 0; unsigned int i; @@ -500,8 +486,7 @@ int cleanup_files(struct fd_tracker *tracker __attribute__((unused)), return ret; } -static -void test_suspendable_limit(void) +static void test_suspendable_limit(void) { int ret; const int files_to_create = TRACKER_FD_LIMIT * 10; @@ -526,15 +511,14 @@ void test_suspendable_limit(void) LTTNG_ASSERT(dir_handle); dir_handle_fd_count = !!lttng_directory_handle_uses_fd(dir_handle); - ret = open_files(tracker, dir_handle, files_to_create, handles, - output_files); - ok(!ret, "Created %d files with a limit of %d simultaneously-opened file descriptor", - files_to_create, TRACKER_FD_LIMIT); - check_fd_count(TRACKER_FD_LIMIT + STDIO_FD_COUNT + unknown_fds_count + - dir_handle_fd_count); + ret = open_files(tracker, dir_handle, files_to_create, handles, output_files); + ok(!ret, + "Created %d files with a limit of %d simultaneously-opened file descriptor", + files_to_create, + TRACKER_FD_LIMIT); + check_fd_count(TRACKER_FD_LIMIT + STDIO_FD_COUNT + unknown_fds_count + dir_handle_fd_count); - ret = cleanup_files(tracker, test_directory, files_to_create, handles, - output_files); + ret = cleanup_files(tracker, test_directory, files_to_create, handles, output_files); ok(!ret, "Close all opened filesystem handles"); ret = rmdir(test_directory); ok(ret == 0, "Test directory is empty"); @@ -545,8 +529,7 @@ end: free(unlinked_files_directory); } -static -void test_mixed_limit(void) +static void test_mixed_limit(void) { int ret; const int files_to_create = TRACKER_FD_LIMIT; @@ -571,30 +554,26 @@ void test_mixed_limit(void) LTTNG_ASSERT(dir_handle); dir_handle_fd_count = !!lttng_directory_handle_uses_fd(dir_handle); - ret = open_files(tracker, dir_handle, files_to_create, handles, - output_files); - ok(!ret, "Created %d files with a limit of %d simultaneously-opened file descriptor", - files_to_create, TRACKER_FD_LIMIT); + ret = open_files(tracker, dir_handle, files_to_create, handles, output_files); + ok(!ret, + "Created %d files with a limit of %d simultaneously-opened file descriptor", + files_to_create, + TRACKER_FD_LIMIT); diag("Check file descriptor count after opening %u files", files_to_create); - check_fd_count(TRACKER_FD_LIMIT + STDIO_FD_COUNT + unknown_fds_count + - dir_handle_fd_count); + check_fd_count(TRACKER_FD_LIMIT + STDIO_FD_COUNT + unknown_fds_count + dir_handle_fd_count); /* * Open unsuspendable fds (stdin, stdout, stderr) and verify that the fd * cap is still respected. */ - diag("Check file descriptor count after adding %d unsuspendable fds", - STDIO_FD_COUNT); + diag("Check file descriptor count after adding %d unsuspendable fds", STDIO_FD_COUNT); track_std_fds(tracker); - check_fd_count(TRACKER_FD_LIMIT + unknown_fds_count + - dir_handle_fd_count); + check_fd_count(TRACKER_FD_LIMIT + unknown_fds_count + dir_handle_fd_count); diag("Untrack unsuspendable file descriptors"); untrack_std_fds(tracker); - check_fd_count(TRACKER_FD_LIMIT + unknown_fds_count + - dir_handle_fd_count); + check_fd_count(TRACKER_FD_LIMIT + unknown_fds_count + dir_handle_fd_count); - ret = cleanup_files(tracker, test_directory, files_to_create, handles, - output_files); + ret = cleanup_files(tracker, test_directory, files_to_create, handles, output_files); ok(!ret, "Close all opened filesystem handles"); ret = rmdir(test_directory); ok(ret == 0, "Test directory is empty"); @@ -613,8 +592,7 @@ end: * * The content of the files is also verified at the end. */ -static -void test_suspendable_restore(void) +static void test_suspendable_restore(void) { int ret; const int files_to_create = TRACKER_FD_LIMIT * 10; @@ -644,13 +622,13 @@ void test_suspendable_restore(void) LTTNG_ASSERT(dir_handle); dir_handle_fd_count = !!lttng_directory_handle_uses_fd(dir_handle); - ret = open_files(tracker, dir_handle, files_to_create, handles, - output_files); - ok(!ret, "Created %d files with a limit of %d simultaneously-opened file descriptor", - files_to_create, TRACKER_FD_LIMIT); + ret = open_files(tracker, dir_handle, files_to_create, handles, output_files); + ok(!ret, + "Created %d files with a limit of %d simultaneously-opened file descriptor", + files_to_create, + TRACKER_FD_LIMIT); diag("Check file descriptor count after opening %u files", files_to_create); - check_fd_count(TRACKER_FD_LIMIT + STDIO_FD_COUNT + unknown_fds_count + - dir_handle_fd_count); + check_fd_count(TRACKER_FD_LIMIT + STDIO_FD_COUNT + unknown_fds_count + dir_handle_fd_count); for (content_index = 0; content_index < sizeof(file_contents); content_index++) { for (handle_index = 0; handle_index < files_to_create; handle_index++) { @@ -661,8 +639,7 @@ void test_suspendable_restore(void) fd = fs_handle_get_fd(handle); if (fd < 0) { write_success = false; - diag("Failed to restore fs_handle to %s", - path); + diag("Failed to restore fs_handle to %s", path); goto skip_write; } @@ -676,9 +653,8 @@ void test_suspendable_restore(void) goto skip_write; } - if (fd_count() > (TRACKER_FD_LIMIT + STDIO_FD_COUNT + - unknown_fds_count + - dir_handle_fd_count)) { + if (fd_count() > (TRACKER_FD_LIMIT + STDIO_FD_COUNT + unknown_fds_count + + dir_handle_fd_count)) { fd_cap_respected = false; } @@ -686,8 +662,7 @@ void test_suspendable_restore(void) } } skip_write: - ok(write_success, "Wrote reference string to %d files", - files_to_create); + ok(write_success, "Wrote reference string to %d files", files_to_create); ok(fd_cap_respected, "FD tracker enforced the file descriptor cap"); /* Validate the contents of the files. */ @@ -699,15 +674,15 @@ skip_write: size_t to_read = sizeof(read_buf); int fd; - fd = lttng_directory_handle_open_file( - dir_handle, path, O_RDONLY, 0); + fd = lttng_directory_handle_open_file(dir_handle, path, O_RDONLY, 0); LTTNG_ASSERT(fd >= 0); ret = fstat(fd, &fd_stat); LTTNG_ASSERT(!ret); if (fd_stat.st_size != sizeof(file_contents)) { diag("Content size of file %s doesn't match, got %" PRId64 ", expected %zu", - path, (int64_t) fd_stat.st_size, - sizeof(file_contents)); + path, + (int64_t) fd_stat.st_size, + sizeof(file_contents)); content_ok = false; (void) close(fd); break; @@ -737,8 +712,7 @@ skip_write: (void) close(fd); } ok(content_ok, "Files contain the expected content"); - ret = cleanup_files(tracker, test_directory, files_to_create, handles, - output_files); + ret = cleanup_files(tracker, test_directory, files_to_create, handles, output_files); ok(!ret, "Close all opened filesystem handles"); ret = rmdir(test_directory); ok(ret == 0, "Test directory is empty"); @@ -749,8 +723,7 @@ end: free(unlinked_files_directory); } -static -void test_unlink(void) +static void test_unlink(void) { int ret; struct fd_tracker *tracker; @@ -765,11 +738,9 @@ void test_unlink(void) int fd; get_temporary_directories(&test_directory, &unlinked_files_directory); - ret = asprintf(&unlinked_file_zero, "%s/%u", unlinked_files_directory, - 0); + ret = asprintf(&unlinked_file_zero, "%s/%u", unlinked_files_directory, 0); LTTNG_ASSERT(ret > 0); - ret = asprintf(&unlinked_file_one, "%s/%u", unlinked_files_directory, - 1); + ret = asprintf(&unlinked_file_one, "%s/%u", unlinked_files_directory, 1); LTTNG_ASSERT(ret > 0); tracker = fd_tracker_create(unlinked_files_directory, 1); @@ -781,10 +752,12 @@ void test_unlink(void) LTTNG_ASSERT(dir_handle); /* Open two handles to the same file. */ - ret = open_same_file(tracker, dir_handle, file_name, handles_to_open, - handles); - ok(!ret, "Successfully opened %i handles to %s/%s", handles_to_open, - test_directory, file_name); + ret = open_same_file(tracker, dir_handle, file_name, handles_to_open, handles); + ok(!ret, + "Successfully opened %i handles to %s/%s", + handles_to_open, + test_directory, + file_name); if (ret) { goto end; } @@ -794,21 +767,18 @@ void test_unlink(void) * to '0'. */ ret = fs_handle_unlink(handles[0]); - ok(!ret, "Successfully unlinked the first handle to %s/%s", - test_directory, file_name); + ok(!ret, "Successfully unlinked the first handle to %s/%s", test_directory, file_name); /* * The original file should no longer exist on the file system, and a * new file named '0' should exist. */ - ok(lttng_directory_handle_stat(dir_handle, file_name, &statbuf) == -1 && - errno == ENOENT, - "%s no longer present on file system after unlink", - file_name); - ok(lttng_directory_handle_stat( - dir_handle, unlinked_file_zero, &statbuf) == 0, - "%s exists on file system after unlink", - unlinked_file_zero); + ok(lttng_directory_handle_stat(dir_handle, file_name, &statbuf) == -1 && errno == ENOENT, + "%s no longer present on file system after unlink", + file_name); + ok(lttng_directory_handle_stat(dir_handle, unlinked_file_zero, &statbuf) == 0, + "%s exists on file system after unlink", + unlinked_file_zero); /* * It should be possible to use the file descriptors of both handles. @@ -819,7 +789,7 @@ void test_unlink(void) ok(fd >= 0, "Got fd from first handle"); fd = fs_handle_get_fd(handles[1]); - ok (fd < 0, "fd tracker does not allow two fds to be used at once"); + ok(fd < 0, "fd tracker does not allow two fds to be used at once"); fs_handle_put_fd(handles[0]); fd = fs_handle_get_fd(handles[1]); @@ -829,15 +799,18 @@ void test_unlink(void) /* The second unlink should fail with -ENOENT. */ ret = fs_handle_unlink(handles[1]); ok(ret == -ENOENT, - "ENOENT is reported when attempting to unlink the second handle to %s/%s", - test_directory, file_name); + "ENOENT is reported when attempting to unlink the second handle to %s/%s", + test_directory, + file_name); /* * Opening a new handle to 'my_file' should succeed. */ ret = open_same_file(tracker, dir_handle, file_name, 1, &new_handle); - ok(!ret, "Successfully opened a new handle to previously unlinked file %s/%s", - test_directory, file_name); + ok(!ret, + "Successfully opened a new handle to previously unlinked file %s/%s", + test_directory, + file_name); LTTNG_ASSERT(new_handle); /* @@ -845,11 +818,10 @@ void test_unlink(void) * to '1' since '0' already exists. */ ret = fs_handle_unlink(new_handle); - ok(!ret, "Successfully unlinked the new handle handle to %s/%s", - test_directory, file_name); + ok(!ret, "Successfully unlinked the new handle handle to %s/%s", test_directory, file_name); ok(stat(unlinked_file_one, &statbuf) == 0, - "%s exists on file system after unlink", - unlinked_file_one); + "%s exists on file system after unlink", + unlinked_file_one); ret = fs_handle_close(handles[0]); ok(!ret, "Successfully closed the first handle"); @@ -858,20 +830,17 @@ void test_unlink(void) ret = fs_handle_close(new_handle); ok(!ret, "Successfully closed the third handle"); - ok(lttng_directory_handle_stat(dir_handle, file_name, &statbuf) == -1 && - errno == ENOENT, - "%s no longer present on file system after handle close", - file_name); - ok(lttng_directory_handle_stat( - dir_handle, unlinked_file_zero, &statbuf) == -1 && - errno == ENOENT, - "%s no longer present on file system after handle close", - unlinked_file_zero); - ok(lttng_directory_handle_stat(dir_handle, unlinked_file_one, - &statbuf) == -1 && - errno == ENOENT, - "%s no longer present on file system after handle close", - unlinked_file_one); + ok(lttng_directory_handle_stat(dir_handle, file_name, &statbuf) == -1 && errno == ENOENT, + "%s no longer present on file system after handle close", + file_name); + ok(lttng_directory_handle_stat(dir_handle, unlinked_file_zero, &statbuf) == -1 && + errno == ENOENT, + "%s no longer present on file system after handle close", + unlinked_file_zero); + ok(lttng_directory_handle_stat(dir_handle, unlinked_file_one, &statbuf) == -1 && + errno == ENOENT, + "%s no longer present on file system after handle close", + unlinked_file_one); ret = rmdir(test_directory); ok(ret == 0, "Test directory is empty");