blob: a5ee9e620d1f2cba285e5510a626705121c9474e [file] [log] [blame]
robbiewcd9464c2002-06-10 14:58:26 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiewcd9464c2002-06-10 14:58:26 +000018 */
19/*
20 * Test Name: mknod09
21 *
22 * Test Description:
subrata_modak4bb656a2009-02-26 12:02:09 +000023 * Verify that, mknod() fails with -1 and sets errno to EINVAL if the mode is
robbiewcd9464c2002-06-10 14:58:26 +000024 * 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)
subrata_modak56207ce2009-03-23 13:35:39 +000040 * if errno set == expected errno
41 * Issue sys call fails with expected return value and errno.
42 * Otherwise,
robbiewcd9464c2002-06-10 14:58:26 +000043 * 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"
robbiewcd9464c2002-06-10 14:58:26 +000072
subrata_modak56207ce2009-03-23 13:35:39 +000073#define MODE_RWX S_IFMT /* mode different from those expected */
robbiewcd9464c2002-06-10 14:58:26 +000074#define TNODE "tnode" /*pathname */
75
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020076char *TCID = "mknod09";
77int TST_TOTAL = 1;
robbiewcd9464c2002-06-10 14:58:26 +000078
79void setup(); /* setup function for the test */
80void cleanup(); /* cleanup function for the test */
81
subrata_modak56207ce2009-03-23 13:35:39 +000082int main(int ac, char **av)
robbiewcd9464c2002-06-10 14:58:26 +000083{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020084 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020085 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000086 char *test_desc; /* test specific error message */
robbiewcd9464c2002-06-10 14:58:26 +000087
Garrett Cooper45e285d2010-11-22 12:19:25 -080088 msg = parse_opts(ac, av, NULL, NULL);
89 if (msg != NULL) {
robbiewcd9464c2002-06-10 14:58:26 +000090 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080091
robbiewcd9464c2002-06-10 14:58:26 +000092 }
93
robbiewcd9464c2002-06-10 14:58:26 +000094 setup();
subrata_modakbdbaec52009-02-26 12:14:51 +000095
robbiewcd9464c2002-06-10 14:58:26 +000096 for (lc = 0; TEST_LOOPING(lc); lc++) {
97 test_desc = "EINVAL";
subrata_modak56207ce2009-03-23 13:35:39 +000098
Caspar Zhangd59a6592013-03-07 14:59:12 +080099 tst_count = 0;
robbiewcd9464c2002-06-10 14:58:26 +0000100
101 /*
subrata_modak56207ce2009-03-23 13:35:39 +0000102 * Call mknod(2) to test condition.
103 * verify that it fails with -1 return value and
104 * sets appropriate errno.
105 */
robbiewcd9464c2002-06-10 14:58:26 +0000106 TEST(mknod(TNODE, MODE_RWX, 0));
subrata_modak56207ce2009-03-23 13:35:39 +0000107
robbiewcd9464c2002-06-10 14:58:26 +0000108 /* Check return code from mknod(2) */
109 if (TEST_RETURN != -1) {
subrata_modak923b23f2009-11-02 13:57:16 +0000110 tst_resm(TFAIL, "mknod() returned %ld,"
subrata_modak56207ce2009-03-23 13:35:39 +0000111 "expected -1, errno=%d", TEST_RETURN,
Cyril Hrubis605fa332015-02-04 13:11:20 +0100112 EINVAL);
subrata_modak56207ce2009-03-23 13:35:39 +0000113 } else {
Cyril Hrubis605fa332015-02-04 13:11:20 +0100114 if (TEST_ERRNO == EINVAL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000115 tst_resm(TPASS, "mknod() fails with expected "
116 "error EINVAL errno:%d", TEST_ERRNO);
robbiewcd9464c2002-06-10 14:58:26 +0000117 } else {
118 tst_resm(TFAIL, "mknod() fails, %s, "
119 "errno=%d, expected errno=%d",
Cyril Hrubis605fa332015-02-04 13:11:20 +0100120 test_desc, TEST_ERRNO, EINVAL);
robbiewcd9464c2002-06-10 14:58:26 +0000121 }
122 }
subrata_modak56207ce2009-03-23 13:35:39 +0000123 }
robbiewcd9464c2002-06-10 14:58:26 +0000124
robbiewcd9464c2002-06-10 14:58:26 +0000125 cleanup();
126
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800127 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800128}
robbiewcd9464c2002-06-10 14:58:26 +0000129
130/*
131 * setup(void)
132 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400133void setup(void)
robbiewcd9464c2002-06-10 14:58:26 +0000134{
Nicolas Jolyd4ceb372014-06-22 17:03:57 +0200135 tst_require_root(NULL);
136
robbiewcd9464c2002-06-10 14:58:26 +0000137 /* Capture unexpected signals */
138 tst_sig(NOFORK, DEF_HANDLER, cleanup);
139
robbiewcd9464c2002-06-10 14:58:26 +0000140 TEST_PAUSE;
141
142 /* Make a temp dir and cd to it */
143 tst_tmpdir();
144}
145
146/*
147 * cleanup()
148 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400149void cleanup(void)
robbiewcd9464c2002-06-10 14:58:26 +0000150{
robbiewcd9464c2002-06-10 14:58:26 +0000151
robbiewcd9464c2002-06-10 14:58:26 +0000152 tst_rmdir();
subrata_modak56207ce2009-03-23 13:35:39 +0000153
Chris Dearmanec6edca2012-10-17 19:54:01 -0700154}