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
);
86 dir
= opendir("/proc/self/fd");
88 perror("# Failed to enumerate /proc/self/fd/ to count the number of used file descriptors");
93 while ((entry
= readdir(dir
)) != NULL
) {
94 if (!strcmp(entry
->d_name
, ".") || !strcmp(entry
->d_name
, "..")) {
99 /* Don't account for the file descriptor opened by opendir(). */
102 perror("# Failed to close test program's self/fd directory file descriptor");
109 void check_fd_count(int expected_count
)
114 ok(count
== expected_count
, "Expected %d open file descriptors (%d are open)",
115 expected_count
, count
);
119 int noop_open(void *data
, int *fds
)
121 *fds
= *((int *) data
);
126 int noop_close(void *data
, int *fds
)
132 void track_std_fds(struct fd_tracker
*tracker
)
135 struct { int fd
; const char *name
; } files
[] = {
136 { .fd
= fileno(stdin
), .name
= "stdin" },
137 { .fd
= fileno(stdout
), .name
= "stdout" },
138 { .fd
= fileno(stderr
), .name
= "stderr" },
141 for (i
= 0; i
< sizeof(files
) / sizeof(*files
); i
++) {
144 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
145 &files
[i
].name
, 1, noop_open
, &files
[i
].fd
);
146 assert(out_fd
== files
[i
].fd
);
148 ok(ret
== 0, "Track unsuspendable fd %d (%s)", files
[i
].fd
,
154 void untrack_std_fds(struct fd_tracker
*tracker
)
157 struct { int fd
; const char *name
; } files
[] = {
158 { .fd
= fileno(stdin
), .name
= "stdin" },
159 { .fd
= fileno(stdout
), .name
= "stdout" },
160 { .fd
= fileno(stderr
), .name
= "stderr" },
162 unsigned int fds_set_to_minus_1
= 0;
164 for (i
= 0; i
< sizeof(files
) / sizeof(*files
); i
++) {
165 int fd
= files
[i
].fd
;
166 int ret
= fd_tracker_close_unsuspendable_fd(tracker
,
167 &files
[i
].fd
, 1, noop_close
, NULL
);
169 ok(ret
== 0, "Untrack unsuspendable fd %d (%s)", fd
,
171 fds_set_to_minus_1
+= (files
[i
].fd
== -1);
176 * Basic test opening and closing three unsuspendable fds.
179 void test_unsuspendable_basic(void)
182 struct fd_tracker
*tracker
;
183 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
185 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
187 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
188 ok(tracker
, "Created an fd tracker with a limit of %d simulateously opened file descriptors",
194 track_std_fds(tracker
);
195 untrack_std_fds(tracker
);
197 fd_tracker_destroy(tracker
);
198 ret
= rmdir(test_directory
);
199 ok(ret
== 0, "Test directory is empty");
201 free(test_directory
);
202 free(unlinked_files_directory
);
206 int error_open(void *data
, int *fds
)
208 return *((int *) data
);
212 int error_close(void *data
, int *fds
)
214 return *((int *) data
);
218 * Validate that user callback return values are returned to the
219 * caller of the fd tracker.
222 void test_unsuspendable_cb_return(void)
224 int ret
, stdout_fd
= fileno(stdout
), out_fd
= 42;
225 struct fd_tracker
*tracker
;
226 int expected_error
= -ENETDOWN
;
227 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
229 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
231 tracker
= fd_tracker_create(test_directory
, TRACKER_FD_LIMIT
);
234 /* The error_open callback should fail and return 'expected_error'. */
235 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
236 NULL
, 1, error_open
, &expected_error
);
237 ok(ret
== expected_error
, "fd_tracker_open_unsuspendable_fd() forwards the user callback's error code");
238 ok(out_fd
== 42, "Output fd parameter is unaffected on error of fd_tracker_open_unsuspendable_fd()");
241 * Track a valid fd since we don't want the tracker to fail with an
242 * invalid fd error for this test.
244 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
245 NULL
, 1, noop_open
, &stdout_fd
);
246 ok(out_fd
== stdout_fd
, "fd_tracker_open_unsuspendable_fd() sets the output fd parameter to the newly-tracked fd's value");
249 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
250 &stdout_fd
, 1, error_close
, &expected_error
);
251 ok(ret
== expected_error
, "fd_tracker_close_unsuspendable_fd() forwards the user callback's error code");
252 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
253 &stdout_fd
, 1, noop_close
, &expected_error
);
256 fd_tracker_destroy(tracker
);
257 ret
= rmdir(test_directory
);
258 ok(ret
== 0, "Test directory is empty");
259 free(test_directory
);
260 free(unlinked_files_directory
);
264 * Validate that the tracker refuses to track two identical unsuspendable
268 void test_unsuspendable_duplicate(void)
270 int ret
, stdout_fd
= fileno(stdout
), out_fd
;
271 struct fd_tracker
*tracker
;
272 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
274 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
276 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
279 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
280 NULL
, 1, noop_open
, &stdout_fd
);
282 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
283 NULL
, 1, noop_open
, &stdout_fd
);
284 ok(ret
== -EEXIST
, "EEXIST reported on open of an already tracked file descriptor");
286 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
287 &stdout_fd
, 1, noop_close
, NULL
);
290 fd_tracker_destroy(tracker
);
291 ret
= rmdir(test_directory
);
292 ok(ret
== 0, "Test directory is empty");
293 free(test_directory
);
294 free(unlinked_files_directory
);
298 int open_pipes(void *data
, int *out_fds
)
301 const unsigned int pipe_count
= TRACKER_FD_LIMIT
/ 2;
303 for (i
= 0; i
< pipe_count
; i
++) {
304 int ret
= pipe(&out_fds
[i
* 2]);
314 int close_pipes(void *data
, int *fds
)
319 for (i
= 0; i
< TRACKER_FD_LIMIT
; i
++) {
320 int ret
= close(pipes
[i
]);
330 * Validate that the tracker enforces the open file descriptor limit
331 * when unsuspendable file descritptors are being opened.
334 void test_unsuspendable_limit(void)
336 struct fd_tracker
*tracker
;
337 int ret
, stdout_fd
= fileno(stdout
), out_fd
;
338 int fds
[TRACKER_FD_LIMIT
];
339 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
341 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
343 /* This test assumes TRACKER_FD_LIMIT is a multiple of 2. */
344 assert((TRACKER_FD_LIMIT
% 2 == 0) && TRACKER_FD_LIMIT
);
346 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
349 ret
= fd_tracker_open_unsuspendable_fd(tracker
, fds
,
350 NULL
, TRACKER_FD_LIMIT
, open_pipes
, NULL
);
351 ok(ret
== 0, "File descriptor tracker allowed the user to meet its limit with unsuspendable file descritptors (%d)",
354 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
355 NULL
, 1, noop_open
, &stdout_fd
);
356 ok(ret
== -EMFILE
, "EMFILE reported when exceeding the file descriptor limit while opening an unsuspendable fd");
358 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
359 fds
, TRACKER_FD_LIMIT
, close_pipes
, NULL
);
362 fd_tracker_destroy(tracker
);
363 ret
= rmdir(test_directory
);
364 ok(ret
== 0, "Test directory is empty");
365 free(test_directory
);
366 free(unlinked_files_directory
);
370 * Validate that the tracker refuses to track two identical unsuspendable
374 void test_unsuspendable_close_untracked(void)
376 int ret
, stdout_fd
= fileno(stdout
), unknown_fds
[2], out_fd
;
377 struct fd_tracker
*tracker
;
378 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
380 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
382 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
387 ret
= pipe(unknown_fds
);
389 assert(close(unknown_fds
[0]) == 0);
390 assert(close(unknown_fds
[1]) == 0);
392 ret
= fd_tracker_open_unsuspendable_fd(tracker
, &out_fd
,
393 NULL
, 1, noop_open
, &stdout_fd
);
396 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
397 unknown_fds
, 1, noop_close
, NULL
);
398 ok(ret
== -EINVAL
, "EINVAL reported on close of an untracked file descriptor");
400 ret
= fd_tracker_close_unsuspendable_fd(tracker
,
401 &stdout_fd
, 1, noop_close
, NULL
);
404 fd_tracker_destroy(tracker
);
405 ret
= rmdir(test_directory
);
406 ok(ret
== 0, "Test directory is empty");
408 free(test_directory
);
409 free(unlinked_files_directory
);
412 static int open_files(struct fd_tracker
*tracker
,
413 struct lttng_directory_handle
*directory
,
415 struct fs_handle
**handles
,
421 for (i
= 0; i
< count
; i
++) {
424 struct fs_handle
*handle
;
425 mode_t mode
= S_IWUSR
| S_IRUSR
;
427 p_ret
= asprintf(&file_path
, "file-%u", i
);
429 file_paths
[i
] = file_path
;
431 handle
= fd_tracker_open_fs_handle(tracker
, directory
, file_path
,
432 O_RDWR
| O_CREAT
, &mode
);
442 static int open_same_file(struct fd_tracker
*tracker
,
443 struct lttng_directory_handle
*directory
,
446 struct fs_handle
**handles
)
451 for (i
= 0; i
< count
; i
++) {
452 struct fs_handle
*handle
;
453 mode_t mode
= S_IWUSR
| S_IRUSR
;
455 handle
= fd_tracker_open_fs_handle(tracker
, directory
, file
,
456 O_RDWR
| O_CREAT
, &mode
);
467 int cleanup_files(struct fd_tracker
*tracker
, const char *dir
,
468 unsigned int count
, struct fs_handle
**handles
,
474 for (i
= 0; i
< count
; i
++) {
475 char *file_path
= file_paths
[i
];
480 if (fs_handle_unlink(handles
[i
])) {
481 diag("Failed to unlink fs_handle to file %s", file_path
);
484 if (fs_handle_close(handles
[i
])) {
485 diag("Failed to close fs_handle to file %s", file_path
);
494 void test_suspendable_limit(void)
497 const int files_to_create
= TRACKER_FD_LIMIT
* 10;
498 struct fd_tracker
*tracker
;
499 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
500 char *output_files
[files_to_create
];
501 struct fs_handle
*handles
[files_to_create
];
502 struct lttng_directory_handle
*dir_handle
= NULL
;
503 int dir_handle_fd_count
;
505 memset(output_files
, 0, sizeof(output_files
));
506 memset(handles
, 0, sizeof(handles
));
508 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
510 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
515 dir_handle
= lttng_directory_handle_create(test_directory
);
517 dir_handle_fd_count
= !!lttng_directory_handle_uses_fd(dir_handle
);
519 ret
= open_files(tracker
, dir_handle
, files_to_create
, handles
,
521 ok(!ret
, "Created %d files with a limit of %d simultaneously-opened file descriptor",
522 files_to_create
, TRACKER_FD_LIMIT
);
523 check_fd_count(TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+ unknown_fds_count
+
524 dir_handle_fd_count
);
526 ret
= cleanup_files(tracker
, test_directory
, files_to_create
, handles
,
528 ok(!ret
, "Close all opened filesystem handles");
529 ret
= rmdir(test_directory
);
530 ok(ret
== 0, "Test directory is empty");
531 fd_tracker_destroy(tracker
);
532 lttng_directory_handle_put(dir_handle
);
534 free(test_directory
);
535 free(unlinked_files_directory
);
539 void test_mixed_limit(void)
542 const int files_to_create
= TRACKER_FD_LIMIT
;
543 struct fd_tracker
*tracker
;
544 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
545 char *output_files
[files_to_create
];
546 struct fs_handle
*handles
[files_to_create
];
547 struct lttng_directory_handle
*dir_handle
= NULL
;
548 int dir_handle_fd_count
;
550 memset(output_files
, 0, sizeof(output_files
));
551 memset(handles
, 0, sizeof(handles
));
553 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
555 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
560 dir_handle
= lttng_directory_handle_create(test_directory
);
562 dir_handle_fd_count
= !!lttng_directory_handle_uses_fd(dir_handle
);
564 ret
= open_files(tracker
, dir_handle
, files_to_create
, handles
,
566 ok(!ret
, "Created %d files with a limit of %d simultaneously-opened file descriptor",
567 files_to_create
, TRACKER_FD_LIMIT
);
568 diag("Check file descriptor count after opening %u files", files_to_create
);
569 check_fd_count(TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+ unknown_fds_count
+
570 dir_handle_fd_count
);
573 * Open unsuspendable fds (stdin, stdout, stderr) and verify that the fd
574 * cap is still respected.
576 diag("Check file descriptor count after adding %d unsuspendable fds",
578 track_std_fds(tracker
);
579 check_fd_count(TRACKER_FD_LIMIT
+ unknown_fds_count
+
580 dir_handle_fd_count
);
581 diag("Untrack unsuspendable file descriptors");
582 untrack_std_fds(tracker
);
583 check_fd_count(TRACKER_FD_LIMIT
+ unknown_fds_count
+
584 dir_handle_fd_count
);
586 ret
= cleanup_files(tracker
, test_directory
, files_to_create
, handles
,
588 ok(!ret
, "Close all opened filesystem handles");
589 ret
= rmdir(test_directory
);
590 ok(ret
== 0, "Test directory is empty");
591 fd_tracker_destroy(tracker
);
592 lttng_directory_handle_put(dir_handle
);
594 free(test_directory
);
595 free(unlinked_files_directory
);
599 * Open more files than allowed by the fd tracker's cap and write,
600 * byte-by-byte, and in round-robin, a string. The goal is to force
601 * the fd tracker to suspend and resume the fs_handles often and
602 * verify that the fd cap is always respected.
604 * The content of the files is also verified at the end.
607 void test_suspendable_restore(void)
610 const int files_to_create
= TRACKER_FD_LIMIT
* 10;
611 struct fd_tracker
*tracker
;
612 char *output_files
[files_to_create
];
613 struct fs_handle
*handles
[files_to_create
];
614 size_t content_index
;
616 bool write_success
= true;
617 bool fd_cap_respected
= true;
618 bool content_ok
= true;
619 struct lttng_directory_handle
*dir_handle
= NULL
;
620 int dir_handle_fd_count
;
621 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
623 memset(output_files
, 0, sizeof(output_files
));
624 memset(handles
, 0, sizeof(handles
));
626 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
628 tracker
= fd_tracker_create(unlinked_files_directory
, TRACKER_FD_LIMIT
);
633 dir_handle
= lttng_directory_handle_create(test_directory
);
635 dir_handle_fd_count
= !!lttng_directory_handle_uses_fd(dir_handle
);
637 ret
= open_files(tracker
, dir_handle
, files_to_create
, handles
,
639 ok(!ret
, "Created %d files with a limit of %d simultaneously-opened file descriptor",
640 files_to_create
, TRACKER_FD_LIMIT
);
641 diag("Check file descriptor count after opening %u files", files_to_create
);
642 check_fd_count(TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+ unknown_fds_count
+
643 dir_handle_fd_count
);
645 for (content_index
= 0; content_index
< sizeof(file_contents
); content_index
++) {
646 for (handle_index
= 0; handle_index
< files_to_create
; handle_index
++) {
648 struct fs_handle
*handle
= handles
[handle_index
];
649 const char *path
= output_files
[handle_index
];
651 fd
= fs_handle_get_fd(handle
);
653 write_success
= false;
654 diag("Failed to restore fs_handle to %s",
660 ret
= write(fd
, file_contents
+ content_index
, 1);
661 } while (ret
< 0 && errno
== EINTR
);
664 write_success
= false;
665 PERROR("write() to %s failed", path
);
669 if (fd_count() > (TRACKER_FD_LIMIT
+ STDIO_FD_COUNT
+
671 dir_handle_fd_count
)) {
672 fd_cap_respected
= false;
675 fs_handle_put_fd(handle
);
679 ok(write_success
, "Wrote reference string to %d files",
681 ok(fd_cap_respected
, "FD tracker enforced the file descriptor cap");
683 /* Validate the contents of the files. */
684 for (handle_index
= 0; handle_index
< files_to_create
; handle_index
++) {
686 const char *path
= output_files
[handle_index
];
687 char read_buf
[sizeof(file_contents
)];
689 size_t to_read
= sizeof(read_buf
);
692 fd
= lttng_directory_handle_open_file(
693 dir_handle
, path
, O_RDONLY
, 0);
695 ret
= fstat(fd
, &fd_stat
);
697 if (fd_stat
.st_size
!= sizeof(file_contents
)) {
698 diag("Content size of file %s doesn't match, got %" PRId64
", expected %zu",
699 path
, (int64_t) fd_stat
.st_size
,
700 sizeof(file_contents
));
708 ret
= read(fd
, read_pos
, to_read
);
713 } while (to_read
&& (ret
< 0 && errno
== EINTR
));
716 PERROR("Failed to read file %s", path
);
721 if (strcmp(file_contents
, read_buf
)) {
723 diag("File content doesn't match the expectated string");
729 ok(content_ok
, "Files contain the expected content");
730 ret
= cleanup_files(tracker
, test_directory
, files_to_create
, handles
,
732 ok(!ret
, "Close all opened filesystem handles");
733 ret
= rmdir(test_directory
);
734 ok(ret
== 0, "Test directory is empty");
735 fd_tracker_destroy(tracker
);
736 lttng_directory_handle_put(dir_handle
);
738 free(test_directory
);
739 free(unlinked_files_directory
);
743 void test_unlink(void)
746 struct fd_tracker
*tracker
;
747 const int handles_to_open
= 2;
748 struct fs_handle
*handles
[handles_to_open
];
749 struct fs_handle
*new_handle
= NULL
;
751 struct lttng_directory_handle
*dir_handle
= NULL
;
752 const char file_name
[] = "my_file";
753 char *test_directory
= NULL
, *unlinked_files_directory
= NULL
;
754 char *unlinked_file_zero
= NULL
, *unlinked_file_one
= NULL
;
757 get_temporary_directories(&test_directory
, &unlinked_files_directory
);
758 ret
= asprintf(&unlinked_file_zero
, "%s/%u", unlinked_files_directory
,
761 ret
= asprintf(&unlinked_file_one
, "%s/%u", unlinked_files_directory
,
765 tracker
= fd_tracker_create(unlinked_files_directory
, 1);
770 dir_handle
= lttng_directory_handle_create(test_directory
);
773 /* Open two handles to the same file. */
774 ret
= open_same_file(tracker
, dir_handle
, file_name
, handles_to_open
,
776 ok(!ret
, "Successfully opened %i handles to %s/%s", handles_to_open
,
777 test_directory
, file_name
);
783 * Unlinking the first handle should cause the file to be renamed
786 ret
= fs_handle_unlink(handles
[0]);
787 ok(!ret
, "Successfully unlinked the first handle to %s/%s",
788 test_directory
, file_name
);
791 * The original file should no longer exist on the file system, and a
792 * new file named '0' should exist.
794 ok(lttng_directory_handle_stat(dir_handle
, file_name
, &statbuf
) == -1 &&
796 "%s no longer present on file system after unlink",
798 ok(lttng_directory_handle_stat(
799 dir_handle
, unlinked_file_zero
, &statbuf
) == 0,
800 "%s exists on file system after unlink",
804 * It should be possible to use the file descriptors of both handles.
805 * Since only one file descriptor can be opened at once, this should
806 * force the fd_tracker to suspend and restore the handles.
808 fd
= fs_handle_get_fd(handles
[0]);
809 ok(fd
>= 0, "Got fd from first handle");
811 fd
= fs_handle_get_fd(handles
[1]);
812 ok (fd
< 0, "fd tracker does not allow two fds to be used at once");
814 fs_handle_put_fd(handles
[0]);
815 fd
= fs_handle_get_fd(handles
[1]);
816 ok(fd
>= 0, "Got fd from second handle");
817 fs_handle_put_fd(handles
[1]);
819 /* The second unlink should fail with -ENOENT. */
820 ret
= fs_handle_unlink(handles
[1]);
822 "ENOENT is reported when attempting to unlink the second handle to %s/%s",
823 test_directory
, file_name
);
826 * Opening a new handle to 'my_file' should succeed.
828 ret
= open_same_file(tracker
, dir_handle
, file_name
, 1, &new_handle
);
829 ok(!ret
, "Successfully opened a new handle to previously unlinked file %s/%s",
830 test_directory
, file_name
);
834 * Unlinking the new handle should cause the file to be renamed
835 * to '1' since '0' already exists.
837 ret
= fs_handle_unlink(new_handle
);
838 ok(!ret
, "Successfully unlinked the new handle handle to %s/%s",
839 test_directory
, file_name
);
840 ok(stat(unlinked_file_one
, &statbuf
) == 0,
841 "%s exists on file system after unlink",
844 ret
= fs_handle_close(handles
[0]);
845 ok(!ret
, "Successfully closed the first handle");
846 ret
= fs_handle_close(handles
[1]);
847 ok(!ret
, "Successfully closed the second handle");
848 ret
= fs_handle_close(new_handle
);
849 ok(!ret
, "Successfully closed the third handle");
851 ok(lttng_directory_handle_stat(dir_handle
, file_name
, &statbuf
) == -1 &&
853 "%s no longer present on file system after handle close",
855 ok(lttng_directory_handle_stat(
856 dir_handle
, unlinked_file_zero
, &statbuf
) == -1 &&
858 "%s no longer present on file system after handle close",
860 ok(lttng_directory_handle_stat(dir_handle
, unlinked_file_one
,
863 "%s no longer present on file system after handle close",
866 ret
= rmdir(test_directory
);
867 ok(ret
== 0, "Test directory is empty");
869 fd_tracker_destroy(tracker
);
870 free(test_directory
);
871 free(unlinked_files_directory
);
872 free(unlinked_file_zero
);
873 free(unlinked_file_one
);
874 lttng_directory_handle_put(dir_handle
);
877 int main(int argc
, char **argv
)
879 plan_tests(NUM_TESTS
);
880 diag("File descriptor tracker unit tests");
882 rcu_register_thread();
884 unknown_fds_count
= fd_count() - STDIO_FD_COUNT
;
885 assert(unknown_fds_count
>= 0);
887 diag("Unsuspendable - basic");
888 test_unsuspendable_basic();
889 diag("Unsuspendable - callback return values");
890 test_unsuspendable_cb_return();
891 diag("Unsuspendable - duplicate file descriptors");
892 test_unsuspendable_duplicate();
893 diag("Unsuspendable - closing an untracked file descriptor");
894 test_unsuspendable_close_untracked();
895 diag("Unsuspendable - check that file descritptor limit is enforced");
896 test_unsuspendable_limit();
898 diag("Suspendable - check that file descritptor limit is enforced");
899 test_suspendable_limit();
900 diag("Suspendable - restoration test");
901 test_suspendable_restore();
903 diag("Mixed - check that file descritptor limit is enforced");
906 diag("Suspendable - Unlinking test");
910 rcu_unregister_thread();
911 return exit_status();