annotate tests/test-posix_spawn_file_actions_adddup2.c @ 17418:88b6febaed97

tests: port large-fd POSIX spawn tests to OS X Problem reported by Daiki Ueno in <http://lists.gnu.org/archive/html/bug-gnulib/2013-06/msg00031.html>. * 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 <limits.h>, for OPEN_MAX, if available. (big_fd): New static function. (main): Use it.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 11 Jun 2013 00:10:21 -0700
parents 160b88fd4691
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test posix_spawn_file_actions_adddup2() function.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 Copyright (C) 2011-2013 Free Software Foundation, Inc.
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <spawn.h>
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "signature.h"
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 SIGNATURE_CHECK (posix_spawn_file_actions_adddup2, int,
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 (posix_spawn_file_actions_t *, int, int));
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <errno.h>
17418
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
26 #include <limits.h>
17373
160b88fd4691 tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
27 #include <unistd.h>
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include "macros.h"
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
17418
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
31 /* Return a file descriptor that is too big to use.
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
32 Prefer the smallest such fd, except use OPEN_MAX if it is defined
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
33 and is greater than getdtablesize (), as that's how OS X works. */
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
34 static int
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
35 big_fd (void)
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
36 {
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
37 int fd = getdtablesize ();
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
38 #ifdef OPEN_MAX
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
39 if (fd < OPEN_MAX)
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
40 fd = OPEN_MAX;
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
41 #endif
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
42 return fd;
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
43 }
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
44
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 int
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 main (void)
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 {
17418
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
48 int bad_fd = big_fd ();
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 posix_spawn_file_actions_t actions;
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 ASSERT (posix_spawn_file_actions_init (&actions) == 0);
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 /* Test behaviour for invalid file descriptors. */
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 {
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 errno = 0;
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 ASSERT (posix_spawn_file_actions_adddup2 (&actions, -1, 2) == EBADF);
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 }
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 {
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 errno = 0;
17373
160b88fd4691 tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
60 ASSERT (posix_spawn_file_actions_adddup2 (&actions, bad_fd, 2) == EBADF);
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 {
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 errno = 0;
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 ASSERT (posix_spawn_file_actions_adddup2 (&actions, 2, -1) == EBADF);
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 }
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 {
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 errno = 0;
17373
160b88fd4691 tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
68 ASSERT (posix_spawn_file_actions_adddup2 (&actions, 2, bad_fd) == EBADF);
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 }
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 return 0;
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 }