blob: b637ab64fca27c67668c99c614dceeb955f7ed5c [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000022 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 *
32 */
subrata_modak56207ce2009-03-23 13:35:39 +000033/* $Id: mkdir01.c,v 1.7 2009/03/23 13:35:54 subrata_modak Exp $ */
plars865695b2001-08-27 22:15:12 +000034/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000035 *
plars865695b2001-08-27 22:15:12 +000036 * OS Test - Silicon Graphics, Inc.
subrata_modak4bb656a2009-02-26 12:02:09 +000037 *
plars865695b2001-08-27 22:15:12 +000038 * TEST IDENTIFIER : mkdir01
subrata_modak4bb656a2009-02-26 12:02:09 +000039 *
plars865695b2001-08-27 22:15:12 +000040 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000041 *
plars865695b2001-08-27 22:15:12 +000042 * TEST TITLE : Basic errno test for mkdir(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000043 *
plars865695b2001-08-27 22:15:12 +000044 * PARENT DOCUMENT : mkstds02
subrata_modak4bb656a2009-02-26 12:02:09 +000045 *
plars865695b2001-08-27 22:15:12 +000046 * TEST CASE TOTAL : 2
subrata_modak4bb656a2009-02-26 12:02:09 +000047 *
plars865695b2001-08-27 22:15:12 +000048 * WALL CLOCK TIME : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000049 *
plars865695b2001-08-27 22:15:12 +000050 * CPU TYPES : ALL
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
plars865695b2001-08-27 22:15:12 +000052 * AUTHOR : Bill Branum
subrata_modak4bb656a2009-02-26 12:02:09 +000053 *
plars865695b2001-08-27 22:15:12 +000054 * CO-PILOT : Kathy Olmsted
subrata_modak4bb656a2009-02-26 12:02:09 +000055 *
plars865695b2001-08-27 22:15:12 +000056 * DATE STARTED : 4/15/92
subrata_modak4bb656a2009-02-26 12:02:09 +000057 *
plars865695b2001-08-27 22:15:12 +000058 * INITIAL RELEASE : UNICOS 7.0
subrata_modak4bb656a2009-02-26 12:02:09 +000059 *
plars865695b2001-08-27 22:15:12 +000060 * TEST CASES
subrata_modak4bb656a2009-02-26 12:02:09 +000061 *
plars865695b2001-08-27 22:15:12 +000062 * mkdir(2) test for errno(s) EFAULT.
subrata_modakbdbaec52009-02-26 12:14:51 +000063 *
plars865695b2001-08-27 22:15:12 +000064 * INPUT SPECIFICATIONS
65 * The standard options for system call tests are accepted.
66 * (See the parse_opts(3) man page).
subrata_modak4bb656a2009-02-26 12:02:09 +000067 *
plars865695b2001-08-27 22:15:12 +000068 * DURATION
69 * Terminates - with frequency and infinite modes.
subrata_modak4bb656a2009-02-26 12:02:09 +000070 *
plars865695b2001-08-27 22:15:12 +000071 * SIGNALS
72 * Uses SIGUSR1 to pause before test if option set.
73 * (See the parse_opts(3) man page).
74 *
75 * ENVIRONMENTAL NEEDS
76 * No run-time environmental needs.
subrata_modak4bb656a2009-02-26 12:02:09 +000077 *
plars865695b2001-08-27 22:15:12 +000078 * DETAILED DESCRIPTION
79 * This test will verify that mkdir(2) returns a value of
80 * -1 and sets errno to EFAULT when the path argument points
81 * outside (above/below) the allocated address space of the
82 * process.
subrata_modak4bb656a2009-02-26 12:02:09 +000083 *
plars865695b2001-08-27 22:15:12 +000084 * Setup:
85 * Setup signal handling.
86 * Create and make current a temporary directory.
87 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000088 *
plars865695b2001-08-27 22:15:12 +000089 * Test:
90 * Loop if the proper options are given.
91 * Execute system call
92 * Check return code, if system call failed (return=-1)
93 * Log the errno.
94 * If doing functional test
95 * check the errno returned and print result message
subrata_modak4bb656a2009-02-26 12:02:09 +000096 *
plars865695b2001-08-27 22:15:12 +000097 * Cleanup:
98 * Print errno log and/or timing stats if options given
99 * Remove the temporary directory.
100 * Exit.
subrata_modak4bb656a2009-02-26 12:02:09 +0000101 *
102 *
plars865695b2001-08-27 22:15:12 +0000103 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
104
105#include <errno.h>
106#include <string.h>
107#include <signal.h>
108#include <sys/stat.h>
109#include <sys/types.h>
plars1ad84512002-07-23 13:11:18 +0000110#include <sys/mman.h>
plars865695b2001-08-27 22:15:12 +0000111#include <fcntl.h>
112#include <unistd.h>
113#include "test.h"
plars865695b2001-08-27 22:15:12 +0000114
115void setup();
116void cleanup();
117
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200118char *TCID = "mkdir01";
119int TST_TOTAL = 2;
plars865695b2001-08-27 22:15:12 +0000120
subrata_modak56207ce2009-03-23 13:35:39 +0000121char *bad_addr = 0;
plars1ad84512002-07-23 13:11:18 +0000122
subrata_modak56207ce2009-03-23 13:35:39 +0000123int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +0000124{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200125 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200126 const char *msg;
plars865695b2001-08-27 22:15:12 +0000127
Garrett Cooper45e285d2010-11-22 12:19:25 -0800128 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800129 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +0000130
subrata_modak56207ce2009-03-23 13:35:39 +0000131 setup();
plars865695b2001-08-27 22:15:12 +0000132
subrata_modak56207ce2009-03-23 13:35:39 +0000133 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000134
Caspar Zhangd59a6592013-03-07 14:59:12 +0800135 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000136
subrata_modak56207ce2009-03-23 13:35:39 +0000137 /*
138 * TEST CASE: 1
139 * mkdir() call with pointer below allocated address space.
140 */
plars865695b2001-08-27 22:15:12 +0000141
subrata_modak56207ce2009-03-23 13:35:39 +0000142 /* Call mkdir(2) */
143 TEST(mkdir(bad_addr, 0777));
subrata_modakbdbaec52009-02-26 12:14:51 +0000144
subrata_modak56207ce2009-03-23 13:35:39 +0000145 /* check return code */
146 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000147 }
plars865695b2001-08-27 22:15:12 +0000148
Cyril Hrubise38b9612014-06-02 17:20:57 +0200149 if (TEST_RETURN == -1) {
150 if (TEST_ERRNO == EFAULT) {
151 tst_resm(TPASS,
152 "mkdir - path argument pointing below allocated address space failed as expected with errno %d : %s",
153 TEST_ERRNO,
154 strerror(TEST_ERRNO));
subrata_modak56207ce2009-03-23 13:35:39 +0000155 } else {
156 tst_resm(TFAIL,
Cyril Hrubise38b9612014-06-02 17:20:57 +0200157 "mkdir - path argument pointing below allocated address space failed with errno %d : %s but expected %d (EFAULT)",
158 TEST_ERRNO,
159 strerror(TEST_ERRNO), EFAULT);
subrata_modak56207ce2009-03-23 13:35:39 +0000160 }
Cyril Hrubise38b9612014-06-02 17:20:57 +0200161 } else {
162 tst_resm(TFAIL,
163 "mkdir - path argument pointing below allocated address space succeeded unexpectedly.");
164
subrata_modak56207ce2009-03-23 13:35:39 +0000165 }
robbiewd34d5812005-07-11 22:28:09 +0000166#if !defined(UCLINUX)
subrata_modak56207ce2009-03-23 13:35:39 +0000167 /*
168 * TEST CASE: 2
169 * mkdir() call with pointer above allocated address space.
170 */
plars865695b2001-08-27 22:15:12 +0000171
subrata_modak56207ce2009-03-23 13:35:39 +0000172 /* Call mkdir(2) */
173 TEST(mkdir(get_high_address(), 0777));
subrata_modakbdbaec52009-02-26 12:14:51 +0000174
subrata_modak56207ce2009-03-23 13:35:39 +0000175 /* check return code */
176 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000177 }
plars865695b2001-08-27 22:15:12 +0000178
Cyril Hrubise38b9612014-06-02 17:20:57 +0200179 if (TEST_RETURN == -1) {
180 if (TEST_ERRNO == EFAULT) {
181 tst_resm(TPASS,
182 "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s",
183 TEST_ERRNO,
184 strerror(TEST_ERRNO));
subrata_modak56207ce2009-03-23 13:35:39 +0000185 } else {
186 tst_resm(TFAIL,
Cyril Hrubise38b9612014-06-02 17:20:57 +0200187 "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)",
188 TEST_ERRNO,
189 strerror(TEST_ERRNO), EFAULT);
subrata_modak56207ce2009-03-23 13:35:39 +0000190 }
Cyril Hrubise38b9612014-06-02 17:20:57 +0200191 } else {
192 tst_resm(TFAIL,
193 "mkdir - path argument pointing above allocated address space succeeded unexpectedly.");
194
subrata_modak56207ce2009-03-23 13:35:39 +0000195 }
robbiewd34d5812005-07-11 22:28:09 +0000196#endif /* if !defined(UCLINUX) */
plars865695b2001-08-27 22:15:12 +0000197
Garrett Cooper2c282152010-12-16 00:55:50 -0800198 }
plars865695b2001-08-27 22:15:12 +0000199
subrata_modak56207ce2009-03-23 13:35:39 +0000200 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800201 tst_exit();
Garrett Cooper43088e12010-12-13 23:30:59 -0800202}
plars865695b2001-08-27 22:15:12 +0000203
204/***************************************************************
205 * setup() - performs all ONE TIME setup for this test.
206 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400207void setup(void)
plars865695b2001-08-27 22:15:12 +0000208{
Garrett Cooper2c282152010-12-16 00:55:50 -0800209
subrata_modak56207ce2009-03-23 13:35:39 +0000210 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000211
subrata_modak56207ce2009-03-23 13:35:39 +0000212 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000213
subrata_modak56207ce2009-03-23 13:35:39 +0000214 /* Create a temporary directory and make it current. */
215 tst_tmpdir();
plars1ad84512002-07-23 13:11:18 +0000216
subrata_modak56207ce2009-03-23 13:35:39 +0000217 bad_addr = mmap(0, 1, PROT_NONE,
218 MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
219 if (bad_addr == MAP_FAILED) {
220 tst_brkm(TBROK, cleanup, "mmap failed");
221 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800222}
plars865695b2001-08-27 22:15:12 +0000223
224/***************************************************************
225 * cleanup() - performs all ONE TIME cleanup for this test at
226 * completion or premature exit.
227 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400228void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000229{
plars865695b2001-08-27 22:15:12 +0000230
subrata_modak56207ce2009-03-23 13:35:39 +0000231 /*
232 * Remove the temporary directory.
233 */
234 tst_rmdir();
plars865695b2001-08-27 22:15:12 +0000235
subrata_modak56207ce2009-03-23 13:35:39 +0000236 /*
237 * Exit with return code appropriate for results.
238 */
plars865695b2001-08-27 22:15:12 +0000239
Chris Dearmanec6edca2012-10-17 19:54:01 -0700240}