mkdir01.c revision fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716
1/* 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 20 * with this program; if not, write the Free Software Foundation, Inc., 21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 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 */ 33/* $Id: mkdir01.c,v 1.7 2009/03/23 13:35:54 subrata_modak Exp $ */ 34/********************************************************** 35 * 36 * OS Test - Silicon Graphics, Inc. 37 * 38 * TEST IDENTIFIER : mkdir01 39 * 40 * EXECUTED BY : anyone 41 * 42 * TEST TITLE : Basic errno test for mkdir(2) 43 * 44 * PARENT DOCUMENT : mkstds02 45 * 46 * TEST CASE TOTAL : 2 47 * 48 * WALL CLOCK TIME : 1 49 * 50 * CPU TYPES : ALL 51 * 52 * AUTHOR : Bill Branum 53 * 54 * CO-PILOT : Kathy Olmsted 55 * 56 * DATE STARTED : 4/15/92 57 * 58 * INITIAL RELEASE : UNICOS 7.0 59 * 60 * TEST CASES 61 * 62 * mkdir(2) test for errno(s) EFAULT. 63 * 64 * INPUT SPECIFICATIONS 65 * The standard options for system call tests are accepted. 66 * (See the parse_opts(3) man page). 67 * 68 * DURATION 69 * Terminates - with frequency and infinite modes. 70 * 71 * 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. 77 * 78 * 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. 83 * 84 * Setup: 85 * Setup signal handling. 86 * Create and make current a temporary directory. 87 * Pause for SIGUSR1 if option specified. 88 * 89 * 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 96 * 97 * Cleanup: 98 * Print errno log and/or timing stats if options given 99 * Remove the temporary directory. 100 * Exit. 101 * 102 * 103 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ 104 105#include <errno.h> 106#include <string.h> 107#include <signal.h> 108#include <sys/stat.h> 109#include <sys/types.h> 110#include <sys/mman.h> 111#include <fcntl.h> 112#include <unistd.h> 113#include "test.h" 114#include "usctest.h" 115 116void setup(); 117void cleanup(); 118 119char *TCID = "mkdir01"; 120int TST_TOTAL = 2; 121 122int exp_enos[] = { EFAULT, 0 }; /* List must end with 0 */ 123 124char *bad_addr = 0; 125 126int main(int ac, char **av) 127{ 128 int lc; 129 char *msg; 130 131 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) 132 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 133 134 setup(); 135 136 /* set the expected errnos... */ 137 TEST_EXP_ENOS(exp_enos); 138 139 for (lc = 0; TEST_LOOPING(lc); lc++) { 140 141 tst_count = 0; 142 143 /* 144 * TEST CASE: 1 145 * mkdir() call with pointer below allocated address space. 146 */ 147 148 /* Call mkdir(2) */ 149 TEST(mkdir(bad_addr, 0777)); 150 151 /* check return code */ 152 if (TEST_RETURN == -1) { 153 TEST_ERROR_LOG(TEST_ERRNO); 154 } 155 156 if (STD_FUNCTIONAL_TEST) { 157 if (TEST_RETURN == -1) { 158 if (TEST_ERRNO == EFAULT) { 159 tst_resm(TPASS, 160 "mkdir - path argument pointing below allocated address space failed as expected with errno %d : %s", 161 TEST_ERRNO, 162 strerror(TEST_ERRNO)); 163 } else { 164 tst_resm(TFAIL, 165 "mkdir - path argument pointing below allocated address space failed with errno %d : %s but expected %d (EFAULT)", 166 TEST_ERRNO, 167 strerror(TEST_ERRNO), EFAULT); 168 } 169 } else { 170 tst_resm(TFAIL, 171 "mkdir - path argument pointing below allocated address space succeeded unexpectedly."); 172 173 } 174 } 175#if !defined(UCLINUX) 176 /* 177 * TEST CASE: 2 178 * mkdir() call with pointer above allocated address space. 179 */ 180 181 /* Call mkdir(2) */ 182 TEST(mkdir(get_high_address(), 0777)); 183 184 /* check return code */ 185 if (TEST_RETURN == -1) { 186 TEST_ERROR_LOG(TEST_ERRNO); 187 } 188 189 if (STD_FUNCTIONAL_TEST) { 190 if (TEST_RETURN == -1) { 191 if (TEST_ERRNO == EFAULT) { 192 tst_resm(TPASS, 193 "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s", 194 TEST_ERRNO, 195 strerror(TEST_ERRNO)); 196 } else { 197 tst_resm(TFAIL, 198 "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)", 199 TEST_ERRNO, 200 strerror(TEST_ERRNO), EFAULT); 201 } 202 } else { 203 tst_resm(TFAIL, 204 "mkdir - path argument pointing above allocated address space succeeded unexpectedly."); 205 206 } 207 } 208#endif /* if !defined(UCLINUX) */ 209 210 } 211 212 cleanup(); 213 tst_exit(); 214 215} 216 217/*************************************************************** 218 * setup() - performs all ONE TIME setup for this test. 219 ***************************************************************/ 220void setup() 221{ 222 223 tst_sig(NOFORK, DEF_HANDLER, cleanup); 224 225 TEST_PAUSE; 226 227 /* Create a temporary directory and make it current. */ 228 tst_tmpdir(); 229 230 bad_addr = mmap(0, 1, PROT_NONE, 231 MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); 232 if (bad_addr == MAP_FAILED) { 233 tst_brkm(TBROK, cleanup, "mmap failed"); 234 } 235} 236 237/*************************************************************** 238 * cleanup() - performs all ONE TIME cleanup for this test at 239 * completion or premature exit. 240 ***************************************************************/ 241void cleanup() 242{ 243 /* 244 * print timing stats if that option was specified. 245 * print errno log if that option was specified. 246 */ 247 TEST_CLEANUP; 248 249 /* 250 * Remove the temporary directory. 251 */ 252 tst_rmdir(); 253 254 /* 255 * Exit with return code appropriate for results. 256 */ 257 258} 259