plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 3 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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. |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 7 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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. |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 11 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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. |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 18 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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., 59 |
| 21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 22 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | */ |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 32 | /* $Id: symlink01.c,v 1.20 2009/11/02 13:57:19 subrata_modak Exp $ */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 33 | /* |
| 34 | * OS Test - Silicon Graphics, Inc. |
| 35 | * |
| 36 | * TEST IDENTIFIER : symlink01 (symlink) |
| 37 | * TEST TITLE : Make a Symbolic Link to a File |
| 38 | * PARENT DOCUMENT : symtds01 |
| 39 | * TEST CASE TOTAL : 5 |
| 40 | * WALL CLOCK TIME : 3 |
| 41 | * |
| 42 | * TEST IDENTIFIER : readlink01 (readlink) |
| 43 | * TEST TITLE : Reads Value of a Symbolic Link |
| 44 | * PARENT DOCUMENT : symtds01 |
| 45 | * TEST CASE TOTAL : 4 |
| 46 | * WALL CLOCK TIME : 3 |
| 47 | * |
| 48 | * TEST IDENTIFIER : stat04 (stat) |
| 49 | * TEST TITLE : Gets File Status Indirectly From a Symbolic Link File |
| 50 | * PARENT DOCUMENT : symtds01 |
| 51 | * TEST CASE TOTAL : 3 |
| 52 | * WALL CLOCK TIME : 3 |
| 53 | * |
| 54 | * TEST IDENTIFIER : lstat01 (lstat) |
| 55 | * TEST TITLE : Get file Status About a Symbolic Link File |
| 56 | * PARENT DOCUMENT : symtds01 |
| 57 | * TEST CASE TOTAL : 3 |
| 58 | * WALL CLOCK TIME : 3 |
| 59 | * |
| 60 | * TEST IDENTIFIER : mkdir05 (mkdir) |
| 61 | * TEST TITLE : Fail When Making a Directory File Indirectly From |
| 62 | * a Symbolic Link File |
| 63 | * PARENT DOCUMENT : symtds01 |
| 64 | * TEST CASE TOTAL : 1 |
| 65 | * WALL CLOCK TIME : 3 |
| 66 | * |
| 67 | * TEST IDENTIFIER : rmdir03 (rmdir) |
| 68 | * TEST TITLE : Fail When Removing a Directory File Indirectly |
| 69 | * From a Symbolic Link File |
| 70 | * PARENT DOCUMENT : symtds01 |
| 71 | * TEST CASE TOTAL : 1 |
| 72 | * WALL CLOCK TIME : 3 |
| 73 | * |
| 74 | * TEST IDENTIFIER : chdir01 (chdir) |
| 75 | * TEST TITLE : Changes Current Working DIrectory Location |
| 76 | * Indirectly From a Symbolic Link File |
| 77 | * PARENT DOCUMENT : symtds01 |
| 78 | * TEST CASE TOTAL : 3 |
| 79 | * WALL CLOCK TIME : 3 |
| 80 | * |
| 81 | * TEST IDENTIFIER : link01 (link) |
| 82 | * TEST TITLE : Creates a Link To a File Indirectly From a |
| 83 | * Symbolic Link File |
| 84 | * PARENT DOCUMENT : symtds01 |
| 85 | * TEST CASE TOTAL : 3 |
| 86 | * WALL CLOCK TIME : 3 |
| 87 | * |
| 88 | * TEST IDENTIFIER : unlink01 (unlink) |
| 89 | * TEST TITLE : Removes a Link To a File And Not Any Object File |
| 90 | * Which Maybe Pointed At |
| 91 | * PARENT DOCUMENT : symtds01 |
| 92 | * TEST CASE TOTAL : 1 |
| 93 | * WALL CLOCK TIME : 3 |
| 94 | * |
| 95 | * TEST IDENTIFIER : chmod01 (chmod) |
| 96 | * TEST TITLE : Change Object File Permissions Indirectly From a |
| 97 | * Symbolic Link File |
| 98 | * PARENT DOCUMENT : symtds01 |
| 99 | * TEST CASE TOTAL : 3 |
| 100 | * WALL CLOCK TIME : 3 |
| 101 | * |
| 102 | * TEST IDENTIFIER : utime01 (utime) |
| 103 | * TEST TITLE : Set File Access And Modify Object File Times |
| 104 | * Indirectly From a Symbolic Link File |
| 105 | * PARENT DOCUMENT : symtds01 |
| 106 | * TEST CASE TOTAL : 3 |
| 107 | * WALL CLOCK TIME : 3 |
| 108 | * |
| 109 | * TEST IDENTIFIER : rename01 (rename) |
| 110 | * TEST TITLE : Rename a Symbolic Link File And Not Any Object |
| 111 | * File |
| 112 | * PARENT DOCUMENT : symtds01 |
| 113 | * TEST CASE TOTAL : 3 |
| 114 | * WALL CLOCK TIME : 3 |
| 115 | * |
| 116 | * TEST IDENTIFIER : open01 (open) |
| 117 | * TEST TITLE : Create/Open a File For Reading Or Writing |
| 118 | * Indirectly From a Symbolic Link File |
| 119 | * PARENT DOCUMENT : symtds01 |
| 120 | * TEST CASE TOTAL : 5 |
| 121 | * WALL CLOCK TIME : 3 |
| 122 | * |
| 123 | * |
| 124 | * EXECUTED BY : whom ever |
| 125 | * CPU TYPES : ALL |
| 126 | * AUTHOR : David Fenner |
| 127 | * CO-PILOT : Jon Hendrickson |
| 128 | * DATE STARTED : 07/25/90 |
| 129 | * INITIAL RELEASE : UNICOS 6.0 |
| 130 | * |
| 131 | * TEST CASES |
| 132 | * |
| 133 | * For symlink |
| 134 | * 1. Create symbolic link with abnormal object name path |
| 135 | * 2. Create symbolic link with normal object name path |
| 136 | * 3. Create symbolic link with path to an existing object file |
| 137 | * 4. Receive EEXIST error when creating an already existing symbolic link file. |
| 138 | * 5. Receive ENAMETOOLONG error when creating symbolic link which exceeds PATH_MAX in length |
| 139 | * |
| 140 | * For readlink |
| 141 | * 1. Read a symbolic link file which points at no object file |
| 142 | * 2. Read a symbolic link file which points at an object file |
| 143 | * 3. Receive ENAMETOOLONG error when reading symbolic link which exceeds PATH_MAX in length |
| 144 | * 4. Receive an EINVAL error when reading a file which is not a symbolic |
| 145 | * link file. |
| 146 | * |
| 147 | * For stat |
| 148 | * 1. Get object file status through symbolic link file |
| 149 | * 2. Receive ENOENT error when accessing non-existent object file through symbolic link file |
| 150 | * 3. Receive ELOOP error when nesting of symbolic links exceed maximum |
| 151 | * |
| 152 | * For lstat |
| 153 | * 1. Get symbolic link file status when pointing at no object file |
| 154 | * 2. Get symbolic link file status when pointing at an object file |
| 155 | * 3. Get object file status when argument is not a symbolic link |
| 156 | * file. |
| 157 | * |
| 158 | * For mkdir |
| 159 | * 1. Receive EEXIST error when creating a directory through a symbolic link file |
| 160 | * |
| 161 | * For rmdir |
| 162 | * 1. Receive ENOTDIR error when removing an existing directory through a symbolic link file |
| 163 | * |
| 164 | * For chdir |
| 165 | * 1. Change current working directory through a symbolic link file |
| 166 | * 2. Receive ENOENT error when accessing non-existent directory through symbolic link file |
| 167 | * 3. Receive ELOOP error when nesting of symbolic links exceed maximum |
| 168 | * |
| 169 | * For link |
| 170 | * 1. Link an object file to a new file through symbolic link file |
| 171 | * 2. Receive ENOENT error when accessing non-existent object file through symbolic link file |
| 172 | * 3. Receive ELOOP error when nesting of symbolic links exceed maximum |
| 173 | * |
| 174 | * For unlink |
| 175 | * 1. Delete a symbolic link file and not the object file which it points at |
| 176 | * |
| 177 | * For chmod |
| 178 | * 1. Change file permissions of object file through a symbolic link file |
| 179 | * 2. Receive ENOENT error when accessing non-existent directory through symbolic link file |
| 180 | * 3. Receive ELOOP error when nesting of symbolic links exceed maximum |
| 181 | * |
| 182 | * For utime |
| 183 | * 1. Change inode times of object file through a symbolic link file |
| 184 | * 2. Receive ENOENT error when accessing non-existent directory through symbolic link file |
| 185 | * 3. Receive ELOOP error when nesting of symbolic links exceed maximum |
| 186 | * |
| 187 | * For rename |
| 188 | * 1. Rename a symbolic link file which points at no object file |
| 189 | * 2. Rename a symbolic link file which points at an object file without any object file alterations. |
| 190 | * 3. Receive EXDEV when trying to rename a symbolic link file to an address outside of current file system |
| 191 | * |
| 192 | * For open |
| 193 | * 1. Create an object file through a symbolic link file |
| 194 | * 2. Open an object file through a symbolic link file |
| 195 | * 3. Receive EEXIST error when exclusively creating an object file through a symbolic link file |
| 196 | * 4. Receive ENOENT error when accessing non-existent object file through symbolic link file |
| 197 | * 5. Receive ELOOP error when nesting of symbolic links exceed maximum |
| 198 | * |
| 199 | * ENVIRONMENTAL NEEDS |
| 200 | * None |
| 201 | * |
| 202 | * DETAILED DESCRIPTION |
| 203 | * |
| 204 | * Self-documenting code so see below |
| 205 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 206 | |
| 207 | #include <stdio.h> |
| 208 | #include <signal.h> |
| 209 | #include <string.h> |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 210 | #include <fcntl.h> /* open(2) system call */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 211 | #include <errno.h> |
| 212 | #include <sys/types.h> |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 213 | #include <utime.h> /* utime(2) system call */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 214 | #include <sys/param.h> |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 215 | #include <sys/stat.h> /* stat(2) and lstat(2) system calls */ |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 216 | #include <stdint.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 217 | |
| 218 | #include "test.h" |
| 219 | #include "usctest.h" |
| 220 | |
| 221 | void setup(); |
| 222 | void cleanup(); |
| 223 | void help(); |
| 224 | void delete_files(); |
| 225 | void do_EEXIST(); |
| 226 | void do_ENOENT(); |
| 227 | void do_ELOOP(); |
| 228 | void do_ENOTDIR(); |
| 229 | void do_EXDEV(); |
| 230 | void do_ENAMETOOLONG(); |
| 231 | void do_EINVAL(); |
| 232 | void do_readlink(); |
| 233 | void do_stat(); |
| 234 | void do_chdir(); |
| 235 | void do_link(); |
| 236 | void do_unlink(); |
| 237 | void do_chmod(); |
| 238 | void do_utime(); |
| 239 | void do_rename(); |
| 240 | void do_open(); |
| 241 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 242 | #define S_FILE "symbolic" /* Name of symbolic link file */ |
| 243 | #define O_FILE "object" /* Name of object file */ |
| 244 | #define A_S_FILE "asymbolic" /* Another name for a symbolic link file */ |
| 245 | #define Y_A_S_FILE "/NiCkEr" /* Yet another symbolic link file */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 246 | #define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" |
| 247 | |
| 248 | #define DEFAULT_TCID "symlink01" |
| 249 | |
| 250 | #define SYMLINK "symlink01" |
| 251 | #define READLINK "readlink01" |
| 252 | #define STAT "stat04" |
subrata_modak | cc378eb | 2008-12-18 05:46:04 +0000 | [diff] [blame] | 253 | #define STAT_64 "stat04_64" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 254 | #define LSTAT "lstat01" |
subrata_modak | cc378eb | 2008-12-18 05:46:04 +0000 | [diff] [blame] | 255 | #define LSTAT_64 "lstat01_64" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 256 | #define MKDIR "mkdir05" |
| 257 | #define RMDIR "rmdir03" |
| 258 | #define CHDIR "chdir01" |
| 259 | #define LINK "link01" |
| 260 | #define UNLINK "unlink01" |
| 261 | #define CHMOD "chmod01" |
| 262 | #define UTIME "utime01" |
| 263 | #define RENAME "rename01" |
| 264 | #define OPEN "open01" |
| 265 | |
| 266 | #define cktcsid(s1,s2) (!strcmp(s1,s2)) |
| 267 | #define BUFMAX 512 |
| 268 | #define MODE 0700 |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 269 | #define MASK 0100777 /* A regular file with r,w,x for all mask */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 270 | |
| 271 | /* |
| 272 | * Lets be optimistic and only define messages for passing test cases |
| 273 | */ |
| 274 | char *msgs[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 275 | "Creation of symbolic link file to no object file is ok", |
| 276 | "Creation of symbolic link file and object file via symbolic link is ok", |
| 277 | "Creating an existing symbolic link file error is caught", |
| 278 | "Creating a symbolic link which exceeds maximum pathname error is caught", |
| 279 | "Reading of symbolic link file contents checks out ok", |
| 280 | "Reading a symbolic link which exceeds maximum pathname error is caught", |
| 281 | "Getting stat info about object file through symbolic link file is ok", |
| 282 | "Stat(2) error when accessing non-existent object through symbolic link is caught", |
| 283 | "lstat(2) of symbolic link file which points to no object file is ok", |
| 284 | "lstat(2) of symbolic link file which points at an object file is ok", |
| 285 | "mkdir(2) of object file through symbolic link file failed as expected", |
| 286 | "rmdir(2) of object file through symbolic link file failed as expected", |
| 287 | "chdir(2) to object file location through symbolic link file is ok", |
| 288 | "chdir(2) to non-existent object file location through symbolic link file failed as expected", |
| 289 | "link(2) to a symbolic link, which is pointing to an existing object file worked - file created and link count adjusted", |
| 290 | "link(2) to a symbolic link, which is pointing to a non-existing object file worked ok - file created and link count adjusted.", |
| 291 | "unlink(2) of symbolic link file with no object file removal is ok", |
| 292 | "chmod(2) of object file permissions through symbolic link file is ok", |
| 293 | "chmod(2) error when accessing non-existent object through symbolic link is caught", |
| 294 | "utime(2) change of object file access and modify times through symbolic link file is ok", |
| 295 | "utime(2) error when accessing non-existent object through symbolic link is caught", |
| 296 | "rename(3) of symbolic link file name which points at no object file is ok", |
| 297 | "rename(3) of symbolic link file name which points at object file is ok", |
| 298 | "rename(3) error of symbolic link file name across file systems is caught", |
| 299 | "open(2) with (O_CREAT | O_RDWR) to create object file through symbolic link file and all writes, reads, and lseeks are ok", |
| 300 | "open(2) with O_RDWR of existing object file through symbolic link file and all writes, reads, and lseeks are ok", |
| 301 | "open(2) with (O_CREAT | O_EXCL) error is caught when creating object file through symbolic link file", |
| 302 | "open(2) error with O_RDWR is caught when processing symbolic link file which points at no object file", |
| 303 | "Nested symbolic link access condition caught. ELOOP is returned", |
| 304 | "Reading a nonsymbolic link file error condition is caught. EINVAL is returned", |
| 305 | "lstat(2) of object file returns object file inode information", |
| 306 | "NULL" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 307 | }; |
| 308 | |
| 309 | /* |
| 310 | * Define test object setup and validation functions |
| 311 | */ |
| 312 | int creat_both(), creat_symlink(), creat_path_max(), ck_symlink(), |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 313 | creat_object(), ck_object(), ck_both(), ck_path_max(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * Define test cases |
| 317 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 318 | struct all_test_cases { |
| 319 | char *tcid; |
| 320 | int test_fail; |
| 321 | int errno_val; |
| 322 | int pass_msg; |
| 323 | int (*test_setup) (); |
| 324 | int (*ck_test) (); |
| 325 | char *fn_arg[3]; |
| 326 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 327 | } test_objects[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 328 | { |
| 329 | SYMLINK, 0, 0, 0, creat_symlink, ck_symlink, { "%bc+eFhi!k", S_FILE, NULL}}, { |
| 330 | SYMLINK, 0, 0, 0, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 331 | SYMLINK, 0, 0, 1, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, { |
| 332 | SYMLINK, 1, EEXIST, 2, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 333 | SYMLINK, 1, ENAMETOOLONG, 3, creat_path_max, ck_path_max, { O_FILE, S_FILE, NULL}}, { |
| 334 | READLINK, 0, 0, 4, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 335 | READLINK, 0, 0, 4, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, { |
| 336 | READLINK, 1, ENAMETOOLONG, 5, creat_path_max, ck_path_max, { O_FILE, S_FILE, NULL}}, { |
| 337 | READLINK, 1, EINVAL, 29, creat_object, ck_object, { O_FILE, NULL, NULL}}, { |
| 338 | STAT, 0, 0, 6, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, |
| 339 | /* 10 */ |
| 340 | { |
| 341 | STAT, 1, ENOENT, 7, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 342 | STAT, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, { |
| 343 | STAT_64, 0, 0, 6, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, { |
| 344 | STAT_64, 1, ENOENT, 7, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 345 | STAT_64, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, { |
| 346 | LSTAT, 0, 0, 8, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 347 | LSTAT, 0, 0, 9, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, { |
| 348 | LSTAT, 0, 0, 30, creat_object, ck_object, { O_FILE, NULL, NULL}}, { |
| 349 | LSTAT_64, 0, 0, 8, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 350 | LSTAT_64, 0, 0, 9, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, |
| 351 | /* 20 */ |
| 352 | { |
| 353 | LSTAT_64, 0, 0, 30, creat_object, ck_object, { O_FILE, NULL, NULL}}, { |
| 354 | MKDIR, 1, EEXIST, 10, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 355 | RMDIR, 1, ENOTDIR, 11, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 356 | CHDIR, 0, 0, 12, creat_symlink, ck_symlink, { O_FILE, S_FILE, O_FILE}}, { |
| 357 | CHDIR, 1, ENOENT, 13, creat_symlink, ck_symlink, { "%bc+eFhi!k", S_FILE, NULL}}, { |
| 358 | CHDIR, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, { |
| 359 | LINK, 0, 0, 14, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, { |
| 360 | LINK, 0, 0, 15, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, |
| 361 | /* The following link test case is invalid - leaving it defined so */ |
| 362 | /* I don't have to change all the entries in the all_tcses array after link */ |
| 363 | /* It has been disabled at the moment. */ |
| 364 | { |
| 365 | LINK, 1, -1, -1, creat_symlink, ck_symlink, { NULL, NULL, NULL}}, { |
| 366 | UNLINK, 0, 0, 16, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, |
| 367 | /* 30 */ |
| 368 | { |
| 369 | CHMOD, 0, 0, 17, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, { |
| 370 | CHMOD, 1, ENOENT, 18, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 371 | CHMOD, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, { |
| 372 | UTIME, 0, 0, 19, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, { |
| 373 | UTIME, 1, ENOENT, 20, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 374 | UTIME, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}}, { |
| 375 | RENAME, 0, 0, 21, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 376 | RENAME, 0, 0, 22, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, |
| 377 | /* The following rename test makes assumption that the link and target */ |
| 378 | /* files are located in different filesystems, which is incorrect. */ |
| 379 | /* It has been disabled at the moment. */ |
| 380 | { |
| 381 | RENAME, 1, EXDEV, 23, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, { |
| 382 | OPEN, 0, 0, 24, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, |
| 383 | /* 40 */ |
| 384 | { |
| 385 | OPEN, 0, 0, 25, creat_both, ck_both, { O_FILE, S_FILE, O_FILE}}, { |
| 386 | OPEN, 1, EEXIST, 26, creat_symlink, ck_symlink, { O_FILE, S_FILE, O_FILE}}, { |
| 387 | OPEN, 1, ENOENT, 27, creat_symlink, ck_symlink, { O_FILE, S_FILE, NULL}}, { |
| 388 | OPEN, 1, ELOOP, 28, creat_symlink, ck_symlink, { S_FILE, S_FILE, NULL}} |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | /* |
| 392 | * Define tcses |
| 393 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 394 | struct tcses { |
| 395 | char *tcid; |
| 396 | char *syscall; |
| 397 | int test_cases; /* number of entries in test_objects array */ |
| 398 | struct all_test_cases *tc_ptr; |
| 399 | char *desc; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 400 | } all_tcses[] = { |
| 401 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 402 | { |
| 403 | SYMLINK, "symlink", 5, &test_objects[0], "Make a Symbolic Link to a File"}, { |
| 404 | READLINK, "readlink", 4, &test_objects[5], "Reads Value of a Symbolic Link"}, { |
| 405 | STAT, "stat", 3, &test_objects[9], |
| 406 | "Gets File Status Indirectly From a Symbolic Link file"}, { |
| 407 | STAT_64, "stat64", 3, &test_objects[12], |
| 408 | "Gets File Status Indirectly From a Symbolic Link file"}, { |
| 409 | LSTAT, "lstat", 3, &test_objects[15], "Get file Status About a Symbolic Link File"}, { |
| 410 | LSTAT_64, "lstat64", 3, &test_objects[18], |
| 411 | "Get file Status About a Symbolic Link File"}, { |
| 412 | MKDIR, "mkdir", 1, &test_objects[21], |
| 413 | "Fail When Making a Directory File Indirectly from a symlink"}, { |
| 414 | RMDIR, "rmdir", 1, &test_objects[22], |
| 415 | "Fail When Removing a Directory File Indirectly from a symlink"}, { |
| 416 | CHDIR, "chdir", 3, &test_objects[23], |
| 417 | "Changes CWD Location Indirectly from a symlink"}, { |
| 418 | LINK, "link", 2, &test_objects[26], |
| 419 | "Creates a Link To a File Indirectly From a Symbolic"}, { |
| 420 | UNLINK, "unlink", 1, &test_objects[29], |
| 421 | "Removes a Link To a File but not the Object File"}, { |
| 422 | CHMOD, "chmod", 3, &test_objects[30], |
| 423 | "Change Object File Permissions Indirectly From a Symbolic"}, { |
| 424 | UTIME, "utime", 3, &test_objects[33], |
| 425 | "Set File Access And Modify Object File Times via symlink"}, { |
| 426 | RENAME, "rename", 2, &test_objects[36], |
| 427 | "Rename a Symbolic Link File And Not Any Object file"}, { |
| 428 | OPEN, "open", 5, &test_objects[39], |
| 429 | "Create/Open a File For Reading Or Writing via symlink"},}; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 430 | |
| 431 | /* |
| 432 | * Define GLOBAL variables |
| 433 | */ |
| 434 | |
| 435 | int TST_TOTAL; |
| 436 | int TEST_RESULT; |
| 437 | time_t a_time_value = 100; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 438 | char *TCID; |
| 439 | char *Selectedtests = NULL; /* Name (tcid) of selected test cases */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 440 | char test_msg[BUFMAX]; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 441 | char full_path[PATH_MAX + 1 + 1]; /* Add one for '\0' and another to exceed the PATH_MAX limit, see creat_path_max() */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 442 | extern int Tst_count; |
| 443 | extern char *TESTDIR; |
mridge | f7298c7 | 2005-12-05 19:14:37 +0000 | [diff] [blame] | 444 | /*extern char *strrchr();*/ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 445 | |
| 446 | struct stat asymlink, statter; |
| 447 | char Buffer[1024]; |
| 448 | char Buf[1024]; |
| 449 | |
| 450 | char *Tcid = NULL; |
| 451 | |
| 452 | option_t Options[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 453 | {"T:", NULL, &Tcid}, /* -T tcid option */ |
| 454 | {NULL, NULL, NULL} |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 455 | }; |
| 456 | |
| 457 | /*********************************************************************** |
| 458 | * MAIN |
| 459 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 460 | int main(int argc, char *argv[]) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 461 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 462 | struct tcses *tcs_ptr, *get_tcs_info(); |
| 463 | int do_syscalltests(); |
| 464 | void cleanup(); |
| 465 | int lc; /* loop counter */ |
| 466 | char *msg; /* message returned from parse_opts */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 467 | |
| 468 | /*************************************************************** |
| 469 | * parse standard options, and exit if there is an error |
| 470 | ***************************************************************/ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 471 | if ((msg = parse_opts(argc, argv, Options, &help)) != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 472 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 473 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 474 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 475 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 476 | /* |
| 477 | * If the -T option was used, use that TCID or use the default |
| 478 | */ |
| 479 | if (Tcid != NULL) { |
| 480 | TCID = Tcid; |
| 481 | Selectedtests = Tcid; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 482 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 483 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 484 | #ifndef ALL |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 485 | else { |
| 486 | TCID = DEFAULT_TCID; |
| 487 | Selectedtests = DEFAULT_TCID; |
| 488 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 489 | #endif |
| 490 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 491 | /* |
| 492 | * Get test case specification information and assign TST_TOTAL |
| 493 | */ |
| 494 | if ((tcs_ptr = get_tcs_info(Selectedtests)) == NULL) { |
| 495 | TST_TOTAL = 1; |
| 496 | tst_brkm(TBROK, cleanup, "Unknown symbolic link test case specification executed"); |
| 497 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 498 | |
| 499 | /*************************************************************** |
| 500 | * perform global setup for test |
| 501 | ***************************************************************/ |
| 502 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 503 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 504 | |
| 505 | /*************************************************************** |
| 506 | * check looping state if -c option given |
| 507 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 508 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 509 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 510 | Tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 511 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 512 | /* |
| 513 | * Execute tcs testing function and all defined test cases |
| 514 | */ |
| 515 | do_syscalltests(tcs_ptr); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 516 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 517 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 518 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 519 | /* |
| 520 | * End appropriately |
| 521 | */ |
| 522 | cleanup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 523 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /*********************************************************************** |
| 527 | * This function maps the name of the process to a test case specification |
| 528 | * defined in the all_tcses array of tcses structures. Either a pointer |
| 529 | * to the mapped test case specification information is returned or a |
| 530 | * null pointer. |
| 531 | * |
| 532 | * Argument is path to program name. |
| 533 | ***********************************************************************/ |
| 534 | struct tcses *get_tcs_info(ptr) |
| 535 | char *ptr; |
| 536 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 537 | int ctr; |
| 538 | struct tcses *tcs_ptr; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 539 | |
| 540 | #if ALL |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 541 | if (ptr == NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 542 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 543 | TST_TOTAL = 0; |
| 544 | for (ctr = 1; ctr < sizeof(all_tcses) / sizeof(struct tcses); ctr++) |
| 545 | TST_TOTAL += all_tcses[ctr].test_cases; |
| 546 | return all_tcses; |
| 547 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 548 | #endif |
| 549 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 550 | for (ctr = 0; ctr < (sizeof(all_tcses) / sizeof(struct tcses)); ctr++) { |
| 551 | if (strcmp(ptr, all_tcses[ctr].tcid) == 0 || |
| 552 | strcmp(ptr, all_tcses[ctr].syscall) == 0) { |
| 553 | tcs_ptr = &all_tcses[ctr]; |
| 554 | TCID = all_tcses[ctr].tcid; |
| 555 | TST_TOTAL = tcs_ptr->test_cases; |
| 556 | return (tcs_ptr); |
| 557 | } |
| 558 | |
| 559 | } |
| 560 | return NULL; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /*********************************************************************** |
| 564 | * Determines if what path points at is a symbolic link file |
| 565 | * |
| 566 | * Argument is path to symbolic link file. |
| 567 | * |
| 568 | * Return status is one if a symbolic link file. Zero if not a symbolic |
| 569 | * link file and a minus one if the path doesn't point at a file. |
| 570 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 571 | int see_if_a_symlink(path) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 572 | char *path; |
| 573 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 574 | if (lstat(path, &asymlink) < 0) |
| 575 | return (-1); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 576 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 577 | if ((asymlink.st_mode & S_IFMT) == S_IFLNK) |
| 578 | return 1; |
| 579 | else |
| 580 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | /*********************************************************************** |
| 584 | * This function performs without any hesitation, file(s) deletions |
| 585 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 586 | void delete_files(path1, path2) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 587 | char *path1, *path2; |
| 588 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 589 | unlink(path1); |
| 590 | unlink(path2); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | /*********************************************************************** |
| 594 | * |
| 595 | * This routine creates a symbolic link file. |
| 596 | * |
| 597 | * Argument one is symbolic link pathname to point at. |
| 598 | * Argument two is name of symbolic link file. |
| 599 | * |
| 600 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 601 | int creat_symlink(path1, path2) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 602 | char *path1, *path2; |
| 603 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 604 | TEST(symlink(path1, path2)); |
| 605 | errno = TEST_ERRNO; |
| 606 | if (TEST_RETURN == -1) { |
| 607 | TEST_RESULT = TBROK; |
| 608 | sprintf(test_msg, |
| 609 | "symlink(2) Failure when creating setup %s object file: errno:%d %s", |
| 610 | path1, errno, strerror(errno)); |
| 611 | return 0; |
| 612 | } else { |
| 613 | sprintf(Buf, "symlink(%s, %s) was succesful.\n", path1, path2); |
| 614 | strcat(Buffer, Buf); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 615 | #if DEBUG |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 616 | tst_resm(TPASS, "symlink(%s, %s) was succesful.", path1, path2); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 617 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 618 | } |
| 619 | return 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /*********************************************************************** |
| 623 | * |
| 624 | * This routine creates a regular file. |
| 625 | * |
| 626 | * Argument one is a pathname |
| 627 | * |
| 628 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 629 | int creat_object(path1) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 630 | char *path1; |
| 631 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 632 | int fd; |
| 633 | if ((fd = creat(path1, MODE)) == -1) { |
| 634 | TEST_RESULT = TBROK; |
| 635 | sprintf(test_msg, |
| 636 | "creat(2) Failure when creating setup %s object file: errno:%d %s", |
| 637 | path1, errno, strerror(errno)); |
| 638 | return 0; |
| 639 | } else { |
| 640 | sprintf(Buf, "creat(%s, %#o) was succesful.\n", path1, MODE); |
| 641 | strcat(Buffer, Buf); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 642 | #if DEBUG |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 643 | tst_resm(TPASS, "creat(%s, %#o) was succesful.", path1, MODE); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 644 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 645 | } |
| 646 | if (close(fd) == -1) { |
| 647 | TEST_RESULT = TBROK; |
| 648 | sprintf(test_msg, |
| 649 | "close(2) Failure when closing setup %s object file: errno:%d %s", |
| 650 | path1, errno, strerror(errno)); |
| 651 | return 0; |
| 652 | } |
| 653 | return 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /*********************************************************************** |
| 657 | * |
| 658 | * This routine creates a symbolic link file and a regular file. |
| 659 | * |
| 660 | * Argument one is a pathname of object file |
| 661 | * Argument two is symbolic link file name |
| 662 | * Argument three is regular file name |
| 663 | * |
| 664 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 665 | int creat_both(path1, path2, path3) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 666 | char *path1, *path2, *path3; |
| 667 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 668 | if (creat_symlink(path1, path2) == -1) |
| 669 | return 0; |
| 670 | else if (creat_object(path3) == -1) |
| 671 | return 0; |
| 672 | return 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /*********************************************************************** |
| 676 | * |
| 677 | * This routine checks if symbolic link file is a symbolic link file. |
| 678 | * |
| 679 | * Argument one is a pathname of object file |
| 680 | * Argument two is symbolic link file name |
| 681 | * Argument three is regular file name |
| 682 | * |
| 683 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 684 | int ck_symlink(path1, path2, path3) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 685 | char *path1, *path2, *path3; |
| 686 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 687 | int ret; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 688 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 689 | if ((ret = see_if_a_symlink(path2)) == -1) { |
| 690 | TEST_RESULT = TBROK; |
| 691 | sprintf(test_msg, |
| 692 | "lstat(2) Failure when accessing %s symbolic link file which should contain %s path to %s file ", |
| 693 | path2, path1, path3); |
| 694 | return 0; |
| 695 | } else if (ret == 0) { |
| 696 | TEST_RESULT = TBROK; |
| 697 | sprintf(test_msg, |
| 698 | "%s is not a symbolic link file which contains %s path to %s file", |
| 699 | path2, path1, path3); |
| 700 | return 0; |
| 701 | } |
| 702 | return 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | /*********************************************************************** |
| 706 | * |
| 707 | * This routine checks if symbolic link file points at object file. |
| 708 | * |
| 709 | * Argument one is a pathname of object file |
| 710 | * Argument two is symbolic link file name |
| 711 | * Argument three is regular file name |
| 712 | * |
| 713 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 714 | int ck_both(path1, path2, path3) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 715 | char *path1, *path2, *path3; |
| 716 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 717 | if (ck_symlink(path1, path2, path3) == 0) |
| 718 | return 0; |
| 719 | else if ((stat(path3, &statter) == -1) && (errno == ENOENT)) { |
| 720 | TEST_RESULT = TBROK; |
| 721 | sprintf(test_msg, "stat(2) Failure when accessing %s object file ", path3); |
| 722 | return 0; |
| 723 | } else if ((stat(path2, &asymlink) == -1) && (errno == ENOENT)) { |
| 724 | TEST_RESULT = TBROK; |
| 725 | sprintf(test_msg, "stat(2) Failure when accessing %s symbolic link file ", path2); |
| 726 | return 0; |
| 727 | } else if (statter.st_ino != asymlink.st_ino) { |
| 728 | TEST_RESULT = TBROK; |
| 729 | sprintf(test_msg, |
| 730 | "stat(2) Failure when accessing %s object file through %s symbolic link file ", |
| 731 | path3, path2); |
| 732 | return 0; |
| 733 | } |
| 734 | return 1; |
| 735 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /*********************************************************************** |
| 739 | * This routine populates full_path with a pathname whose length exceeds |
| 740 | * the PATH_MAX define value in param.h |
| 741 | * |
| 742 | * Argument one is a pathname of object file |
| 743 | * Argument two is symbolic link file name |
| 744 | * Argument three is regular file name |
| 745 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 746 | int creat_path_max(path1, path2, path3) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 747 | char *path1, *path2, *path3; |
| 748 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 749 | int ctr, to_go, size, whole_chunks; |
| 750 | char *cwd, *getcwd(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 751 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 752 | if ((cwd = getcwd(NULL, 0)) == NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 753 | TEST_RESULT = TBROK; |
| 754 | sprintf(test_msg, |
| 755 | "getcwd(3) Failure in setup of %s %s %s test case object elements", |
| 756 | path1, path2, path3); |
| 757 | return 0; |
| 758 | } |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 759 | cwd = getcwd(NULL, 0); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 760 | size = strlen(cwd); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 761 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 762 | to_go = PATH_MAX - size; |
| 763 | size = strlen(path1); |
| 764 | whole_chunks = to_go / size; |
| 765 | strcpy(full_path, cwd); |
| 766 | for (ctr = 0; ctr < whole_chunks; ctr++) { |
| 767 | strcat(full_path, path1); |
| 768 | } |
| 769 | size = strlen(full_path); |
| 770 | to_go = PATH_MAX - size; |
| 771 | strcat(full_path, "/"); |
| 772 | for (ctr = 0; ctr < to_go; ctr++) |
| 773 | strcat(full_path, "Z"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 774 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 775 | return 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | /*********************************************************************** |
| 779 | * This routine checks that full_path's length exceeds the PATH_MAX |
| 780 | * define value in param.h |
| 781 | * |
| 782 | * Argument one is a pathname of object file |
| 783 | * Argument two is symbolic link file name |
| 784 | * Argument three is regular file name |
| 785 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 786 | int ck_path_max(path1, path2, path3) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 787 | char *path1, *path2, *path3; |
| 788 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 789 | if (strlen(full_path) == (PATH_MAX + 1)) |
| 790 | return 1; |
| 791 | else { |
| 792 | TEST_RESULT = TBROK; |
| 793 | sprintf(test_msg, "%s %d %s %s %s %s", |
| 794 | "full_path character array length was not", |
| 795 | (PATH_MAX + 1), |
| 796 | "characters long for test case object elements", path1, path2, path3); |
| 797 | return 0; |
| 798 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /*********************************************************************** |
| 802 | * This routine checks if the stat(2) and lstat(2) calls return the same |
| 803 | * information when the path is not a symbolic link file |
| 804 | * |
| 805 | * Argument one is a pathname of object file |
| 806 | * Argument two is symbolic link file name |
| 807 | * Argument three is regular file name |
| 808 | * |
| 809 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 810 | int ck_object(path1, path2, path3) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 811 | char *path1, *path2, *path3; |
| 812 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 813 | int ret; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 814 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 815 | if ((ret = see_if_a_symlink(path1)) < 0) { |
| 816 | TEST_RESULT = TFAIL; |
| 817 | sprintf(test_msg, |
| 818 | "lstat(2) failed to return inode information for a regular object file"); |
| 819 | return 0; |
| 820 | } else if (ret == 1) { |
| 821 | TEST_RESULT = TFAIL; |
| 822 | sprintf(test_msg, |
| 823 | "lstat(2) detected a regular object file as a symbolic link file"); |
| 824 | return 0; |
| 825 | } else if (stat(path1, &statter) == -1) { |
| 826 | TEST_RESULT = TBROK; |
| 827 | sprintf(test_msg, |
| 828 | "stat(2) failed to return inode information for a regular object file"); |
| 829 | return 0; |
| 830 | } else if (memcmp((char *)&statter, (char *)&asymlink, sizeof(statter)) |
| 831 | != 0) { |
| 832 | TEST_RESULT = TFAIL; |
| 833 | sprintf(test_msg, |
| 834 | "lstat(2) and stat(2) do not return same inode information for an object file"); |
| 835 | return 0; |
| 836 | |
| 837 | } |
| 838 | return 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | /*********************************************************************** |
| 842 | * Main test case processing function |
| 843 | * |
| 844 | * Argument is a ptr into the all_tcses array of structures of type tcses |
| 845 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 846 | int do_syscalltests(tcs) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 847 | struct tcses *tcs; |
| 848 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 849 | int ctr, ret; |
| 850 | struct all_test_cases *tc_ptr; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 851 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 852 | /* |
| 853 | * loop through desired number of test cases |
| 854 | */ |
| 855 | for (ctr = 0, tc_ptr = tcs->tc_ptr; ctr < TST_TOTAL; ctr++, tc_ptr++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 856 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 857 | Buffer[0] = '\0'; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 858 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 859 | /* |
| 860 | * If running all test cases for all tcid, set the TCID if needed. |
| 861 | */ |
| 862 | if (Selectedtests == NULL) { |
| 863 | if (strcmp(tcs->tcid, tc_ptr->tcid) != 0) { |
| 864 | TCID = tc_ptr->tcid; |
| 865 | Tst_count = 0; |
| 866 | } |
| 867 | } |
| 868 | /* |
| 869 | * Insure that we are executing the correct tcs test case |
| 870 | */ |
| 871 | if (strcmp(tcs->tcid, tc_ptr->tcid) != 0) { |
| 872 | tst_resm(TBROK, |
| 873 | "%s TCID attempted to execute %s %d %d test case", |
| 874 | tcs->tcid, tc_ptr->tcid, tc_ptr->test_fail, tc_ptr->errno_val); |
| 875 | continue; |
| 876 | } |
| 877 | TEST_RESULT = TPASS; |
| 878 | delete_files(S_FILE, O_FILE); |
| 879 | /* |
| 880 | * Perform test case setup |
| 881 | */ |
| 882 | ret = |
| 883 | (tc_ptr->test_setup) (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1], |
| 884 | tc_ptr->fn_arg[2], tc_ptr->errno_val); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 885 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 886 | /* If an expected error, try it out */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 887 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 888 | if (tc_ptr->test_fail) { |
| 889 | /* |
| 890 | * Try to perform test verification function |
| 891 | */ |
| 892 | if (!(tc_ptr->ck_test) |
| 893 | (tc_ptr->fn_arg[0], tc_ptr->fn_arg[1], |
| 894 | tc_ptr->fn_arg[2], tc_ptr->errno_val)) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 895 | tst_resm(TEST_RESULT, "%s", test_msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 896 | else if (tc_ptr->errno_val == EEXIST) |
| 897 | do_EEXIST(tc_ptr); |
| 898 | else if (tc_ptr->errno_val == ENOENT) |
| 899 | do_ENOENT(tc_ptr); |
| 900 | else if (tc_ptr->errno_val == ELOOP) |
| 901 | do_ELOOP(tc_ptr); |
| 902 | else if (tc_ptr->errno_val == ENOTDIR) |
| 903 | do_ENOTDIR(tc_ptr); |
| 904 | else if (tc_ptr->errno_val == EXDEV) |
| 905 | do_EXDEV(tc_ptr); |
| 906 | else if (tc_ptr->errno_val == ENAMETOOLONG) |
| 907 | do_ENAMETOOLONG(tc_ptr); |
| 908 | else if (tc_ptr->errno_val == EINVAL) |
| 909 | do_EINVAL(tc_ptr); |
| 910 | else |
| 911 | tst_resm(TBROK, "Test Case Declaration Error"); |
| 912 | } else if (ret == 1) { /* No setup function error */ |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 913 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 914 | if (tc_ptr->errno_val != 0) |
| 915 | tst_resm(TBROK, "Test Case Declaration Error"); |
| 916 | else { |
| 917 | /* |
| 918 | * Perform test verification function |
| 919 | */ |
| 920 | ret = |
| 921 | (tc_ptr->ck_test) (tc_ptr->fn_arg[0], |
| 922 | tc_ptr->fn_arg[1], |
| 923 | tc_ptr->fn_arg[2], tc_ptr->errno_val); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 924 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 925 | /* Perform requested symbolic link system call test */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 926 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 927 | if ((cktcsid(tc_ptr->tcid, SYMLINK)) || |
| 928 | (cktcsid(tc_ptr->tcid, LSTAT)) || |
| 929 | (cktcsid(tc_ptr->tcid, LSTAT_64))) { |
| 930 | if (ret == 1) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 931 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 932 | else |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 933 | tst_resm(TEST_RESULT, "%s", test_msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 934 | } else if (ret == 0) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 935 | tst_resm(TEST_RESULT, "%s", test_msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 936 | else if (cktcsid(tc_ptr->tcid, READLINK)) |
| 937 | do_readlink(tc_ptr); |
| 938 | else if (cktcsid(tc_ptr->tcid, STAT)) |
| 939 | do_stat(tc_ptr); |
| 940 | else if (cktcsid(tc_ptr->tcid, STAT_64)) |
| 941 | do_stat(tc_ptr); |
| 942 | else if (cktcsid(tc_ptr->tcid, CHDIR)) |
| 943 | do_chdir(tc_ptr); |
| 944 | else if (cktcsid(tc_ptr->tcid, LINK)) |
| 945 | do_link(tc_ptr); |
| 946 | else if (cktcsid(tc_ptr->tcid, UNLINK)) |
| 947 | do_unlink(tc_ptr); |
| 948 | else if (cktcsid(tc_ptr->tcid, CHMOD)) |
| 949 | do_chmod(tc_ptr); |
| 950 | else if (cktcsid(tc_ptr->tcid, UTIME)) |
| 951 | do_utime(tc_ptr); |
| 952 | else if (cktcsid(tc_ptr->tcid, RENAME)) |
| 953 | do_rename(tc_ptr); |
| 954 | else if (cktcsid(tc_ptr->tcid, OPEN)) |
| 955 | do_open(tc_ptr); |
| 956 | else |
| 957 | tst_resm(TBROK, |
| 958 | "Unknown test case processing actions declared"); |
| 959 | } |
| 960 | } else |
| 961 | tst_resm(TBROK, "Test Case Declaration Error"); |
| 962 | } |
| 963 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | /*********************************************************************** |
| 967 | * This routine checks for the return of EEXIST errno from requested |
| 968 | * system call |
| 969 | * |
| 970 | * Argument is pointer to test_objects array of structures of type |
| 971 | * all_test_cases |
| 972 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 973 | void do_EEXIST(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 974 | struct all_test_cases *tc_ptr; |
| 975 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 976 | if (cktcsid(tc_ptr->tcid, SYMLINK)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 977 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 978 | TEST(symlink(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1])); |
| 979 | errno = TEST_ERRNO; |
| 980 | if ((TEST_RETURN == -1) && (errno == EEXIST)) |
| 981 | if (STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 982 | tst_resm(TPASS, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 983 | else |
| 984 | Tst_count++; |
| 985 | else |
| 986 | tst_resm(TFAIL, "%s %s", |
| 987 | "Expected EEXIST error when creating a symbolic link file", |
| 988 | "which already existed"); |
| 989 | } else if (cktcsid(tc_ptr->tcid, MKDIR)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 990 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 991 | TEST(mkdir(tc_ptr->fn_arg[1], MODE)); |
| 992 | errno = TEST_ERRNO; |
| 993 | if ((TEST_RETURN == -1) && (errno == EEXIST)) |
| 994 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 995 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 996 | else |
| 997 | Tst_count++; |
| 998 | else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 999 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1000 | tst_resm(TFAIL, "%s %s", |
| 1001 | "Expected EEXIST error when creating a directory by a symbolic", |
| 1002 | "link file which pointed at no object file"); |
| 1003 | rmdir(tc_ptr->fn_arg[1]); |
| 1004 | } |
| 1005 | } else if (cktcsid(tc_ptr->tcid, OPEN)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1006 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1007 | TEST(open(tc_ptr->fn_arg[1], (O_EXCL | O_CREAT), 0666)); |
| 1008 | errno = TEST_ERRNO; |
| 1009 | if ((TEST_RETURN == -1) && (errno == EEXIST)) |
| 1010 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1011 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1012 | else |
| 1013 | Tst_count++; |
| 1014 | else |
| 1015 | tst_resm(TFAIL, "%s %s errno:%d %s", |
| 1016 | "Expected EEXIST error for exclusively opening an object file", |
| 1017 | "through a symbolic link file was not received:", |
| 1018 | errno, strerror(errno)); |
| 1019 | } else |
| 1020 | tst_resm(TBROK, "Unknown test case processing actions declared"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | /*********************************************************************** |
| 1024 | * This routine checks for the return of ENOENT errno from requested |
| 1025 | * system call |
| 1026 | * |
| 1027 | * Argument is pointer to test_objects array of structures of type |
| 1028 | * all_test_cases |
| 1029 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1030 | void do_ENOENT(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1031 | struct all_test_cases *tc_ptr; |
| 1032 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1033 | if ((cktcsid(tc_ptr->tcid, STAT)) || (cktcsid(tc_ptr->tcid, STAT_64))) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1034 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1035 | if ((stat(tc_ptr->fn_arg[1], &asymlink) == -1) |
| 1036 | && (errno == ENOENT)) |
| 1037 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1038 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1039 | else |
| 1040 | Tst_count++; |
| 1041 | else |
| 1042 | tst_resm(TFAIL, "%s %s errno:%d %s", |
| 1043 | "Expected ENOENT error for stating a non-existent directory", |
| 1044 | "through a symbolic link file was not received:", |
| 1045 | errno, strerror(errno)); |
| 1046 | } else if (cktcsid(tc_ptr->tcid, CHDIR)) { |
| 1047 | if ((chdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOENT)) |
| 1048 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1049 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1050 | else |
| 1051 | Tst_count++; |
| 1052 | else { |
| 1053 | tst_resm(TFAIL, "%s %s errno:%d %s", |
| 1054 | "Expected ENOENT error for changing to a non-existent", |
| 1055 | "directory through a symbolic link file was not received:", |
| 1056 | errno, strerror(errno)); |
| 1057 | chdir(TESTDIR); |
| 1058 | } |
| 1059 | } else if (cktcsid(tc_ptr->tcid, LINK)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1060 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1061 | if ((link(tc_ptr->fn_arg[1], "nick") == -1) |
| 1062 | && (errno == ENOENT)) |
| 1063 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1064 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1065 | else |
| 1066 | Tst_count++; |
| 1067 | else { |
| 1068 | tst_resm(TFAIL, "%s %s errno:%d %s", |
| 1069 | "Expected ENOENT error condition when link(2) a symbolic", |
| 1070 | "link which pointed at no object:", errno, strerror(errno)); |
| 1071 | delete_files("nick", NULL); |
| 1072 | } |
| 1073 | } else if (cktcsid(tc_ptr->tcid, CHMOD)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1074 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1075 | if ((chmod(tc_ptr->fn_arg[1], MODE) == -1) && (errno == ENOENT)) |
| 1076 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1077 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1078 | else |
| 1079 | Tst_count++; |
| 1080 | else |
| 1081 | tst_resm(TFAIL, "%s %s errno:%d %s", |
| 1082 | "Expected ENOENT error condition when chmod(2) a symbolic", |
| 1083 | "link which pointed at no object,", errno, strerror(errno)); |
| 1084 | } else if (cktcsid(tc_ptr->tcid, UTIME)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1085 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1086 | if ((utime(tc_ptr->fn_arg[1], NULL) == -1) && (errno == ENOENT)) |
| 1087 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1088 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1089 | else |
| 1090 | Tst_count++; |
| 1091 | else |
| 1092 | tst_resm(TFAIL, "%s %s errno:%d %s", |
| 1093 | "Expected ENOENT error condition when utime(2) a symbolic", |
| 1094 | "link which pointed at no object:", errno, strerror(errno)); |
| 1095 | } else if (cktcsid(tc_ptr->tcid, OPEN)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1096 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1097 | if ((open(tc_ptr->fn_arg[1], O_RDWR) == -1) |
| 1098 | && (errno == ENOENT)) |
| 1099 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1100 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1101 | else |
| 1102 | Tst_count++; |
| 1103 | else |
| 1104 | tst_resm(TFAIL, "%s %s errno:%d %s", |
| 1105 | "Expected ENOENT error for opening a non-existent object", |
| 1106 | " file through a symbolic link file was not received,", |
| 1107 | errno, strerror(errno)); |
| 1108 | } else |
| 1109 | tst_resm(TBROK, "Unknown test case processing actions declared"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | /*********************************************************************** |
| 1113 | * This routine checks for the return of ELOOP errno from requested |
| 1114 | * system call |
| 1115 | * |
| 1116 | * Argument is pointer to test_objects array of structures of type |
| 1117 | * all_test_cases |
| 1118 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1119 | void do_ELOOP(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1120 | struct all_test_cases *tc_ptr; |
| 1121 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1122 | if ((cktcsid(tc_ptr->tcid, STAT)) || (cktcsid(tc_ptr->tcid, STAT_64))) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1123 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1124 | TEST(stat(tc_ptr->fn_arg[1], &asymlink)); |
| 1125 | errno = TEST_ERRNO; |
| 1126 | if ((TEST_RETURN == -1) && (errno == ELOOP)) |
| 1127 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1128 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1129 | else |
| 1130 | Tst_count++; |
| 1131 | else if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
| 1132 | tst_resm(TEST_RESULT, "%s errno:%d %s", |
| 1133 | "Expected ELOOP errno from stat(2) (nested symb link),", |
| 1134 | errno, strerror(errno)); |
| 1135 | else |
| 1136 | Tst_count++; |
| 1137 | } else if (cktcsid(tc_ptr->tcid, CHDIR)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1138 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1139 | TEST(chdir(tc_ptr->fn_arg[1])); |
| 1140 | errno = TEST_ERRNO; |
| 1141 | if ((TEST_RETURN == -1) && (errno == ELOOP)) |
| 1142 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1143 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1144 | else |
| 1145 | Tst_count++; |
| 1146 | else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1147 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1148 | tst_resm(TFAIL, "%s errno:%d %s", |
| 1149 | "Expected ELOOP error condition when chdir(2) a nested symbolic link:", |
| 1150 | errno, strerror(errno)); |
| 1151 | chdir(TESTDIR); |
| 1152 | } |
| 1153 | } else if (cktcsid(tc_ptr->tcid, LINK)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1154 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1155 | TEST(link(tc_ptr->fn_arg[1], O_FILE)); |
| 1156 | errno = TEST_ERRNO; |
| 1157 | if ((TEST_RETURN == -1) && (errno == ELOOP)) |
| 1158 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1159 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1160 | else |
| 1161 | Tst_count++; |
| 1162 | else |
| 1163 | tst_resm(TFAIL, "%s errno:%d %s", |
| 1164 | "Expected ELOOP error condition when link(2) a nested symbolic link:", |
| 1165 | errno, strerror(errno)); |
| 1166 | } else if (cktcsid(tc_ptr->tcid, CHMOD)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1167 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1168 | TEST(chmod(tc_ptr->fn_arg[1], MODE)); |
| 1169 | errno = TEST_ERRNO; |
| 1170 | if ((TEST_RETURN == -1) && (errno == ELOOP)) |
| 1171 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1172 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1173 | else |
| 1174 | Tst_count++; |
| 1175 | else |
| 1176 | tst_resm(TFAIL, "%s errno:%d %s", |
| 1177 | "Expected ELOOP error condition when chmod(2) a nested symbolic link:", |
| 1178 | errno, strerror(errno)); |
| 1179 | return; |
| 1180 | } else if (cktcsid(tc_ptr->tcid, UTIME)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1181 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1182 | TEST(utime(tc_ptr->fn_arg[1], NULL)); |
| 1183 | errno = TEST_ERRNO; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1184 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1185 | if ((TEST_RETURN == -1) && (errno == ELOOP)) |
| 1186 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1187 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1188 | else |
| 1189 | Tst_count++; |
| 1190 | else |
| 1191 | tst_resm(TFAIL, "%s errno:%d %s", |
| 1192 | "Expected ELOOP error condition when utime(2) a nested symbolic link:", |
| 1193 | errno, strerror(errno)); |
| 1194 | } else if (cktcsid(tc_ptr->tcid, OPEN)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1195 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1196 | int fd; |
| 1197 | TEST(open(tc_ptr->fn_arg[1], O_CREAT, 0666)); |
| 1198 | fd = TEST_RETURN; |
| 1199 | errno = TEST_ERRNO; |
| 1200 | if ((fd == -1) && (errno == ELOOP)) |
| 1201 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1202 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1203 | else |
| 1204 | Tst_count++; |
| 1205 | else |
| 1206 | tst_resm(TFAIL, "%s errno:%d %s", |
| 1207 | "Expected ELOOP error condition when open(2) a nested symbolic link:", |
| 1208 | errno, strerror(errno)); |
| 1209 | } else |
| 1210 | tst_resm(TBROK, "Unknown test case processing actions declared"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /*********************************************************************** |
| 1214 | * This routine checks for the return of ENOTDIR errno from requested |
| 1215 | * system call |
| 1216 | * |
| 1217 | * Argument is pointer to test_objects array of structures of type |
| 1218 | * all_test_cases |
| 1219 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1220 | void do_ENOTDIR(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1221 | struct all_test_cases *tc_ptr; |
| 1222 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1223 | if (cktcsid(tc_ptr->tcid, RMDIR)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1224 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1225 | TEST(mkdir(tc_ptr->fn_arg[0], MODE)); |
| 1226 | errno = TEST_ERRNO; |
| 1227 | if (TEST_RETURN == -1) |
| 1228 | tst_resm(TBROK, "mkdir(2) Failure when creating %s", tc_ptr->fn_arg[0]); |
| 1229 | else if ((rmdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOTDIR)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1230 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1231 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1232 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1233 | else |
| 1234 | Tst_count++; |
| 1235 | rmdir(tc_ptr->fn_arg[0]); |
| 1236 | } else |
| 1237 | tst_resm(TFAIL, "%s %s errno:%d %s", |
| 1238 | "Expected ENOTDIR error for removing a non-existent", |
| 1239 | "directory through a symbolic link file was not received,", |
| 1240 | errno, strerror(errno)); |
| 1241 | } else |
| 1242 | tst_resm(TBROK, "Unknown test case processing actions declared"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | /*********************************************************************** |
| 1246 | * This routine checks for the return of EXDEV errno from requested |
| 1247 | * system call |
| 1248 | * |
| 1249 | * Argument is pointer to test_objects array of structures of type |
| 1250 | * all_test_cases |
| 1251 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1252 | void do_EXDEV(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1253 | struct all_test_cases *tc_ptr; |
| 1254 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1255 | if (cktcsid(tc_ptr->tcid, RENAME)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1256 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1257 | TEST(rename(tc_ptr->fn_arg[1], Y_A_S_FILE)); |
| 1258 | errno = TEST_ERRNO; |
| 1259 | if ((TEST_RETURN == -1) && (errno == EXDEV)) { |
| 1260 | if (see_if_a_symlink(Y_A_S_FILE) == -1) |
| 1261 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1262 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1263 | else |
| 1264 | Tst_count++; |
| 1265 | else |
| 1266 | tst_resm(TFAIL, |
| 1267 | "%s %s %s file outside of current file system", |
| 1268 | "rename(3) returned -1 when trying to move symbolic link file", |
| 1269 | "outside of current file system, but created", Y_A_S_FILE); |
| 1270 | } else { |
| 1271 | tst_resm(TFAIL, "%s %s errno:%d %s", |
| 1272 | "Expected EXDEV error for renaming an existing symbolic", |
| 1273 | "link file to a location outside of existing file system,", |
| 1274 | errno, strerror(errno)); |
| 1275 | delete_files("/NiCkEr", NULL); |
| 1276 | } |
| 1277 | } else |
| 1278 | tst_resm(TBROK, "Unknown test case processing actions declared"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | /*********************************************************************** |
| 1282 | * This routine checks for the return of ENAMETOOLONG errno from requested |
| 1283 | * system call |
| 1284 | * |
| 1285 | * Argument is pointer to test_objects array of structures of type |
| 1286 | * all_test_cases |
| 1287 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1288 | void do_ENAMETOOLONG(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1289 | struct all_test_cases *tc_ptr; |
| 1290 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1291 | int ret; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1292 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1293 | if (cktcsid(tc_ptr->tcid, SYMLINK)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1294 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1295 | TEST(symlink(tc_ptr->fn_arg[0], full_path)); |
| 1296 | errno = TEST_ERRNO; |
| 1297 | if ((TEST_RETURN == -1) && (errno == ENAMETOOLONG)) |
| 1298 | if (see_if_a_symlink(full_path) == -1) |
| 1299 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1300 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1301 | else |
| 1302 | Tst_count++; |
| 1303 | else |
| 1304 | tst_resm(TFAIL, "%s %s %d %s", |
| 1305 | "symlink(2) returned -1 when trying to create a symbolic", |
| 1306 | "link file whose name exceeded", |
| 1307 | (PATH_MAX + 1), |
| 1308 | "characters, but it created the symbolic link file"); |
| 1309 | else |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1310 | tst_resm(TFAIL|TERRNO, |
| 1311 | "Expected ENAMETOOLONG error when creating %s symbolic link file with a path exceeding %d characters", |
| 1312 | tc_ptr->fn_arg[1], (PATH_MAX + 1)); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1313 | } else if (cktcsid(tc_ptr->tcid, READLINK)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1314 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1315 | char scratch[PATH_MAX + 1]; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1316 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1317 | ret = readlink(full_path, scratch, strlen(full_path)); |
| 1318 | if ((ret == -1) && (errno == ENAMETOOLONG)) |
| 1319 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1320 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1321 | else |
| 1322 | Tst_count++; |
| 1323 | else |
| 1324 | tst_resm(TFAIL, |
| 1325 | "Expected ENAMETOOLONG error when reading %s symbolic link file with a path exceeding %d characters: errno:%d %s", |
| 1326 | tc_ptr->fn_arg[1], (PATH_MAX + 1), errno, strerror(errno)); |
| 1327 | } else |
| 1328 | tst_resm(TBROK, "Unknown test case processing actions declared"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | /*********************************************************************** |
| 1332 | * This routine checks for the return of EINVAL errno from requested |
| 1333 | * system call |
| 1334 | * |
| 1335 | * Argument is pointer to test_objects array of structures of type |
| 1336 | * all_test_cases |
| 1337 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1338 | void do_EINVAL(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1339 | struct all_test_cases *tc_ptr; |
| 1340 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1341 | if (cktcsid(tc_ptr->tcid, READLINK)) { |
| 1342 | TEST(readlink(tc_ptr->fn_arg[0], test_msg, BUFMAX)); |
| 1343 | errno = TEST_ERRNO; |
| 1344 | if (TEST_RETURN == -1) { |
| 1345 | if (errno == EINVAL) { |
| 1346 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1347 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1348 | else |
| 1349 | Tst_count++; |
| 1350 | } else |
| 1351 | tst_resm(TFAIL, |
| 1352 | "readlink(2) ret:-1, errno:%d, : Exp errno:%d", |
| 1353 | errno, EINVAL); |
| 1354 | } else { |
| 1355 | tst_resm(TFAIL, |
| 1356 | "readlink(2) did not returned -1 when reading %s", |
| 1357 | "a file which is not a symbolic link file"); |
| 1358 | } |
| 1359 | } else |
| 1360 | tst_resm(TBROK, "Unknown test case processing actions declared"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | /*********************************************************************** |
| 1364 | * This routine checks out the readlink(2) system call for a successful |
| 1365 | * invocation |
| 1366 | * |
| 1367 | * Argument is pointer to test_objects array of structures of type |
| 1368 | * all_test_cases |
| 1369 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1370 | void do_readlink(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1371 | struct all_test_cases *tc_ptr; |
| 1372 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1373 | char scratch[PATH_MAX]; |
| 1374 | int ret; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1375 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1376 | ret = readlink(tc_ptr->fn_arg[1], scratch, strlen(tc_ptr->fn_arg[0])); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1377 | |
| 1378 | /*** the TEST macro cannot be used here for some reason ****/ |
| 1379 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1380 | if (ret == -1) { |
| 1381 | tst_resm(TFAIL, "readlink(2) failure on %s symbolic link file", tc_ptr->fn_arg[1]); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1382 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1383 | } else if (strncmp(tc_ptr->fn_arg[0], scratch, strlen(tc_ptr->fn_arg[0])) != 0) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1384 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1385 | /* Must null terminate scratch because readlink(2) doesn't */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1386 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1387 | scratch[strlen(tc_ptr->fn_arg[0])] = '\0'; |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 1388 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1389 | tst_resm(TFAIL, |
| 1390 | "readlink(2) Error : Expected %s symbolic link file contents but %s actual contents were returned", |
| 1391 | tc_ptr->fn_arg[0], scratch); |
| 1392 | } else if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1393 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1394 | else |
| 1395 | Tst_count++; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | /*********************************************************************** |
| 1399 | * This routine checks out the stat(2) system call for a successful |
| 1400 | * invocation |
| 1401 | * |
| 1402 | * Argument is pointer to test_objects array of structures of type |
| 1403 | * all_test_cases |
| 1404 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1405 | void do_stat(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1406 | struct all_test_cases *tc_ptr; |
| 1407 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1408 | if (statter.st_dev != asymlink.st_dev) |
| 1409 | tst_resm(TFAIL, |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 1410 | "stat of symbolic link reference to object device info %jd != stat of object file device info %jd", |
| 1411 | (intmax_t)statter.st_dev, (intmax_t)asymlink.st_dev); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1412 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1413 | else if (statter.st_mode != asymlink.st_mode) |
| 1414 | tst_resm(TFAIL, |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 1415 | "stat of symbolic link reference to object file permissions %jd != stat of object file permissions %jd", |
| 1416 | (intmax_t)statter.st_mode, (intmax_t)asymlink.st_mode); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1417 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1418 | else if (statter.st_nlink != asymlink.st_nlink) |
| 1419 | tst_resm(TFAIL, |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 1420 | "stat of symbolic link reference to object file link count %jd != stat of object file link count %jd", |
| 1421 | (intmax_t)statter.st_nlink, (intmax_t)asymlink.st_nlink); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1422 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1423 | else if (statter.st_uid != asymlink.st_uid) |
| 1424 | tst_resm(TFAIL, |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 1425 | "stat of symbolic link reference to object file uid %jd != stat of object file uid %jd", |
| 1426 | (intmax_t)statter.st_uid, (intmax_t)asymlink.st_uid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1427 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1428 | else if (statter.st_gid != asymlink.st_gid) |
| 1429 | tst_resm(TFAIL, |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 1430 | "stat of symbolic link reference to object file gid %jd != stat of object file gid %jd", |
| 1431 | (intmax_t)statter.st_gid, (intmax_t)asymlink.st_gid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1432 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1433 | else if (statter.st_size != asymlink.st_size) |
| 1434 | tst_resm(TFAIL, |
| 1435 | "stat of symbolic link reference to object file size %ld != stat of object file size %ld", |
| 1436 | statter.st_size, asymlink.st_size); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1437 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1438 | else if (statter.st_atime != asymlink.st_atime) |
| 1439 | tst_resm(TFAIL, |
| 1440 | "stat of symbolic link reference to object access time %ld != stat of object file access time %ld", |
| 1441 | statter.st_atime, asymlink.st_atime); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1442 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1443 | else if (statter.st_mtime != asymlink.st_mtime) |
| 1444 | tst_resm(TFAIL, |
| 1445 | "stat of symbolic link reference to object modify time %ld != stat of object file modify time %ld", |
| 1446 | statter.st_atime, asymlink.st_atime); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1447 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1448 | else if (statter.st_ctime != asymlink.st_ctime) |
| 1449 | tst_resm(TFAIL, |
| 1450 | "stat of symbolic link reference to object change time %ld != stat of object file change time %ld", |
| 1451 | statter.st_atime, asymlink.st_atime); |
| 1452 | else if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1453 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1454 | else |
| 1455 | Tst_count++; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /*********************************************************************** |
| 1459 | * This routine checks out the chdir(2) system call for a successful |
| 1460 | * invocation |
| 1461 | * |
| 1462 | * Argument is pointer to test_objects array of structures of type |
| 1463 | * all_test_cases |
| 1464 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1465 | void do_chdir(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1466 | struct all_test_cases *tc_ptr; |
| 1467 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1468 | if (mkdir(tc_ptr->fn_arg[2], MODE) == -1) |
| 1469 | tst_resm(TFAIL, "Could not create a setup directory file"); |
| 1470 | else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1471 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1472 | sprintf(Buf, "mkdir(%s, %#o) was successful\n", tc_ptr->fn_arg[2], MODE); |
| 1473 | strcat(Buffer, Buf); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1474 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1475 | if (chdir(tc_ptr->fn_arg[1]) == -1) |
| 1476 | tst_resm(TFAIL, |
| 1477 | "%sCould not change a directory file through a %s", |
| 1478 | Buffer, "symbolic link which which pointed at object"); |
| 1479 | else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1480 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1481 | char *cwd, *getcwd(); |
| 1482 | char expected_location[PATH_MAX]; |
| 1483 | /* |
| 1484 | * Build expected current directory position |
| 1485 | */ |
| 1486 | strcpy(expected_location, TESTDIR); |
| 1487 | strcat(expected_location, "/"); |
| 1488 | strcat(expected_location, tc_ptr->fn_arg[2]); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1489 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 1490 | if ((cwd = getcwd(NULL, 0)) == NULL) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1491 | tst_resm(TFAIL, "getcwd(3) FAILURE"); |
| 1492 | else if (strcmp(cwd, expected_location) == 0) |
| 1493 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1494 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1495 | else |
| 1496 | Tst_count++; |
| 1497 | else { |
| 1498 | tst_resm(TFAIL, |
| 1499 | "%s%s %s %s not equal to expected %s", |
| 1500 | Buffer, |
| 1501 | "chdir(2) returned successfully, but getcwd(3) indicated", |
| 1502 | "new current working directory location", |
| 1503 | cwd, expected_location); |
| 1504 | } |
| 1505 | chdir(TESTDIR); |
| 1506 | } |
| 1507 | rmdir(tc_ptr->fn_arg[2]); |
| 1508 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | /*********************************************************************** |
| 1512 | * This routine checks out the link(2) system call for a successful |
| 1513 | * invocation |
| 1514 | * |
| 1515 | * Argument is pointer to test_objects array of structures of type |
| 1516 | * all_test_cases |
| 1517 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1518 | void do_link(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1519 | struct all_test_cases *tc_ptr; |
| 1520 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1521 | struct stat stbuf; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1522 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1523 | if (link(tc_ptr->fn_arg[1], "nick") == -1) { |
| 1524 | tst_resm(TFAIL, "%slink(%s, \"nick\") failed, errno: %d: %s %s", |
| 1525 | Buffer, tc_ptr->fn_arg[1], errno, |
| 1526 | "link of new file to object file via symbolic link file failed", |
| 1527 | "when expected not to"); |
| 1528 | } else { |
| 1529 | sprintf(Buf, "link(%s, \"nick\") was successful\n", tc_ptr->fn_arg[1]); |
| 1530 | strcat(Buffer, Buf); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1531 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1532 | if (STD_FUNCTIONAL_TEST) { |
| 1533 | /* |
| 1534 | * Check that links counts were properly set |
| 1535 | */ |
| 1536 | if (lstat(tc_ptr->fn_arg[1], &asymlink) == -1) { |
| 1537 | tst_resm(TBROK, "lstat(%s) failed. errno: %d", |
| 1538 | tc_ptr->fn_arg[1], errno); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1539 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1540 | } else if (lstat("nick", &statter) == -1) { |
| 1541 | tst_resm(TBROK, "lstat(nick) failed, errno:%d", errno); |
| 1542 | } else { |
| 1543 | if (statter.st_ino == asymlink.st_ino) { |
| 1544 | if ((statter.st_nlink == 2) |
| 1545 | && (asymlink.st_nlink == 2)) { |
| 1546 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1547 | tst_resm(TEST_RESULT, "%s", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1548 | msgs[tc_ptr->pass_msg]); |
| 1549 | else |
| 1550 | Tst_count++; |
| 1551 | } else { |
| 1552 | lstat(tc_ptr->fn_arg[2], &stbuf); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1553 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1554 | tst_resm(TFAIL, |
| 1555 | "%slink(%s, %s) failed to adjust link count.\n\ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1556 | count for nick is %d, count for %s is %d, count for %s is %d.", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1557 | Buffer, tc_ptr->fn_arg[1], "nick", statter.st_nlink, tc_ptr->fn_arg[1], asymlink.st_nlink, tc_ptr->fn_arg[2], |
| 1558 | stbuf.st_nlink); |
| 1559 | } |
| 1560 | } else { |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 1561 | tst_resm(TFAIL, "%sA lstat of %s (ino:%jd) and of\n\t\t\ |
| 1562 | %s (ino:%jd), does not show them being the same ino.", Buffer, tc_ptr->fn_arg[1], (intmax_t)asymlink.st_ino, "nick", (intmax_t)statter.st_ino); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1563 | } |
| 1564 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1565 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1566 | delete_files("nick", NULL); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1567 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | /*********************************************************************** |
| 1571 | * This routine checks out the unlink(2) system call for a successful |
| 1572 | * invocation |
| 1573 | * |
| 1574 | * Argument is pointer to test_objects array of structures of type |
| 1575 | * all_test_cases |
| 1576 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1577 | void do_unlink(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1578 | struct all_test_cases *tc_ptr; |
| 1579 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1580 | if (stat(tc_ptr->fn_arg[2], &asymlink) == -1) |
| 1581 | tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]); |
| 1582 | else if (unlink(tc_ptr->fn_arg[1]) == -1) |
| 1583 | tst_resm(TFAIL, "unlink(2) failed when removing symbolic link file"); |
| 1584 | else { |
| 1585 | sprintf(Buf, "unlink(%s) was successful\n", tc_ptr->fn_arg[1]); |
| 1586 | strcat(Buffer, Buf); |
| 1587 | if (stat(tc_ptr->fn_arg[2], &statter) == -1) |
| 1588 | tst_resm(TFAIL, "%s %s", |
| 1589 | "unlink(2) failed because it not only removed symbolic link", |
| 1590 | "file which pointed at object file, but object file as well"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 1591 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1592 | else if ((statter.st_ino == asymlink.st_ino) && |
| 1593 | (statter.st_dev == asymlink.st_dev) && |
| 1594 | (statter.st_size == asymlink.st_size)) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1595 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1596 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1597 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1598 | else |
| 1599 | Tst_count++; |
| 1600 | else |
| 1601 | tst_resm(TFAIL, "%s%s %s %s", Buffer, |
| 1602 | "unlink(2) failed because it not only removed symbolic link", |
| 1603 | "file which pointed at object file, but it changed object", |
| 1604 | "file inode information"); |
| 1605 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1606 | |
| 1607 | } |
| 1608 | |
| 1609 | /*********************************************************************** |
| 1610 | * This routine checks out the chmod(2) system call for a successful |
| 1611 | * invocation |
| 1612 | * |
| 1613 | * Argument is pointer to test_objects array of structures of type |
| 1614 | * all_test_cases |
| 1615 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1616 | void do_chmod(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1617 | struct all_test_cases *tc_ptr; |
| 1618 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1619 | if (stat(tc_ptr->fn_arg[2], &asymlink) == -1) |
| 1620 | tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]); |
| 1621 | else if (chmod(tc_ptr->fn_arg[1], (MODE | MASK)) == -1) |
| 1622 | tst_resm(TFAIL, "%s%s %s", Buffer, |
| 1623 | "chmod(2) failed when changing file permission", |
| 1624 | "through symbolic link file"); |
| 1625 | else { |
| 1626 | sprintf(Buf, "chmod(%s, %#o) was successful\n", tc_ptr->fn_arg[1], (MODE | MASK)); |
| 1627 | strcat(Buffer, Buf); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1628 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1629 | if (stat(tc_ptr->fn_arg[2], &statter) == -1) |
| 1630 | tst_resm(TBROK, |
| 1631 | "stat(2) Failure when accessing %s object file", |
| 1632 | tc_ptr->fn_arg[2]); |
| 1633 | else if ((statter.st_mode == (MODE | MASK)) |
| 1634 | && (statter.st_mode != asymlink.st_mode)) |
| 1635 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1636 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1637 | else |
| 1638 | Tst_count++; |
| 1639 | else |
| 1640 | tst_resm(TFAIL, "%s%s %o to %o %s", Buffer, |
| 1641 | "chmod(2) failed to change object file permissions from", |
| 1642 | asymlink.st_mode, (MODE | MASK), "through symbolic link file"); |
| 1643 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1644 | |
| 1645 | } |
| 1646 | |
| 1647 | /*********************************************************************** |
| 1648 | * This routine checks out the utime(2) system call for a successful |
| 1649 | * invocation |
| 1650 | * |
| 1651 | * Argument is pointer to test_objects array of structures of type |
| 1652 | * all_test_cases |
| 1653 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1654 | void do_utime(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1655 | struct all_test_cases *tc_ptr; |
| 1656 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1657 | struct utimbuf utimes; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1658 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1659 | if (stat(tc_ptr->fn_arg[2], &asymlink) == -1) |
| 1660 | tst_resm(TBROK, "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]); |
| 1661 | else { |
| 1662 | /* Now add a few values to access and modify times */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1663 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1664 | utimes.actime = asymlink.st_atime + a_time_value; |
| 1665 | utimes.modtime = asymlink.st_mtime + a_time_value; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1666 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1667 | /* Now hand off to utime(2) via symbolic link file */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1668 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1669 | if (utime(tc_ptr->fn_arg[1], &utimes) == -1) |
| 1670 | tst_resm(TFAIL, "%s %s", |
| 1671 | "utime(2) failed to process object file access and modify", |
| 1672 | "time updates through symbolic link"); |
| 1673 | else { |
| 1674 | /* Now verify changes were made */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1675 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1676 | if (stat(tc_ptr->fn_arg[2], &statter) == -1) |
| 1677 | tst_resm(TBROK, |
| 1678 | "stat(2) Failure when accessing %s object file", |
| 1679 | tc_ptr->fn_arg[2]); |
| 1680 | else { |
| 1681 | time_t temp, diff; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1682 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1683 | temp = statter.st_atime - asymlink.st_atime; |
| 1684 | diff = (statter.st_mtime - asymlink.st_mtime) - temp; |
| 1685 | |
| 1686 | if (!diff) |
| 1687 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1688 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1689 | else |
| 1690 | Tst_count++; |
| 1691 | else |
| 1692 | tst_resm(TFAIL, |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 1693 | "%s %s %jd greater than original times", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1694 | "utime(2) failed to change object file access and", |
| 1695 | "modify times through symbolic link to a value", |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 1696 | (intmax_t)a_time_value); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1697 | } |
| 1698 | } |
| 1699 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | /*********************************************************************** |
| 1703 | * This routine checks out the rename(2) system call for a successful |
| 1704 | * invocation |
| 1705 | * |
| 1706 | * Argument is pointer to test_objects array of structures of type |
| 1707 | * all_test_cases |
| 1708 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1709 | void do_rename(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1710 | struct all_test_cases *tc_ptr; |
| 1711 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1712 | int pts_at_object = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1713 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1714 | if (stat(tc_ptr->fn_arg[2], &statter) != -1) |
| 1715 | pts_at_object = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1716 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1717 | TEST(rename(tc_ptr->fn_arg[1], A_S_FILE)); |
| 1718 | errno = TEST_ERRNO; |
| 1719 | if (TEST_RETURN == -1) |
| 1720 | tst_resm(TFAIL, |
| 1721 | "rename(3) failed to rename %s symbolic link file to %s", |
| 1722 | tc_ptr->fn_arg[2], A_S_FILE); |
| 1723 | else if (pts_at_object) |
| 1724 | if (ck_both(tc_ptr->fn_arg[0], A_S_FILE, tc_ptr->fn_arg[2])) |
| 1725 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1726 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1727 | else |
| 1728 | Tst_count++; |
| 1729 | else |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1730 | tst_resm(TFAIL, "%s", test_msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1731 | else if (!ck_symlink(tc_ptr->fn_arg[0], A_S_FILE, NULL)) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1732 | tst_resm(TFAIL, "%s", test_msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1733 | else if (stat(tc_ptr->fn_arg[1], &asymlink) != -1) |
| 1734 | tst_resm(TFAIL, |
| 1735 | "rename(3) did not remove %s when renaming to %s", |
| 1736 | tc_ptr->fn_arg[1], A_S_FILE); |
| 1737 | else if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1738 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1739 | else |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1740 | Tst_count++; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | /*********************************************************************** |
| 1744 | * This routine checks out the open(2) system call for a successful |
| 1745 | * invocation |
| 1746 | * |
| 1747 | * Argument is pointer to test_objects array of structures of type |
| 1748 | * all_test_cases |
| 1749 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1750 | void do_open(tc_ptr) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1751 | struct all_test_cases *tc_ptr; |
| 1752 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1753 | int fd = -1; |
| 1754 | int ret, pts_at_object = 0; |
| 1755 | char scratch[PATH_MAX]; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1756 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1757 | if (stat(tc_ptr->fn_arg[2], &statter) != -1) |
| 1758 | pts_at_object = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1759 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1760 | if (pts_at_object) { |
| 1761 | TEST(open(tc_ptr->fn_arg[1], O_RDWR)); |
| 1762 | errno = TEST_ERRNO; |
| 1763 | if ((fd = TEST_RETURN) == -1) { |
| 1764 | tst_resm(TFAIL, |
| 1765 | "open(2) Failure when opening object file through symbolic link file"); |
| 1766 | return; |
| 1767 | } |
| 1768 | } else { |
| 1769 | TEST(open(tc_ptr->fn_arg[1], (O_CREAT | O_RDWR), MODE)); |
| 1770 | errno = TEST_ERRNO; |
| 1771 | if ((fd = TEST_RETURN) == -1) { |
| 1772 | tst_resm(TFAIL, |
| 1773 | "open(2) Failure when creating object file through symbolic link file"); |
| 1774 | return; |
| 1775 | } |
| 1776 | } |
| 1777 | if ((ret = write(fd, BIG_STRING, strlen(BIG_STRING))) == -1) { |
| 1778 | tst_resm(TFAIL, |
| 1779 | "write(2) Failure to object file opened through a symbolic link file: errno:%d", |
| 1780 | errno); |
| 1781 | } else if (ret != strlen(BIG_STRING)) { |
| 1782 | tst_resm(TFAIL, |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1783 | "write(2) Failed to write %zu bytes to object file opened through a symbolic link file", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1784 | strlen(BIG_STRING)); |
| 1785 | } else if (lseek(fd, 0L, 0) == -1) { |
| 1786 | tst_resm(TFAIL, |
| 1787 | "lseek(2) Failed to position to beginning of object file opened through a symbolic link file: errno = %d", |
| 1788 | errno); |
| 1789 | } else if ((ret = read(fd, scratch, strlen(BIG_STRING))) == -1) { |
| 1790 | tst_resm(TFAIL, |
| 1791 | "read(2) Failure of object file opened through a symbolic link file: errno = %d", |
| 1792 | errno); |
| 1793 | } else if (ret != strlen(BIG_STRING)) { |
| 1794 | tst_resm(TFAIL, |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1795 | "read(2) Failed to read %zu bytes to object file opened through a symbolic link file", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1796 | strlen(BIG_STRING)); |
| 1797 | } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) { |
| 1798 | tst_resm(TFAIL, |
| 1799 | "Content of write(2) and read(2) Failed to object file through symbolic link file was not as expected. Expected %s and read returned %s", |
| 1800 | BIG_STRING, scratch); |
| 1801 | } else { |
| 1802 | /* |
| 1803 | * Close off symbolic link file to object file access |
| 1804 | */ |
| 1805 | if (close(fd) == -1) { |
| 1806 | tst_resm(TFAIL, |
| 1807 | "close(2) Failure when closing object file accessed symbolic link file"); |
| 1808 | } |
| 1809 | /* |
| 1810 | * Now, lets open up and read object file and compare contents |
| 1811 | */ |
| 1812 | else if ((fd = open(tc_ptr->fn_arg[0], O_RDONLY)) == -1) { |
| 1813 | tst_resm(TFAIL, |
| 1814 | "open(2) Failure when opening %s file: errno:%d %s", |
| 1815 | tc_ptr->fn_arg[0], errno, strerror(errno)); |
| 1816 | } else if ((ret = read(fd, scratch, strlen(BIG_STRING))) == -1) { |
| 1817 | tst_resm(TFAIL, |
| 1818 | "read(2) Failure of object file opened through a symbolic link file: errno:%d", |
| 1819 | errno); |
| 1820 | } else if (ret != strlen(BIG_STRING)) { |
| 1821 | tst_resm(TFAIL, |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1822 | "read(2) Failed to read %zu bytes to object file opened through a symbolic link file", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1823 | strlen(BIG_STRING)); |
| 1824 | } else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) { |
| 1825 | tst_resm(TFAIL, |
| 1826 | "Content of write(2) and read(2) Failed to object file through symbolic link file was not as expected. Expected %s and read returned %s", |
| 1827 | BIG_STRING, scratch); |
| 1828 | } else if (pts_at_object) { |
| 1829 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1830 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1831 | else |
| 1832 | Tst_count++; |
| 1833 | } else { /* Insure newly created object file is pointed at */ |
| 1834 | if (ck_both(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1], tc_ptr->fn_arg[0])) |
| 1835 | if (TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST) |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1836 | tst_resm(TEST_RESULT, "%s", msgs[tc_ptr->pass_msg]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1837 | else |
| 1838 | Tst_count++; |
| 1839 | else |
vapier | e5fce93 | 2009-08-28 14:17:14 +0000 | [diff] [blame] | 1840 | tst_resm(TFAIL, "%s", test_msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1841 | } |
| 1842 | close(fd); |
| 1843 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | /*************************************************************** |
| 1847 | * setup() - performs all ONE TIME setup for this test. |
| 1848 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1849 | void setup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1850 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 1851 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1852 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1853 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1854 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1855 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1856 | /* create a temporary directory and go to it */ |
| 1857 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1858 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 1859 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1860 | |
| 1861 | /*************************************************************** |
| 1862 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 1863 | * completion or premature exit. |
| 1864 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1865 | void cleanup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1866 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1867 | /* |
| 1868 | * print timing stats if that option was specified. |
| 1869 | */ |
| 1870 | TEST_CLEANUP; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1871 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1872 | tst_rmdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1873 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 1874 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1875 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1876 | void help() |
| 1877 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1878 | int ind; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1879 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1880 | printf(" -T id Determines which tests cases to execute:\n"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1881 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 1882 | for (ind = 0; ind < sizeof(all_tcses) / sizeof(struct tcses); ind++) { |
| 1883 | printf(" %s/%s - %s\n", all_tcses[ind].tcid, |
| 1884 | all_tcses[ind].syscall, all_tcses[ind].desc); |
| 1885 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 1886 | } |