Fix: statements with side-effects in assert statements
[lttng-tools.git] / tests / unit / test_fd_tracker.c
index db9b4248b4b137d239d58872b0bfa9a86e46aa2f..a1e4c017a710fe175f1df26e96b055ec3712d68b 100644 (file)
@@ -15,7 +15,6 @@
 #include <sys/types.h>
 #include <dirent.h>
 #include <stdio.h>
-#include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -24,6 +23,7 @@
 #include <urcu.h>
 
 #include <common/compat/directory-handle.h>
+#include <common/compat/errno.h>
 #include <common/error.h>
 #include <common/fd-tracker/fd-tracker.h>
 
@@ -40,6 +40,13 @@ int lttng_opt_mi;
 #define TMP_DIR_PATTERN "/tmp/fd-tracker-XXXXXX"
 #define TEST_UNLINK_DIRECTORY_NAME "unlinked_files"
 
+#ifdef __linux__
+#define SELF_FD_DIR "/proc/self/fd"
+#else
+/* Most Unices have /dev/fd */
+#define SELF_FD_DIR "/dev/fd"
+#endif
+
 /*
  * Count of fds, beyond stdin, stderr, stdout that were open
  * at the launch of the test. This allows the test to succeed when
@@ -84,9 +91,9 @@ int fd_count(void)
        struct dirent *entry;
        int count = 0;
 
-       dir = opendir("/proc/self/fd");
+       dir = opendir(SELF_FD_DIR);
        if (!dir) {
-               perror("# Failed to enumerate /proc/self/fd/ 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;
        }
@@ -100,7 +107,7 @@ 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 directory file descriptor");
+               perror("# Failed to close test program's " SELF_FD_DIR " directory file descriptor");
        }
 end:
        return count;
@@ -387,8 +394,10 @@ void test_unsuspendable_close_untracked(void)
 
        ret = pipe(unknown_fds);
        assert(!ret);
-       assert(close(unknown_fds[0]) == 0);
-       assert(close(unknown_fds[1]) == 0);
+       ret = close(unknown_fds[0]);
+       assert(ret == 0);
+       ret = close(unknown_fds[1]);
+       assert(ret == 0);
 
        ret = fd_tracker_open_unsuspendable_fd(tracker, &out_fd,
                        NULL, 1, noop_open, &stdout_fd);
This page took 0.024076 seconds and 4 git commands to generate.