annotate tests/test-mkfifo.h @ 40186:8964917f9574

autoupdate
author Karl Berry <karl@freefriends.org>
date Mon, 18 Feb 2019 08:02:49 -0800
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12266
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Tests of mkfifo and friends.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
12266
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
12266
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 /* This file is designed to test mkfifo(n,m), mknod(n,m|S_IFIFO,0),
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20 mkfifoat(AT_FDCWD,n,m), and mknodat(AT_FDCWD,n,m|S_IFIFO,0). FUNC
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 is the function to test. Assumes that BASE and ASSERT are already
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22 defined, and that appropriate headers are already included. If
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
23 PRINT, warn before skipping symlink tests with status 77. */
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
24
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25 static int
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 test_mkfifo (int (*func) (char const *, mode_t), bool print)
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27 {
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
28 int result = func (BASE "fifo", 0600);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 struct stat st;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 if (result == -1 && errno == ENOSYS)
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 {
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32 if (print)
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33 fputs ("skipping test: no support for named fifos\n", stderr);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34 return 77;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 }
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36 ASSERT (result == 0);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 ASSERT (stat (BASE "fifo", &st) == 0);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38 ASSERT (S_ISFIFO (st.st_mode));
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 /* Sanity checks of failures. */
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 errno = 0;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 ASSERT (func ("", S_IRUSR | S_IWUSR) == -1);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 ASSERT (errno == ENOENT);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 errno = 0;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 ASSERT (func (".", 0600) == -1);
17516
78e9001f9ab0 mkfifo-tests, etc.: allow HP-UX 11.11 bug
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
46 /* Allow HP-UX 11.11's EISDIR, even though POSIX says it's wrong,
78e9001f9ab0 mkfifo-tests, etc.: allow HP-UX 11.11 bug
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
47 since it doesn't really hurt anything and we lack the energy to
78e9001f9ab0 mkfifo-tests, etc.: allow HP-UX 11.11 bug
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
48 fix it. */
78e9001f9ab0 mkfifo-tests, etc.: allow HP-UX 11.11 bug
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
49 ASSERT (errno == EEXIST || errno == EINVAL || errno == EISDIR);
12266
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 errno = 0;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 ASSERT (func (BASE "fifo", 0600) == -1);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52 ASSERT (errno == EEXIST);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 ASSERT (unlink (BASE "fifo") == 0);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 errno = 0;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 ASSERT (func (BASE "fifo/", 0600) == -1);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 ASSERT (errno == ENOENT || errno == ENOTDIR);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 /* Test trailing slash behavior. */
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59 if (symlink (BASE "fifo", BASE "link"))
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 {
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 if (print)
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 fputs ("skipping test: symlinks not supported on this file system\n",
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
63 stderr);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 return 77;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65 }
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 errno = 0;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 ASSERT (func (BASE "link", 0600) == -1);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 ASSERT (errno == EEXIST);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
69 errno = 0;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
70 ASSERT (func (BASE "link/", 0600) == -1);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
71 ASSERT (errno == EEXIST || errno == ENOENT || errno == ENOTDIR);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
72 errno = 0;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
73 ASSERT (unlink (BASE "fifo") == -1);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 ASSERT (errno == ENOENT);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 ASSERT (unlink (BASE "link") == 0);
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76 return 0;
37fd04a02bc8 mkfifo: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 }