1 /*
2 * Copyright (C) Bull S.A. 2001
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 /*
20 * Test Name: mknod09
21 *
22 * Test Description:
23 * Verify that, mknod() fails with -1 and sets errno to EINVAL if the mode is
24 * different than a normal file, device special file or FIFO.
25 *
26 * Expected Result:
27 * mknod() should fail with return value -1 and sets expected errno.
28 *
29 * Algorithm:
30 * Setup:
31 * Setup signal handling.
32 * Check id is super/root
33 * Pause for SIGUSR1 if option specified.
34 * Create temporary directory.
35 *
36 * Test:
37 * Loop if the proper options are given.
38 * Execute system call
39 * Check return code, if system call failed (return=-1)
40 * if errno set == expected errno
41 * Issue sys call fails with expected return value and errno.
42 * Otherwise,
43 * Issue sys call fails with unexpected errno.
44 * Otherwise,
45 * Issue sys call returns unexpected value.
46 *
47 * Cleanup:
48 * Print errno log and/or timing stats if options given
49 * Delete the temporary directory created.
50 *
51 * Usage: <for command-line>
52 * mknod09 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t]
53 * where, -c n : Run n copies concurrently.
54 * -e : Turn on errno logging.
55 * -f : Turn off functionality Testing.
56 * -i n : Execute test n times.
57 * -I x : Execute test for x seconds.
58 * -P x : Pause for x seconds between iterations.
59 * -t : Turn on syscall timing.
60 *
61 * HISTORY
62 * 05/2002 Ported by Andr� Merlier
63 *
64 * RESTRICTIONS:
65 * This test should be run by 'super-user' (root) only.
66 *
67 */
68
69 #include <errno.h>
70 #include <sys/stat.h>
71 #include "test.h"
72
73 #define MODE_RWX S_IFMT /* mode different from those expected */
74 #define TNODE "tnode" /*pathname */
75
76 char *TCID = "mknod09";
77 int TST_TOTAL = 1;
78
79 void setup(); /* setup function for the test */
80 void cleanup(); /* cleanup function for the test */
81
main(int ac,char ** av)82 int main(int ac, char **av)
83 {
84 int lc;
85 char *test_desc; /* test specific error message */
86
87 tst_parse_opts(ac, av, NULL, NULL);
88
89 setup();
90
91 for (lc = 0; TEST_LOOPING(lc); lc++) {
92 test_desc = "EINVAL";
93
94 tst_count = 0;
95
96 /*
97 * Call mknod(2) to test condition.
98 * verify that it fails with -1 return value and
99 * sets appropriate errno.
100 */
101 TEST(mknod(TNODE, MODE_RWX, 0));
102
103 /* Check return code from mknod(2) */
104 if (TEST_RETURN != -1) {
105 tst_resm(TFAIL, "mknod() returned %ld,"
106 "expected -1, errno=%d", TEST_RETURN,
107 EINVAL);
108 } else {
109 if (TEST_ERRNO == EINVAL) {
110 tst_resm(TPASS, "mknod() fails with expected "
111 "error EINVAL errno:%d", TEST_ERRNO);
112 } else {
113 tst_resm(TFAIL, "mknod() fails, %s, "
114 "errno=%d, expected errno=%d",
115 test_desc, TEST_ERRNO, EINVAL);
116 }
117 }
118 }
119
120 cleanup();
121
122 tst_exit();
123 }
124
125 /*
126 * setup(void)
127 */
setup(void)128 void setup(void)
129 {
130 tst_require_root();
131
132 /* Capture unexpected signals */
133 tst_sig(NOFORK, DEF_HANDLER, cleanup);
134
135 TEST_PAUSE;
136
137 /* Make a temp dir and cd to it */
138 tst_tmpdir();
139 }
140
141 /*
142 * cleanup()
143 */
cleanup(void)144 void cleanup(void)
145 {
146
147 tst_rmdir();
148
149 }
150