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