2 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
15 #include <sys/types.h>
22 #include <sys/types.h>
26 #include <common/compat/directory-handle.h>
27 #include <common/error.h>
28 #include <common/fd-tracker/fd-tracker.h>
31 int lttng_opt_quiet
= 1;
32 int lttng_opt_verbose
;
35 /* Number of TAP tests in this file */
37 /* 3 for stdin, stdout, and stderr */
38 #define STDIO_FD_COUNT 3
39 #define TRACKER_FD_LIMIT 50
40 #define TMP_DIR_PATTERN "/tmp/fd-tracker-XXXXXX"
41 #define TEST_UNLINK_DIRECTORY_NAME "unlinked_files"
44 * Count of fds, beyond stdin, stderr, stdout that were open
45 * at the launch of the test. This allows the test to succeed when
46 * run by automake's test runner or valgrind which both open
47 * fds behind our back.
49 int unknown_fds_count
;
51 const char file_contents
[] = "Bacon ipsum dolor amet jerky drumstick sirloin "
52 "strip steak venison boudin filet mignon picanha doner shoulder. "
53 "Strip steak brisket alcatra, venison beef chuck cupim pastrami. "
54 "Landjaeger tri-tip salami leberkas ball tip, ham hock chuck sausage "
55 "flank jerky cupim. Pig bacon chuck pancetta andouille.";
58 void get_temporary_directories(char **_test_directory
, char **_unlink_directory
)
61 char tmp_path_pattern
[] = TMP_DIR_PATTERN
;
64 output_dir
= mkdtemp(tmp_path_pattern
);
66 diag("Failed to create temporary path of the form %s",
71 *_test_directory
= strdup(output_dir
);
72 assert(*_test_directory
);
73 ret
= asprintf(_unlink_directory
, "%s/%s", output_dir
,
74 TEST_UNLINK_DIRECTORY_NAME
);
87 dir
= opendir("/proc/self/fd");
89 perror("# Failed to enumerate /proc/self/fd/ to count the number of used file descriptors");
94 while ((entry
= readdir(dir
)) != NULL
) {
95 if (!strcmp(entry
->d_name
, ".") || !strcmp(entry
->d_name
, "..")) {
100 /* Don't account for the file descriptor opened by opendir(). */
103 perror("# Failed to close test program's self/fd directory file descriptor");
110 void check_fd_count(int expected_count
)
115 ok(count
== expected_count
, "Expected %d open file descriptors (%d are open)",
116 expected_count
, count
);
120 int noop_open(void *data
, int *fds
)
122 *fds
= *((int *) data
);
127 int noop_close(void *data
, int *fds
)
133 void track_std_fds(struct fd_tracker
*tracker
)
136 struct { int fd
; const char *name
; } files
[] = {
137 { .fd
= fileno(stdin
), .name
= "stdin" },
138 { .fd
= fileno(stdout
), .name
= "stdout" },
139 { .fd
= fileno(stderr
), .name
= "stderr" },
142 for (i
= 0; i
< sizeof(files
) / sizeof(*files
); i
++) {
145 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
146 &files
[i
].name
, 1, noop_open
, &files
[i
].fd
);
147 assert(out_fd
== files
[i
].fd
);
149 ok(ret
== 0, "Track unsuspendable fd %d (%s)", files
[i
].fd
,
155 void untrack_std_fds(struct fd_tracker
*tracker
)
158 struct { int fd
; const char *name
; } files
[] = {
159 { .fd
= fileno(stdin
), .name
= "stdin" },
160 { .fd
= fileno(stdout
), .name
= "stdout" },
161 { .fd
= fileno(stderr
), .name
= "stderr" },
163 unsigned int fds_set_to_minus_1
= 0;
165 for (i
= 0; i
< sizeof(files
) / sizeof(*files
); i
++) {
166 int fd
= files
[i
].fd
;
167 int ret
= fd_tracker_close_unsuspendable_fd(tracker
,
168 &files
[i
].fd
, 1, noop_close
, NULL
);
170 ok(ret
== 0, "Untrack unsuspendable fd %d (%s)", fd
,
172 fds_set_to_minus_1
+= (files
[i
].fd
== -1);
177 * Basic test opening and closing three unsuspendable fds.
180 void test_unsuspendable_basic(void)
183 struct fd_tracker
*tracker
;
184 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
186 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
188 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
189 ok(tracker
, "Created an fd tracker with a limit of %d simulateously opened file descriptors",
195 track_std_fds(tracker
);
196 untrack_std_fds(tracker
);
198 fd_tracker_destroy(tracker
);
199 ret
= rmdir(test_directory
);
200 ok(ret
== 0, "Test directory is empty");
202 free(test_directory
);
203 free(unlinked_files_directory
);
207 int error_open(void *data
, int *fds
)
209 return *((int *) data
);
213 int error_close(void *data
, int *fds
)
215 return *((int *) data
);
219 * Validate that user callback return values are returned to the
220 * caller of the fd tracker.
223 void test_unsuspendable_cb_return(void)
225 int ret
, stdout_fd
= fileno(stdout
), out_fd
= 42;
226 struct fd_tracker
*tracker
;
227 int expected_error
= -ENETDOWN
;
228 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
230 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
232 tracker
= fd_tracker_create(test_directory
, TRACKER_FD_LIMIT
);
235 /* The error_open callback should fail and return 'expected_error'. */
236 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
237 NULL
, 1, error_open
, &expected_error
);
238 ok(ret
== expected_error
, "fd_tracker_open_unsuspendable_fd() forwards the user callback's error code");
239 ok(out_fd
== 42, "Output fd parameter is unaffected on error of fd_tracker_open_unsuspendable_fd()");
242 * Track a valid fd since we don't want the tracker to fail with an
243 * invalid fd error for this test.
245 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
246 NULL
, 1, noop_open
, &stdout_fd
);
247 ok(out_fd
== stdout_fd
, "fd_tracker_open_unsuspendable_fd() sets the output fd parameter to the newly-tracked fd's value");
250 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
251 &stdout_fd
, 1, error_close
, &expected_error
);
252 ok(ret
== expected_error
, "fd_tracker_close_unsuspendable_fd() forwards the user callback's error code");
253 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
254 &stdout_fd
, 1, noop_close
, &expected_error
);
257 fd_tracker_destroy(tracker
);
258 ret
= rmdir(test_directory
);
259 ok(ret
== 0, "Test directory is empty");
260 free(test_directory
);
261 free(unlinked_files_directory
);
265 * Validate that the tracker refuses to track two identical unsuspendable
269 void test_unsuspendable_duplicate(void)
271 int ret
, stdout_fd
= fileno(stdout
), out_fd
;
272 struct fd_tracker
*tracker
;
273 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
275 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
277 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
280 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
281 NULL
, 1, noop_open
, &stdout_fd
);
283 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
284 NULL
, 1, noop_open
, &stdout_fd
);
285 ok(ret
== -EEXIST
, "EEXIST reported on open of an already tracked file descriptor");
287 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
288 &stdout_fd
, 1, noop_close
, NULL
);
291 fd_tracker_destroy(tracker
);
292 ret
= rmdir(test_directory
);
293 ok(ret
== 0, "Test directory is empty");
294 free(test_directory
);
295 free(unlinked_files_directory
);
299 int open_pipes(void *data
, int *out_fds
)
302 const unsigned int pipe_count
= TRACKER_FD_LIMIT
/ 2;
304 for (i
= 0; i
< pipe_count
; i
++) {
305 int ret
= pipe(&out_fds
[i
* 2]);
315 int close_pipes(void *data
, int *fds
)
320 for (i
= 0; i
< TRACKER_FD_LIMIT
; i
++) {
321 int ret
= close(pipes
[i
]);
331 * Validate that the tracker enforces the open file descriptor limit
332 * when unsuspendable file descriptors are being opened.
335 void test_unsuspendable_limit(void)
337 struct fd_tracker
*tracker
;
338 int ret
, stdout_fd
= fileno(stdout
), out_fd
;
339 int fds
[TRACKER_FD_LIMIT
];
340 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
342 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
344 /* This test assumes TRACKER_FD_LIMIT is a multiple of 2. */
345 assert((TRACKER_FD_LIMIT
% 2 == 0) && TRACKER_FD_LIMIT
);
347 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
350 ret
= fd_tracker_open_unsuspendable_fd(tracker
, fds
,
351 NULL
, TRACKER_FD_LIMIT
, open_pipes
, NULL
);
352 ok(ret
== 0, "File descriptor tracker allowed the user to meet its limit with unsuspendable file descriptors (%d)",
355 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
356 NULL
, 1, noop_open
, &stdout_fd
);
357 ok(ret
== -EMFILE
, "EMFILE reported when exceeding the file descriptor limit while opening an unsuspendable fd");
359 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
360 fds
, TRACKER_FD_LIMIT
, close_pipes
, NULL
);
363 fd_tracker_destroy(tracker
);
364 ret
= rmdir(test_directory
);
365 ok(ret
== 0, "Test directory is empty");
366 free(test_directory
);
367 free(unlinked_files_directory
);
371 * Validate that the tracker refuses to track two identical unsuspendable
375 void test_unsuspendable_close_untracked(void)
377 int ret
, stdout_fd
= fileno(stdout
), unknown_fds
[2], out_fd
;
378 struct fd_tracker
*tracker
;
379 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
381 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
383 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
388 ret
= pipe(unknown_fds
);
390 ret
= close(unknown_fds
[0]);
392 ret
= close(unknown_fds
[1]);
395 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
396 NULL
, 1, noop_open
, &stdout_fd
);
399 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
400 unknown_fds
, 1, noop_close
, NULL
);
401 ok(ret
== -EINVAL
, "EINVAL reported on close of an untracked file descriptor");
403 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
404 &stdout_fd
, 1, noop_close
, NULL
);
407 fd_tracker_destroy(tracker
);
408 ret
= rmdir(test_directory
);
409 ok(ret
== 0, "Test directory is empty");
411 free(test_directory
);
412 free(unlinked_files_directory
);
415 static int open_files(struct fd_tracker
*tracker
,
416 struct lttng_directory_handle
*directory
,
418 struct fs_handle
**handles
,
424 for (i
= 0; i
< count
; i
++) {
427 struct fs_handle
*handle
;
428 mode_t mode
= S_IWUSR
| S_IRUSR
;
430 p_ret
= asprintf(&file_path
, "file-%u", i
);
432 file_paths
[i
] = file_path
;
434 handle
= fd_tracker_open_fs_handle(tracker
, directory
, file_path
,
435 O_RDWR
| O_CREAT
, &mode
);
445 static int open_same_file(struct fd_tracker
*tracker
,
446 struct lttng_directory_handle
*directory
,
449 struct fs_handle
**handles
)
454 for (i
= 0; i
< count
; i
++) {
455 struct fs_handle
*handle
;
456 mode_t mode
= S_IWUSR
| S_IRUSR
;
458 handle
= fd_tracker_open_fs_handle(tracker
, directory
, file
,
459 O_RDWR
| O_CREAT
, &mode
);
470 int cleanup_files(struct fd_tracker
*tracker
, const char *dir
,
471 unsigned int count
, struct fs_handle
**handles
,
477 for (i
= 0; i
< count
; i
++) {
478 char *file_path
= file_paths
[i
];
483 if (fs_handle_unlink(handles
[i
])) {
484 diag("Failed to unlink fs_handle to file %s", file_path
);
487 if (fs_handle_close(handles
[i
])) {
488 diag("Failed to close fs_handle to file %s", file_path
);
497 void test_suspendable_limit(void)
500 const int files_to_create
= TRACKER_FD_LIMIT
* 10;
501 struct fd_tracker
*tracker
;
502 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
503 char *output_files
[files_to_create
];
504 struct fs_handle
*handles
[files_to_create
];
505 struct lttng_directory_handle
*dir_handle
= NULL
;
506 int dir_handle_fd_count
;
508 memset(output_files
, 0, sizeof(output_files
));
509 memset(handles
, 0, sizeof(handles
));
511 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
513 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
518 dir_handle
= lttng_directory_handle_create(test_directory
);
520 dir_handle_fd_count
= !!lttng_directory_handle_uses_fd(dir_handle
);
522 ret
= open_files(tracker
, dir_handle
, files_to_create
, handles
,
524 ok(!ret
, "Created %d files with a limit of %d simultaneously-opened file descriptor",
525 files_to_create
, TRACKER_FD_LIMIT
);
526 check_fd_count(TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+ unknown_fds_count
+
527 dir_handle_fd_count
);
529 ret
= cleanup_files(tracker
, test_directory
, files_to_create
, handles
,
531 ok(!ret
, "Close all opened filesystem handles");
532 ret
= rmdir(test_directory
);
533 ok(ret
== 0, "Test directory is empty");
534 fd_tracker_destroy(tracker
);
535 lttng_directory_handle_put(dir_handle
);
537 free(test_directory
);
538 free(unlinked_files_directory
);
542 void test_mixed_limit(void)
545 const int files_to_create
= TRACKER_FD_LIMIT
;
546 struct fd_tracker
*tracker
;
547 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
548 char *output_files
[files_to_create
];
549 struct fs_handle
*handles
[files_to_create
];
550 struct lttng_directory_handle
*dir_handle
= NULL
;
551 int dir_handle_fd_count
;
553 memset(output_files
, 0, sizeof(output_files
));
554 memset(handles
, 0, sizeof(handles
));
556 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
558 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
563 dir_handle
= lttng_directory_handle_create(test_directory
);
565 dir_handle_fd_count
= !!lttng_directory_handle_uses_fd(dir_handle
);
567 ret
= open_files(tracker
, dir_handle
, files_to_create
, handles
,
569 ok(!ret
, "Created %d files with a limit of %d simultaneously-opened file descriptor",
570 files_to_create
, TRACKER_FD_LIMIT
);
571 diag("Check file descriptor count after opening %u files", files_to_create
);
572 check_fd_count(TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+ unknown_fds_count
+
573 dir_handle_fd_count
);
576 * Open unsuspendable fds (stdin, stdout, stderr) and verify that the fd
577 * cap is still respected.
579 diag("Check file descriptor count after adding %d unsuspendable fds",
581 track_std_fds(tracker
);
582 check_fd_count(TRACKER_FD_LIMIT
+ unknown_fds_count
+
583 dir_handle_fd_count
);
584 diag("Untrack unsuspendable file descriptors");
585 untrack_std_fds(tracker
);
586 check_fd_count(TRACKER_FD_LIMIT
+ unknown_fds_count
+
587 dir_handle_fd_count
);
589 ret
= cleanup_files(tracker
, test_directory
, files_to_create
, handles
,
591 ok(!ret
, "Close all opened filesystem handles");
592 ret
= rmdir(test_directory
);
593 ok(ret
== 0, "Test directory is empty");
594 fd_tracker_destroy(tracker
);
595 lttng_directory_handle_put(dir_handle
);
597 free(test_directory
);
598 free(unlinked_files_directory
);
602 * Open more files than allowed by the fd tracker's cap and write,
603 * byte-by-byte, and in round-robin, a string. The goal is to force
604 * the fd tracker to suspend and resume the fs_handles often and
605 * verify that the fd cap is always respected.
607 * The content of the files is also verified at the end.
610 void test_suspendable_restore(void)
613 const int files_to_create
= TRACKER_FD_LIMIT
* 10;
614 struct fd_tracker
*tracker
;
615 char *output_files
[files_to_create
];
616 struct fs_handle
*handles
[files_to_create
];
617 size_t content_index
;
619 bool write_success
= true;
620 bool fd_cap_respected
= true;
621 bool content_ok
= true;
622 struct lttng_directory_handle
*dir_handle
= NULL
;
623 int dir_handle_fd_count
;
624 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
626 memset(output_files
, 0, sizeof(output_files
));
627 memset(handles
, 0, sizeof(handles
));
629 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
631 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
636 dir_handle
= lttng_directory_handle_create(test_directory
);
638 dir_handle_fd_count
= !!lttng_directory_handle_uses_fd(dir_handle
);
640 ret
= open_files(tracker
, dir_handle
, files_to_create
, handles
,
642 ok(!ret
, "Created %d files with a limit of %d simultaneously-opened file descriptor",
643 files_to_create
, TRACKER_FD_LIMIT
);
644 diag("Check file descriptor count after opening %u files", files_to_create
);
645 check_fd_count(TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+ unknown_fds_count
+
646 dir_handle_fd_count
);
648 for (content_index
= 0; content_index
< sizeof(file_contents
); content_index
++) {
649 for (handle_index
= 0; handle_index
< files_to_create
; handle_index
++) {
651 struct fs_handle
*handle
= handles
[handle_index
];
652 const char *path
= output_files
[handle_index
];
654 fd
= fs_handle_get_fd(handle
);
656 write_success
= false;
657 diag("Failed to restore fs_handle to %s",
663 ret
= write(fd
, file_contents
+ content_index
, 1);
664 } while (ret
< 0 && errno
== EINTR
);
667 write_success
= false;
668 PERROR("write() to %s failed", path
);
672 if (fd_count() > (TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+
674 dir_handle_fd_count
)) {
675 fd_cap_respected
= false;
678 fs_handle_put_fd(handle
);
682 ok(write_success
, "Wrote reference string to %d files",
684 ok(fd_cap_respected
, "FD tracker enforced the file descriptor cap");
686 /* Validate the contents of the files. */
687 for (handle_index
= 0; handle_index
< files_to_create
; handle_index
++) {
689 const char *path
= output_files
[handle_index
];
690 char read_buf
[sizeof(file_contents
)];
692 size_t to_read
= sizeof(read_buf
);
695 fd
= lttng_directory_handle_open_file(
696 dir_handle
, path
, O_RDONLY
, 0);
698 ret
= fstat(fd
, &fd_stat
);
700 if (fd_stat
.st_size
!= sizeof(file_contents
)) {
701 diag("Content size of file %s doesn't match, got %" PRId64
", expected %zu",
702 path
, (int64_t) fd_stat
.st_size
,
703 sizeof(file_contents
));
711 ret
= read(fd
, read_pos
, to_read
);
716 } while (to_read
&& (ret
< 0 && errno
== EINTR
));
719 PERROR("Failed to read file %s", path
);
724 if (strcmp(file_contents
, read_buf
)) {
726 diag("File content doesn't match the expectated string");
732 ok(content_ok
, "Files contain the expected content");
733 ret
= cleanup_files(tracker
, test_directory
, files_to_create
, handles
,
735 ok(!ret
, "Close all opened filesystem handles");
736 ret
= rmdir(test_directory
);
737 ok(ret
== 0, "Test directory is empty");
738 fd_tracker_destroy(tracker
);
739 lttng_directory_handle_put(dir_handle
);
741 free(test_directory
);
742 free(unlinked_files_directory
);
746 void test_unlink(void)
749 struct fd_tracker
*tracker
;
750 const int handles_to_open
= 2;
751 struct fs_handle
*handles
[handles_to_open
];
752 struct fs_handle
*new_handle
= NULL
;
754 struct lttng_directory_handle
*dir_handle
= NULL
;
755 const char file_name
[] = "my_file";
756 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
757 char *unlinked_file_zero
= NULL
, *unlinked_file_one
= NULL
;
760 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
761 ret
= asprintf(&unlinked_file_zero
, "%s/%u", unlinked_files_directory
,
764 ret
= asprintf(&unlinked_file_one
, "%s/%u", unlinked_files_directory
,
768 tracker
= fd_tracker_create(unlinked_files_directory
, 1);
773 dir_handle
= lttng_directory_handle_create(test_directory
);
776 /* Open two handles to the same file. */
777 ret
= open_same_file(tracker
, dir_handle
, file_name
, handles_to_open
,
779 ok(!ret
, "Successfully opened %i handles to %s/%s", handles_to_open
,
780 test_directory
, file_name
);
786 * Unlinking the first handle should cause the file to be renamed
789 ret
= fs_handle_unlink(handles
[0]);
790 ok(!ret
, "Successfully unlinked the first handle to %s/%s",
791 test_directory
, file_name
);
794 * The original file should no longer exist on the file system, and a
795 * new file named '0' should exist.
797 ok(lttng_directory_handle_stat(dir_handle
, file_name
, &statbuf
) == -1 &&
799 "%s no longer present on file system after unlink",
801 ok(lttng_directory_handle_stat(
802 dir_handle
, unlinked_file_zero
, &statbuf
) == 0,
803 "%s exists on file system after unlink",
807 * It should be possible to use the file descriptors of both handles.
808 * Since only one file descriptor can be opened at once, this should
809 * force the fd_tracker to suspend and restore the handles.
811 fd
= fs_handle_get_fd(handles
[0]);
812 ok(fd
>= 0, "Got fd from first handle");
814 fd
= fs_handle_get_fd(handles
[1]);
815 ok (fd
< 0, "fd tracker does not allow two fds to be used at once");
817 fs_handle_put_fd(handles
[0]);
818 fd
= fs_handle_get_fd(handles
[1]);
819 ok(fd
>= 0, "Got fd from second handle");
820 fs_handle_put_fd(handles
[1]);
822 /* The second unlink should fail with -ENOENT. */
823 ret
= fs_handle_unlink(handles
[1]);
825 "ENOENT is reported when attempting to unlink the second handle to %s/%s",
826 test_directory
, file_name
);
829 * Opening a new handle to 'my_file' should succeed.
831 ret
= open_same_file(tracker
, dir_handle
, file_name
, 1, &new_handle
);
832 ok(!ret
, "Successfully opened a new handle to previously unlinked file %s/%s",
833 test_directory
, file_name
);
837 * Unlinking the new handle should cause the file to be renamed
838 * to '1' since '0' already exists.
840 ret
= fs_handle_unlink(new_handle
);
841 ok(!ret
, "Successfully unlinked the new handle handle to %s/%s",
842 test_directory
, file_name
);
843 ok(stat(unlinked_file_one
, &statbuf
) == 0,
844 "%s exists on file system after unlink",
847 ret
= fs_handle_close(handles
[0]);
848 ok(!ret
, "Successfully closed the first handle");
849 ret
= fs_handle_close(handles
[1]);
850 ok(!ret
, "Successfully closed the second handle");
851 ret
= fs_handle_close(new_handle
);
852 ok(!ret
, "Successfully closed the third handle");
854 ok(lttng_directory_handle_stat(dir_handle
, file_name
, &statbuf
) == -1 &&
856 "%s no longer present on file system after handle close",
858 ok(lttng_directory_handle_stat(
859 dir_handle
, unlinked_file_zero
, &statbuf
) == -1 &&
861 "%s no longer present on file system after handle close",
863 ok(lttng_directory_handle_stat(dir_handle
, unlinked_file_one
,
866 "%s no longer present on file system after handle close",
869 ret
= rmdir(test_directory
);
870 ok(ret
== 0, "Test directory is empty");
872 fd_tracker_destroy(tracker
);
873 free(test_directory
);
874 free(unlinked_files_directory
);
875 free(unlinked_file_zero
);
876 free(unlinked_file_one
);
877 lttng_directory_handle_put(dir_handle
);
880 int main(int argc
, char **argv
)
882 plan_tests(NUM_TESTS
);
883 diag("File descriptor tracker unit tests");
885 rcu_register_thread();
887 unknown_fds_count
= fd_count() - STDIO_FD_COUNT
;
888 assert(unknown_fds_count
>= 0);
890 diag("Unsuspendable - basic");
891 test_unsuspendable_basic();
892 diag("Unsuspendable - callback return values");
893 test_unsuspendable_cb_return();
894 diag("Unsuspendable - duplicate file descriptors");
895 test_unsuspendable_duplicate();
896 diag("Unsuspendable - closing an untracked file descriptor");
897 test_unsuspendable_close_untracked();
898 diag("Unsuspendable - check that file descriptor limit is enforced");
899 test_unsuspendable_limit();
901 diag("Suspendable - check that file descriptor limit is enforced");
902 test_suspendable_limit();
903 diag("Suspendable - restoration test");
904 test_suspendable_restore();
906 diag("Mixed - check that file descriptor limit is enforced");
909 diag("Suspendable - Unlinking test");
913 rcu_unregister_thread();
914 return exit_status();