robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 18 | */ |
| 19 | /* |
| 20 | * Test Name: mknod09 |
| 21 | * |
| 22 | * Test Description: |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 23 | * Verify that, mknod() fails with -1 and sets errno to EINVAL if the mode is |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 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) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 40 | * if errno set == expected errno |
| 41 | * Issue sys call fails with expected return value and errno. |
| 42 | * Otherwise, |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 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" |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 72 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | #define MODE_RWX S_IFMT /* mode different from those expected */ |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 74 | #define TNODE "tnode" /*pathname */ |
| 75 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 76 | char *TCID = "mknod09"; |
| 77 | int TST_TOTAL = 1; |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 78 | |
| 79 | void setup(); /* setup function for the test */ |
| 80 | void cleanup(); /* cleanup function for the test */ |
| 81 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | int main(int ac, char **av) |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 83 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 84 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 85 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | char *test_desc; /* test specific error message */ |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 87 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 88 | msg = parse_opts(ac, av, NULL, NULL); |
| 89 | if (msg != NULL) { |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 90 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 91 | |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 92 | } |
| 93 | |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 94 | setup(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 95 | |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 96 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 97 | test_desc = "EINVAL"; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 99 | tst_count = 0; |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 100 | |
| 101 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 102 | * Call mknod(2) to test condition. |
| 103 | * verify that it fails with -1 return value and |
| 104 | * sets appropriate errno. |
| 105 | */ |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 106 | TEST(mknod(TNODE, MODE_RWX, 0)); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 107 | |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 108 | /* Check return code from mknod(2) */ |
| 109 | if (TEST_RETURN != -1) { |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 110 | tst_resm(TFAIL, "mknod() returned %ld," |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 111 | "expected -1, errno=%d", TEST_RETURN, |
Cyril Hrubis | 605fa33 | 2015-02-04 13:11:20 +0100 | [diff] [blame] | 112 | EINVAL); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 113 | } else { |
Cyril Hrubis | 605fa33 | 2015-02-04 13:11:20 +0100 | [diff] [blame] | 114 | if (TEST_ERRNO == EINVAL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | tst_resm(TPASS, "mknod() fails with expected " |
| 116 | "error EINVAL errno:%d", TEST_ERRNO); |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 117 | } else { |
| 118 | tst_resm(TFAIL, "mknod() fails, %s, " |
| 119 | "errno=%d, expected errno=%d", |
Cyril Hrubis | 605fa33 | 2015-02-04 13:11:20 +0100 | [diff] [blame] | 120 | test_desc, TEST_ERRNO, EINVAL); |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 123 | } |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 124 | |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 125 | cleanup(); |
| 126 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 127 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 128 | } |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * setup(void) |
| 132 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 133 | void setup(void) |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 134 | { |
Nicolas Joly | d4ceb37 | 2014-06-22 17:03:57 +0200 | [diff] [blame] | 135 | tst_require_root(NULL); |
| 136 | |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 137 | /* Capture unexpected signals */ |
| 138 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 139 | |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 140 | TEST_PAUSE; |
| 141 | |
| 142 | /* Make a temp dir and cd to it */ |
| 143 | tst_tmpdir(); |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * cleanup() |
| 148 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 149 | void cleanup(void) |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 150 | { |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 151 | |
robbiew | cd9464c | 2002-06-10 14:58:26 +0000 | [diff] [blame] | 152 | tst_rmdir(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 153 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 154 | } |