[PATCH 10/12] tests: Use /dev/fd on FreeBSD to determine open FDs

Philip Withnall philip at tecnocode.co.uk
Fri Feb 15 04:57:17 PST 2013


FreeBSD doesn’t have /proc/self/fd; it uses fdescfs instead, which must be
mounted explicitly before the test suite can be run, using:
    mount -f fdescfs fdescfs /dev/fd

Signed-off-by: Philip Withnall <philip at tecnocode.co.uk>
---
 tests/test-helpers.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/tests/test-helpers.c b/tests/test-helpers.c
index 4761b09..969e4f1 100644
--- a/tests/test-helpers.c
+++ b/tests/test-helpers.c
@@ -20,6 +20,12 @@
  * OF THIS SOFTWARE.
  */
 
+#include "../config.h"
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
 #include <assert.h>
 #include <errno.h>
 #include <dirent.h>
@@ -28,6 +34,16 @@
 
 #include "test-runner.h"
 
+#ifdef __FreeBSD__
+/* FreeBSD uses fdescfs (which must be mounted using:
+ *    mount -t fdescfs fdescfs /dev/fd
+ * before the test suite can be run). */
+#define OPEN_FDS_DIR "/dev/fd"
+#else
+/* Linux. */
+#define OPEN_FDS_DIR "/proc/self/fd"
+#endif
+
 int
 count_open_fds(void)
 {
@@ -35,8 +51,8 @@ count_open_fds(void)
 	struct dirent *ent;
 	int count = 0;
 
-	dir = opendir("/proc/self/fd");
-	assert(dir && "opening /proc/self/fd failed.");
+	dir = opendir(OPEN_FDS_DIR);
+	assert(dir && "opening " OPEN_FDS_DIR " failed.");
 
 	errno = 0;
 	while ((ent = readdir(dir))) {
@@ -45,7 +61,7 @@ count_open_fds(void)
 			continue;
 		count++;
 	}
-	assert(errno == 0 && "reading /proc/self/fd failed.");
+	assert(errno == 0 && "reading " OPEN_FDS_DIR " failed.");
 
 	closedir(dir);
 
-- 
1.7.11.7

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 230 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20130215/a84bb9cb/attachment.pgp>


More information about the wayland-devel mailing list