# HG changeset patch # User Paul Eggert # Date 1370934621 25200 # Node ID 88b6febaed97724358d14f8a2599f8d288bf876c # Parent 4af247cb0aef86d775896e299c8df150eca083b2 tests: port large-fd POSIX spawn tests to OS X Problem reported by Daiki Ueno in . * tests/test-posix_spawn_file_actions_addclose.c: * tests/test-posix_spawn_file_actions_adddup2.c: * tests/test-posix_spawn_file_actions_addopen.c: Include , for OPEN_MAX, if available. (big_fd): New static function. (main): Use it. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2013-06-11 Paul Eggert + + tests: port large-fd POSIX spawn tests to OS X + Problem reported by Daiki Ueno in + . + * tests/test-posix_spawn_file_actions_addclose.c: + * tests/test-posix_spawn_file_actions_adddup2.c: + * tests/test-posix_spawn_file_actions_addopen.c: + Include , for OPEN_MAX, if available. + (big_fd): New static function. + (main): Use it. + 2013-06-04 Bernhard Voelker tests/nap.h: use an adaptive delay to avoid ctime update issues diff --git a/tests/test-posix_spawn_file_actions_addclose.c b/tests/test-posix_spawn_file_actions_addclose.c --- a/tests/test-posix_spawn_file_actions_addclose.c +++ b/tests/test-posix_spawn_file_actions_addclose.c @@ -23,10 +23,25 @@ (posix_spawn_file_actions_t *, int)); #include +#include #include #include "macros.h" +/* Return a file descriptor that is too big to use. + Prefer the smallest such fd, except use OPEN_MAX if it is defined + and is greater than getdtablesize (), as that's how OS X works. */ +static int +big_fd (void) +{ + int fd = getdtablesize (); +#ifdef OPEN_MAX + if (fd < OPEN_MAX) + fd = OPEN_MAX; +#endif + return fd; +} + int main (void) { @@ -40,9 +55,9 @@ ASSERT (posix_spawn_file_actions_addclose (&actions, -1) == EBADF); } { + int bad_fd = big_fd (); errno = 0; - ASSERT (posix_spawn_file_actions_addclose (&actions, getdtablesize ()) - == EBADF); + ASSERT (posix_spawn_file_actions_addclose (&actions, bad_fd) == EBADF); } return 0; diff --git a/tests/test-posix_spawn_file_actions_adddup2.c b/tests/test-posix_spawn_file_actions_adddup2.c --- a/tests/test-posix_spawn_file_actions_adddup2.c +++ b/tests/test-posix_spawn_file_actions_adddup2.c @@ -23,14 +23,29 @@ (posix_spawn_file_actions_t *, int, int)); #include +#include #include #include "macros.h" +/* Return a file descriptor that is too big to use. + Prefer the smallest such fd, except use OPEN_MAX if it is defined + and is greater than getdtablesize (), as that's how OS X works. */ +static int +big_fd (void) +{ + int fd = getdtablesize (); +#ifdef OPEN_MAX + if (fd < OPEN_MAX) + fd = OPEN_MAX; +#endif + return fd; +} + int main (void) { - int bad_fd = getdtablesize (); + int bad_fd = big_fd (); posix_spawn_file_actions_t actions; ASSERT (posix_spawn_file_actions_init (&actions) == 0); diff --git a/tests/test-posix_spawn_file_actions_addopen.c b/tests/test-posix_spawn_file_actions_addopen.c --- a/tests/test-posix_spawn_file_actions_addopen.c +++ b/tests/test-posix_spawn_file_actions_addopen.c @@ -25,10 +25,25 @@ #include #include +#include #include #include "macros.h" +/* Return a file descriptor that is too big to use. + Prefer the smallest such fd, except use OPEN_MAX if it is defined + and is greater than getdtablesize (), as that's how OS X works. */ +static int +big_fd (void) +{ + int fd = getdtablesize (); +#ifdef OPEN_MAX + if (fd < OPEN_MAX) + fd = OPEN_MAX; +#endif + return fd; +} + int main (void) { @@ -44,8 +59,9 @@ == EBADF); } { + int bad_fd = big_fd (); errno = 0; - ASSERT (posix_spawn_file_actions_addopen (&actions, getdtablesize (), + ASSERT (posix_spawn_file_actions_addopen (&actions, bad_fd, "foo", 0, O_RDONLY) == EBADF); }