chmod02.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/* $Id: chmod02.c,v 1.5 2009/08/28 11:49:07 vapier Exp $ */ 33/********************************************************** 34 * 35 * OS Test - Silicon Graphics, Inc. 36 * 37 * TEST IDENTIFIER : chmod02 38 * 39 * EXECUTED BY : anyone 40 * 41 * TEST TITLE : Basic test for chmod(2) 42 * 43 * PARENT DOCUMENT : usctpl01 44 * 45 * TEST CASE TOTAL : 8 46 * 47 * WALL CLOCK TIME : 1 48 * 49 * CPU TYPES : ALL 50 * 51 * AUTHOR : William Roske 52 * 53 * CO-PILOT : Dave Fenner 54 * 55 * DATE STARTED : 03/30/92 56 * 57 * INITIAL RELEASE : UNICOS 7.0 58 * 59 * TEST CASES 60 * 61 * 1.) chmod(2) returns...(See Description) 62 * 63 * INPUT SPECIFICATIONS 64 * The standard options for system call tests are accepted. 65 * (See the parse_opts(3) man page). 66 * 67 * OUTPUT SPECIFICATIONS 68 *$ 69 * DURATION 70 * Terminates - with frequency and infinite modes. 71 * 72 * SIGNALS 73 * Uses SIGUSR1 to pause before test if option set. 74 * (See the parse_opts(3) man page). 75 * 76 * RESOURCES 77 * None 78 * 79 * ENVIRONMENTAL NEEDS 80 * The libcuts.a and libsys.a libraries must be included in 81 * the compilation of this test. 82 * 83 * SPECIAL PROCEDURAL REQUIREMENTS 84 * None 85 * 86 * INTERCASE DEPENDENCIES 87 * None 88 * 89 * DETAILED DESCRIPTION 90 * This is a Phase I test for the chmod(2) system call. It is intended 91 * to provide a limited exposure of the system call, for now. It 92 * should/will be extended when full functional tests are written for 93 * chmod(2). 94 * 95 * Setup: 96 * Setup signal handling. 97 * Pause for SIGUSR1 if option specified. 98 * 99 * Test: 100 * Loop if the proper options are given. 101 * Execute system call 102 * Check return code, if system call failed (return=-1) 103 * Log the errno and Issue a FAIL message. 104 * Otherwise, Issue a PASS message. 105 * 106 * Cleanup: 107 * Print errno log and/or timing stats if options given 108 * 109 * 110 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ 111 112#include <sys/types.h> 113#include <sys/stat.h> 114#include <sys/fcntl.h> 115#include <errno.h> 116#include <string.h> 117#include <signal.h> 118#include "test.h" 119#include "usctest.h" 120 121void setup(); 122void cleanup(); 123 124char *TCID = "chmod02"; 125int TST_TOTAL = 1; 126 127char fname[255]; 128char *buf = "file contents\n"; 129 130int Modes[] = { 0, 07, 070, 0700, 0777, 02777, 04777, 06777 }; 131 132int main(int ac, char **av) 133{ 134 int lc; 135 char *msg; 136 int ind; 137 int mode; 138 139 TST_TOTAL = sizeof(Modes) / sizeof(int); 140 141 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) 142 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 143 144 setup(); 145 146 for (lc = 0; TEST_LOOPING(lc); lc++) { 147 148 tst_count = 0; 149 150 for (ind = 0; ind < TST_TOTAL; ind++) { 151 mode = Modes[ind]; 152 153 TEST(chmod(fname, mode)); 154 155 if (TEST_RETURN == -1) { 156 tst_resm(TFAIL | TTERRNO, 157 "chmod(%s, %#o) failed", fname, mode); 158 } else { 159 160 if (STD_FUNCTIONAL_TEST) { 161 tst_resm(TPASS, 162 "chmod(%s, %#o) returned %ld", 163 fname, mode, TEST_RETURN); 164 } else 165 tst_count++; 166 } 167 } 168 169 } 170 171 cleanup(); 172 173 tst_exit(); 174} 175 176void setup() 177{ 178 int fd; 179 180 tst_sig(NOFORK, DEF_HANDLER, cleanup); 181 182 TEST_PAUSE; 183 184 tst_tmpdir(); 185 186 strcat(fname, "tfile"); 187 if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) { 188 tst_brkm(TBROK | TERRNO, cleanup, 189 "open(%s, O_RDWR|O_CREAT,0700) failed", fname); 190 } else if (write(fd, &buf, strlen(buf)) == -1) { 191 tst_brkm(TBROK | TERRNO, cleanup, 192 "write(%s, &buf, strlen(buf)) failed", fname); 193 } else if (close(fd) == -1) { 194 tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", fname); 195 } 196} 197 198void cleanup() 199{ 200 TEST_CLEANUP; 201 202 tst_rmdir(); 203 204} 205