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.";
57 void get_temporary_directories(char **_test_directory
, char **_unlink_directory
)
60 char tmp_path_pattern
[] = TMP_DIR_PATTERN
;
63 output_dir
= mkdtemp(tmp_path_pattern
);
65 diag("Failed to create temporary path of the form %s",
70 *_test_directory
= strdup(output_dir
);
71 assert(*_test_directory
);
72 ret
= asprintf(_unlink_directory
, "%s/%s", output_dir
,
73 TEST_UNLINK_DIRECTORY_NAME
);
85 dir
= opendir("/proc/self/fd");
87 perror("# Failed to enumerate /proc/self/fd/ to count the number of used file descriptors");
92 while ((entry
= readdir(dir
)) != NULL
) {
93 if (!strcmp(entry
->d_name
, ".") || !strcmp(entry
->d_name
, "..")) {
98 /* Don't account for the file descriptor opened by opendir(). */
101 perror("# Failed to close test program's self/fd directory file descriptor");
108 void check_fd_count(int expected_count
)
113 ok(count
== expected_count
, "Expected %d open file descriptors (%d are open)",
114 expected_count
, count
);
118 int noop_open(void *data
, int *fds
)
120 *fds
= *((int *) data
);
125 int noop_close(void *data
, int *fds
)
131 void track_std_fds(struct fd_tracker
*tracker
)
134 struct { int fd
; const char *name
; } files
[] = {
135 { .fd
= fileno(stdin
), .name
= "stdin" },
136 { .fd
= fileno(stdout
), .name
= "stdout" },
137 { .fd
= fileno(stderr
), .name
= "stderr" },
140 for (i
= 0; i
< sizeof(files
) / sizeof(*files
); i
++) {
143 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
144 &files
[i
].name
, 1, noop_open
, &files
[i
].fd
);
145 assert(out_fd
== files
[i
].fd
);
147 ok(ret
== 0, "Track unsuspendable fd %d (%s)", files
[i
].fd
,
153 void untrack_std_fds(struct fd_tracker
*tracker
)
156 struct { int fd
; const char *name
; } files
[] = {
157 { .fd
= fileno(stdin
), .name
= "stdin" },
158 { .fd
= fileno(stdout
), .name
= "stdout" },
159 { .fd
= fileno(stderr
), .name
= "stderr" },
161 unsigned int fds_set_to_minus_1
= 0;
163 for (i
= 0; i
< sizeof(files
) / sizeof(*files
); i
++) {
164 int fd
= files
[i
].fd
;
165 int ret
= fd_tracker_close_unsuspendable_fd(tracker
,
166 &files
[i
].fd
, 1, noop_close
, NULL
);
168 ok(ret
== 0, "Untrack unsuspendable fd %d (%s)", fd
,
170 fds_set_to_minus_1
+= (files
[i
].fd
== -1);
175 * Basic test opening and closing three unsuspendable fds.
178 void test_unsuspendable_basic(void)
181 struct fd_tracker
*tracker
;
182 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
184 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
186 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
187 ok(tracker
, "Created an fd tracker with a limit of %d simulateously opened file descriptors",
193 track_std_fds(tracker
);
194 untrack_std_fds(tracker
);
196 fd_tracker_destroy(tracker
);
197 ret
= rmdir(test_directory
);
198 ok(ret
== 0, "Test directory is empty");
200 free(test_directory
);
201 free(unlinked_files_directory
);
205 int error_open(void *data
, int *fds
)
207 return *((int *) data
);
211 int error_close(void *data
, int *fds
)
213 return *((int *) data
);
217 * Validate that user callback return values are returned to the
218 * caller of the fd tracker.
221 void test_unsuspendable_cb_return(void)
223 int ret
, stdout_fd
= fileno(stdout
), out_fd
= 42;
224 struct fd_tracker
*tracker
;
225 int expected_error
= -ENETDOWN
;
226 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
228 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
230 tracker
= fd_tracker_create(test_directory
, TRACKER_FD_LIMIT
);
233 /* The error_open callback should fail and return 'expected_error'. */
234 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
235 NULL
, 1, error_open
, &expected_error
);
236 ok(ret
== expected_error
, "fd_tracker_open_unsuspendable_fd() forwards the user callback's error code");
237 ok(out_fd
== 42, "Output fd parameter is unaffected on error of fd_tracker_open_unsuspendable_fd()");
240 * Track a valid fd since we don't want the tracker to fail with an
241 * invalid fd error for this test.
243 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
244 NULL
, 1, noop_open
, &stdout_fd
);
245 ok(out_fd
== stdout_fd
, "fd_tracker_open_unsuspendable_fd() sets the output fd parameter to the newly-tracked fd's value");
248 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
249 &stdout_fd
, 1, error_close
, &expected_error
);
250 ok(ret
== expected_error
, "fd_tracker_close_unsuspendable_fd() forwards the user callback's error code");
251 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
252 &stdout_fd
, 1, noop_close
, &expected_error
);
255 fd_tracker_destroy(tracker
);
256 ret
= rmdir(test_directory
);
257 ok(ret
== 0, "Test directory is empty");
258 free(test_directory
);
259 free(unlinked_files_directory
);
263 * Validate that the tracker refuses to track two identical unsuspendable
267 void test_unsuspendable_duplicate(void)
269 int ret
, stdout_fd
= fileno(stdout
), out_fd
;
270 struct fd_tracker
*tracker
;
271 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
273 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
275 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
278 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
279 NULL
, 1, noop_open
, &stdout_fd
);
281 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
282 NULL
, 1, noop_open
, &stdout_fd
);
283 ok(ret
== -EEXIST
, "EEXIST reported on open of an already tracked file descriptor");
285 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
286 &stdout_fd
, 1, noop_close
, NULL
);
289 fd_tracker_destroy(tracker
);
290 ret
= rmdir(test_directory
);
291 ok(ret
== 0, "Test directory is empty");
292 free(test_directory
);
293 free(unlinked_files_directory
);
297 int open_pipes(void *data
, int *out_fds
)
300 const unsigned int pipe_count
= TRACKER_FD_LIMIT
/ 2;
302 for (i
= 0; i
< pipe_count
; i
++) {
303 int ret
= pipe(&out_fds
[i
* 2]);
313 int close_pipes(void *data
, int *fds
)
318 for (i
= 0; i
< TRACKER_FD_LIMIT
; i
++) {
319 int ret
= close(pipes
[i
]);
329 * Validate that the tracker enforces the open file descriptor limit
330 * when unsuspendable file descritptors are being opened.
333 void test_unsuspendable_limit(void)
335 struct fd_tracker
*tracker
;
336 int ret
, stdout_fd
= fileno(stdout
), out_fd
;
337 int fds
[TRACKER_FD_LIMIT
];
338 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
340 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
342 /* This test assumes TRACKER_FD_LIMIT is a multiple of 2. */
343 assert((TRACKER_FD_LIMIT
% 2 == 0) && TRACKER_FD_LIMIT
);
345 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
348 ret
= fd_tracker_open_unsuspendable_fd(tracker
, fds
,
349 NULL
, TRACKER_FD_LIMIT
, open_pipes
, NULL
);
350 ok(ret
== 0, "File descriptor tracker allowed the user to meet its limit with unsuspendable file descritptors (%d)",
353 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
354 NULL
, 1, noop_open
, &stdout_fd
);
355 ok(ret
== -EMFILE
, "EMFILE reported when exceeding the file descriptor limit while opening an unsuspendable fd");
357 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
358 fds
, TRACKER_FD_LIMIT
, close_pipes
, NULL
);
361 fd_tracker_destroy(tracker
);
362 ret
= rmdir(test_directory
);
363 ok(ret
== 0, "Test directory is empty");
364 free(test_directory
);
365 free(unlinked_files_directory
);
369 * Validate that the tracker refuses to track two identical unsuspendable
373 void test_unsuspendable_close_untracked(void)
375 int ret
, stdout_fd
= fileno(stdout
), unknown_fds
[2], out_fd
;
376 struct fd_tracker
*tracker
;
377 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
379 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
381 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
386 ret
= pipe(unknown_fds
);
388 assert(close(unknown_fds
[0]) == 0);
389 assert(close(unknown_fds
[1]) == 0);
391 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
392 NULL
, 1, noop_open
, &stdout_fd
);
395 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
396 unknown_fds
, 1, noop_close
, NULL
);
397 ok(ret
== -EINVAL
, "EINVAL reported on close of an untracked file descriptor");
399 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
400 &stdout_fd
, 1, noop_close
, NULL
);
403 fd_tracker_destroy(tracker
);
404 ret
= rmdir(test_directory
);
405 ok(ret
== 0, "Test directory is empty");
407 free(test_directory
);
408 free(unlinked_files_directory
);
411 static int open_files(struct fd_tracker
*tracker
,
412 struct lttng_directory_handle
*directory
,
414 struct fs_handle
**handles
,
420 for (i
= 0; i
< count
; i
++) {
423 struct fs_handle
*handle
;
424 mode_t mode
= S_IWUSR
| S_IRUSR
;
426 p_ret
= asprintf(&file_path
, "file-%u", i
);
428 file_paths
[i
] = file_path
;
430 handle
= fd_tracker_open_fs_handle(tracker
, directory
, file_path
,
431 O_RDWR
| O_CREAT
, &mode
);
441 static int open_same_file(struct fd_tracker
*tracker
,
442 struct lttng_directory_handle
*directory
,
445 struct fs_handle
**handles
)
450 for (i
= 0; i
< count
; i
++) {
451 struct fs_handle
*handle
;
452 mode_t mode
= S_IWUSR
| S_IRUSR
;
454 handle
= fd_tracker_open_fs_handle(tracker
, directory
, file
,
455 O_RDWR
| O_CREAT
, &mode
);
466 int cleanup_files(struct fd_tracker
*tracker
, const char *dir
,
467 unsigned int count
, struct fs_handle
**handles
,
473 for (i
= 0; i
< count
; i
++) {
474 char *file_path
= file_paths
[i
];
479 if (fs_handle_unlink(handles
[i
])) {
480 diag("Failed to unlink fs_handle to file %s", file_path
);
483 if (fs_handle_close(handles
[i
])) {
484 diag("Failed to close fs_handle to file %s", file_path
);
493 void test_suspendable_limit(void)
496 const int files_to_create
= TRACKER_FD_LIMIT
* 10;
497 struct fd_tracker
*tracker
;
498 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
499 char *output_files
[files_to_create
];
500 struct fs_handle
*handles
[files_to_create
];
501 struct lttng_directory_handle
*dir_handle
= NULL
;
502 int dir_handle_fd_count
;
504 memset(output_files
, 0, sizeof(output_files
));
505 memset(handles
, 0, sizeof(handles
));
507 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
509 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
514 dir_handle
= lttng_directory_handle_create(test_directory
);
516 dir_handle_fd_count
= !!lttng_directory_handle_uses_fd(dir_handle
);
518 ret
= open_files(tracker
, dir_handle
, files_to_create
, handles
,
520 ok(!ret
, "Created %d files with a limit of %d simultaneously-opened file descriptor",
521 files_to_create
, TRACKER_FD_LIMIT
);
522 check_fd_count(TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+ unknown_fds_count
+
523 dir_handle_fd_count
);
525 ret
= cleanup_files(tracker
, test_directory
, files_to_create
, handles
,
527 ok(!ret
, "Close all opened filesystem handles");
528 ret
= rmdir(test_directory
);
529 ok(ret
== 0, "Test directory is empty");
530 fd_tracker_destroy(tracker
);
531 lttng_directory_handle_put(dir_handle
);
533 free(test_directory
);
534 free(unlinked_files_directory
);
538 void test_mixed_limit(void)
541 const int files_to_create
= TRACKER_FD_LIMIT
;
542 struct fd_tracker
*tracker
;
543 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
544 char *output_files
[files_to_create
];
545 struct fs_handle
*handles
[files_to_create
];
546 struct lttng_directory_handle
*dir_handle
= NULL
;
547 int dir_handle_fd_count
;
549 memset(output_files
, 0, sizeof(output_files
));
550 memset(handles
, 0, sizeof(handles
));
552 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
554 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
559 dir_handle
= lttng_directory_handle_create(test_directory
);
561 dir_handle_fd_count
= !!lttng_directory_handle_uses_fd(dir_handle
);
563 ret
= open_files(tracker
, dir_handle
, files_to_create
, handles
,
565 ok(!ret
, "Created %d files with a limit of %d simultaneously-opened file descriptor",
566 files_to_create
, TRACKER_FD_LIMIT
);
567 diag("Check file descriptor count after opening %u files", files_to_create
);
568 check_fd_count(TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+ unknown_fds_count
+
569 dir_handle_fd_count
);
572 * Open unsuspendable fds (stdin, stdout, stderr) and verify that the fd
573 * cap is still respected.
575 diag("Check file descriptor count after adding %d unsuspendable fds",
577 track_std_fds(tracker
);
578 check_fd_count(TRACKER_FD_LIMIT
+ unknown_fds_count
+
579 dir_handle_fd_count
);
580 diag("Untrack unsuspendable file descriptors");
581 untrack_std_fds(tracker
);
582 check_fd_count(TRACKER_FD_LIMIT
+ unknown_fds_count
+
583 dir_handle_fd_count
);
585 ret
= cleanup_files(tracker
, test_directory
, files_to_create
, handles
,
587 ok(!ret
, "Close all opened filesystem handles");
588 ret
= rmdir(test_directory
);
589 ok(ret
== 0, "Test directory is empty");
590 fd_tracker_destroy(tracker
);
591 lttng_directory_handle_put(dir_handle
);
593 free(test_directory
);
594 free(unlinked_files_directory
);
598 * Open more files than allowed by the fd tracker's cap and write,
599 * byte-by-byte, and in round-robin, a string. The goal is to force
600 * the fd tracker to suspend and resume the fs_handles often and
601 * verify that the fd cap is always respected.
603 * The content of the files is also verified at the end.
606 void test_suspendable_restore(void)
609 const int files_to_create
= TRACKER_FD_LIMIT
* 10;
610 struct fd_tracker
*tracker
;
611 char *output_files
[files_to_create
];
612 struct fs_handle
*handles
[files_to_create
];
613 size_t content_index
;
615 bool write_success
= true;
616 bool fd_cap_respected
= true;
617 bool content_ok
= true;
618 struct lttng_directory_handle
*dir_handle
= NULL
;
619 int dir_handle_fd_count
;
620 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
622 memset(output_files
, 0, sizeof(output_files
));
623 memset(handles
, 0, sizeof(handles
));
625 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
627 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
632 dir_handle
= lttng_directory_handle_create(test_directory
);
634 dir_handle_fd_count
= !!lttng_directory_handle_uses_fd(dir_handle
);
636 ret
= open_files(tracker
, dir_handle
, files_to_create
, handles
,
638 ok(!ret
, "Created %d files with a limit of %d simultaneously-opened file descriptor",
639 files_to_create
, TRACKER_FD_LIMIT
);
640 diag("Check file descriptor count after opening %u files", files_to_create
);
641 check_fd_count(TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+ unknown_fds_count
+
642 dir_handle_fd_count
);
644 for (content_index
= 0; content_index
< sizeof(file_contents
); content_index
++) {
645 for (handle_index
= 0; handle_index
< files_to_create
; handle_index
++) {
647 struct fs_handle
*handle
= handles
[handle_index
];
648 const char *path
= output_files
[handle_index
];
650 fd
= fs_handle_get_fd(handle
);
652 write_success
= false;
653 diag("Failed to restore fs_handle to %s",
659 ret
= write(fd
, file_contents
+ content_index
, 1);
660 } while (ret
< 0 && errno
== EINTR
);
663 write_success
= false;
664 PERROR("write() to %s failed", path
);
668 if (fd_count() > (TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+
670 dir_handle_fd_count
)) {
671 fd_cap_respected
= false;
674 fs_handle_put_fd(handle
);
678 ok(write_success
, "Wrote reference string to %d files",
680 ok(fd_cap_respected
, "FD tracker enforced the file descriptor cap");
682 /* Validate the contents of the files. */
683 for (handle_index
= 0; handle_index
< files_to_create
; handle_index
++) {
685 const char *path
= output_files
[handle_index
];
686 char read_buf
[sizeof(file_contents
)];
688 size_t to_read
= sizeof(read_buf
);
691 fd
= lttng_directory_handle_open_file(
692 dir_handle
, path
, O_RDONLY
, 0);
694 ret
= fstat(fd
, &fd_stat
);
696 if (fd_stat
.st_size
!= sizeof(file_contents
)) {
697 diag("Content size of file %s doesn't match, got %" PRId64
", expected %zu",
698 path
, (int64_t) fd_stat
.st_size
,
699 sizeof(file_contents
));
707 ret
= read(fd
, read_pos
, to_read
);
712 } while (to_read
&& (ret
< 0 && errno
== EINTR
));
715 PERROR("Failed to read file %s", path
);
720 if (strcmp(file_contents
, read_buf
)) {
722 diag("File content doesn't match the expectated string");
728 ok(content_ok
, "Files contain the expected content");
729 ret
= cleanup_files(tracker
, test_directory
, files_to_create
, handles
,
731 ok(!ret
, "Close all opened filesystem handles");
732 ret
= rmdir(test_directory
);
733 ok(ret
== 0, "Test directory is empty");
734 fd_tracker_destroy(tracker
);
735 lttng_directory_handle_put(dir_handle
);
737 free(test_directory
);
738 free(unlinked_files_directory
);
742 void test_unlink(void)
745 struct fd_tracker
*tracker
;
746 const int handles_to_open
= 2;
747 struct fs_handle
*handles
[handles_to_open
];
748 struct fs_handle
*new_handle
= NULL
;
750 struct lttng_directory_handle
*dir_handle
= NULL
;
751 const char file_name
[] = "my_file";
752 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
753 char *unlinked_file_zero
= NULL
, *unlinked_file_one
= NULL
;
756 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
757 ret
= asprintf(&unlinked_file_zero
, "%s/%u", unlinked_files_directory
,
760 ret
= asprintf(&unlinked_file_one
, "%s/%u", unlinked_files_directory
,
764 tracker
= fd_tracker_create(unlinked_files_directory
, 1);
769 dir_handle
= lttng_directory_handle_create(test_directory
);
772 /* Open two handles to the same file. */
773 ret
= open_same_file(tracker
, dir_handle
, file_name
, handles_to_open
,
775 ok(!ret
, "Successfully opened %i handles to %s/%s", handles_to_open
,
776 test_directory
, file_name
);
782 * Unlinking the first handle should cause the file to be renamed
785 ret
= fs_handle_unlink(handles
[0]);
786 ok(!ret
, "Successfully unlinked the first handle to %s/%s",
787 test_directory
, file_name
);
790 * The original file should no longer exist on the file system, and a
791 * new file named '0' should exist.
793 ok(lttng_directory_handle_stat(dir_handle
, file_name
, &statbuf
) == -1 &&
795 "%s no longer present on file system after unlink",
797 ok(lttng_directory_handle_stat(
798 dir_handle
, unlinked_file_zero
, &statbuf
) == 0,
799 "%s exists on file system after unlink",
803 * It should be possible to use the file descriptors of both handles.
804 * Since only one file descriptor can be opened at once, this should
805 * force the fd_tracker to suspend and restore the handles.
807 fd
= fs_handle_get_fd(handles
[0]);
808 ok(fd
>= 0, "Got fd from first handle");
810 fd
= fs_handle_get_fd(handles
[1]);
811 ok (fd
< 0, "fd tracker does not allow two fds to be used at once");
813 fs_handle_put_fd(handles
[0]);
814 fd
= fs_handle_get_fd(handles
[1]);
815 ok(fd
>= 0, "Got fd from second handle");
816 fs_handle_put_fd(handles
[1]);
818 /* The second unlink should fail with -ENOENT. */
819 ret
= fs_handle_unlink(handles
[1]);
821 "ENOENT is reported when attempting to unlink the second handle to %s/%s",
822 test_directory
, file_name
);
825 * Opening a new handle to 'my_file' should succeed.
827 ret
= open_same_file(tracker
, dir_handle
, file_name
, 1, &new_handle
);
828 ok(!ret
, "Successfully opened a new handle to previously unlinked file %s/%s",
829 test_directory
, file_name
);
833 * Unlinking the new handle should cause the file to be renamed
834 * to '1' since '0' already exists.
836 ret
= fs_handle_unlink(new_handle
);
837 ok(!ret
, "Successfully unlinked the new handle handle to %s/%s",
838 test_directory
, file_name
);
839 ok(stat(unlinked_file_one
, &statbuf
) == 0,
840 "%s exists on file system after unlink",
843 ret
= fs_handle_close(handles
[0]);
844 ok(!ret
, "Successfully closed the first handle");
845 ret
= fs_handle_close(handles
[1]);
846 ok(!ret
, "Successfully closed the second handle");
847 ret
= fs_handle_close(new_handle
);
848 ok(!ret
, "Successfully closed the third handle");
850 ok(lttng_directory_handle_stat(dir_handle
, file_name
, &statbuf
) == -1 &&
852 "%s no longer present on file system after handle close",
854 ok(lttng_directory_handle_stat(
855 dir_handle
, unlinked_file_zero
, &statbuf
) == -1 &&
857 "%s no longer present on file system after handle close",
859 ok(lttng_directory_handle_stat(dir_handle
, unlinked_file_one
,
862 "%s no longer present on file system after handle close",
865 ret
= rmdir(test_directory
);
866 ok(ret
== 0, "Test directory is empty");
868 fd_tracker_destroy(tracker
);
869 free(test_directory
);
870 free(unlinked_files_directory
);
871 free(unlinked_file_zero
);
872 free(unlinked_file_one
);
873 lttng_directory_handle_put(dir_handle
);
876 int main(int argc
, char **argv
)
878 plan_tests(NUM_TESTS
);
879 diag("File descriptor tracker unit tests");
881 rcu_register_thread();
883 unknown_fds_count
= fd_count() - STDIO_FD_COUNT
;
884 assert(unknown_fds_count
>= 0);
886 diag("Unsuspendable - basic");
887 test_unsuspendable_basic();
888 diag("Unsuspendable - callback return values");
889 test_unsuspendable_cb_return();
890 diag("Unsuspendable - duplicate file descriptors");
891 test_unsuspendable_duplicate();
892 diag("Unsuspendable - closing an untracked file descriptor");
893 test_unsuspendable_close_untracked();
894 diag("Unsuspendable - check that file descritptor limit is enforced");
895 test_unsuspendable_limit();
897 diag("Suspendable - check that file descritptor limit is enforced");
898 test_suspendable_limit();
899 diag("Suspendable - restoration test");
900 test_suspendable_restore();
902 diag("Mixed - check that file descritptor limit is enforced");
905 diag("Suspendable - Unlinking test");
909 rcu_unregister_thread();
910 return exit_status();