vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2006 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 18 | * |
| 19 | * NAME |
| 20 | * faccessat01.c |
| 21 | * |
| 22 | * DESCRIPTION |
| 23 | * This test case will verify basic function of faccessat |
| 24 | * added by kernel 2.6.16 or up. |
| 25 | * |
| 26 | * USAGE: <for command-line> |
| 27 | * faccessat01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p] |
| 28 | * where: |
| 29 | * -c n : Run n copies simultaneously. |
| 30 | * -e : Turn on errno logging. |
| 31 | * -i n : Execute test n times. |
| 32 | * -I x : Execute test for x seconds. |
| 33 | * -p : Pause for SIGUSR1 before starting |
| 34 | * -P x : Pause for x seconds between iterations. |
| 35 | * -t : Turn on syscall timing. |
| 36 | * |
| 37 | * Author |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 38 | * Yi Yang <yyangcdl@cn.ibm.com> |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 39 | * |
| 40 | * History |
| 41 | * 08/28/2006 Created first by Yi Yang <yyangcdl@cn.ibm.com> |
| 42 | * |
| 43 | *****************************************************************************/ |
| 44 | |
| 45 | #define _GNU_SOURCE |
| 46 | |
| 47 | #include <sys/types.h> |
| 48 | #include <sys/stat.h> |
| 49 | #include <fcntl.h> |
| 50 | #include <unistd.h> |
| 51 | #include <error.h> |
| 52 | #include <stdlib.h> |
| 53 | #include <errno.h> |
| 54 | #include <string.h> |
| 55 | #include <signal.h> |
| 56 | #include "test.h" |
| 57 | #include "usctest.h" |
| 58 | #include "linux_syscall_numbers.h" |
| 59 | |
subrata_modak | bbaeb93 | 2008-03-27 12:01:59 +0000 | [diff] [blame] | 60 | #define TEST_CASES 6 |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 61 | #ifndef AT_FDCWD |
| 62 | #define AT_FDCWD -100 |
| 63 | #endif |
| 64 | void setup(); |
| 65 | void cleanup(); |
| 66 | void setup_every_copy(); |
| 67 | |
| 68 | char *TCID = "faccessat01"; /* Test program identifier. */ |
| 69 | int TST_TOTAL = TEST_CASES; /* Total number of test cases. */ |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 70 | char pathname[256] = ""; |
| 71 | char testfile[256] = ""; |
| 72 | char testfile2[256] = ""; |
| 73 | char testfile3[256] = ""; |
| 74 | int dirfd, fd, ret; |
| 75 | int fds[TEST_CASES]; |
| 76 | char *filenames[TEST_CASES]; |
subrata_modak | bbaeb93 | 2008-03-27 12:01:59 +0000 | [diff] [blame] | 77 | int expected_errno[TEST_CASES] = { 0, 0, ENOTDIR, EBADF, 0, 0 }; |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 78 | |
| 79 | int myfaccessat(int dirfd, const char *filename, int mode) |
| 80 | { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 81 | return ltp_syscall(__NR_faccessat, dirfd, filename, mode); |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | int main(int ac, char **av) |
| 85 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 86 | int lc; |
| 87 | char *msg; |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 88 | int i; |
| 89 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | /* Disable test if the version of the kernel is less than 2.6.16 */ |
| 91 | if (((tst_kvercmp(2, 6, 16)) < 0)) { |
| 92 | tst_resm(TWARN, "This test can only run on kernels that are "); |
| 93 | tst_resm(TWARN, "2.6.16 and higher"); |
| 94 | exit(0); |
| 95 | } |
mreed10 | 807cfe5 | 2006-09-18 19:03:19 +0000 | [diff] [blame] | 96 | |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 97 | /*************************************************************** |
| 98 | * parse standard options |
| 99 | ***************************************************************/ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 100 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 101 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 102 | |
| 103 | /*************************************************************** |
| 104 | * perform global setup for test |
| 105 | ***************************************************************/ |
| 106 | setup(); |
| 107 | |
| 108 | /*************************************************************** |
| 109 | * check looping state if -c option given |
| 110 | ***************************************************************/ |
| 111 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 112 | setup_every_copy(); |
| 113 | |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 114 | Tst_count = 0; |
| 115 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 116 | /* |
| 117 | * Call faccessat |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 118 | */ |
| 119 | for (i = 0; i < TST_TOTAL; i++) { |
| 120 | TEST(myfaccessat(fds[i], filenames[i], R_OK)); |
| 121 | |
| 122 | /* check return code */ |
| 123 | if (TEST_ERRNO == expected_errno[i]) { |
| 124 | |
| 125 | /*************************************************************** |
| 126 | * only perform functional verification if flag set (-f not given) |
| 127 | ***************************************************************/ |
| 128 | if (STD_FUNCTIONAL_TEST) { |
| 129 | /* No Verification test, yet... */ |
| 130 | tst_resm(TPASS, |
| 131 | "faccessat() returned the expected errno %d: %s", |
| 132 | TEST_ERRNO, |
| 133 | strerror(TEST_ERRNO)); |
| 134 | } |
| 135 | } else { |
| 136 | TEST_ERROR_LOG(TEST_ERRNO); |
| 137 | tst_resm(TFAIL, |
| 138 | "faccessdat() Failed, errno=%d : %s", |
| 139 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 140 | } |
| 141 | } |
| 142 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 143 | } |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 144 | |
| 145 | /*************************************************************** |
| 146 | * cleanup and exit |
| 147 | ***************************************************************/ |
| 148 | cleanup(); |
| 149 | |
| 150 | return (0); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 151 | } |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 152 | |
| 153 | void setup_every_copy() |
| 154 | { |
| 155 | /* Initialize test dir and file names */ |
| 156 | sprintf(pathname, "faccessattestdir%d", getpid()); |
| 157 | sprintf(testfile, "faccessattestfile%d.txt", getpid()); |
| 158 | sprintf(testfile2, "/tmp/faccessattestfile%d.txt", getpid()); |
| 159 | sprintf(testfile3, "faccessattestdir%d/faccessattestfile%d.txt", |
| 160 | getpid(), getpid()); |
| 161 | |
| 162 | ret = mkdir(pathname, 0700); |
| 163 | if (ret < 0) { |
| 164 | perror("mkdir: "); |
| 165 | exit(-1); |
| 166 | } |
| 167 | |
| 168 | dirfd = open(pathname, O_DIRECTORY); |
| 169 | if (dirfd < 0) { |
| 170 | perror("open: "); |
| 171 | exit(-1); |
| 172 | } |
| 173 | |
| 174 | fd = open(testfile, O_CREAT | O_RDWR, 0600); |
| 175 | if (fd < 0) { |
| 176 | perror("open: "); |
| 177 | exit(-1); |
| 178 | } |
| 179 | |
| 180 | fd = open(testfile2, O_CREAT | O_RDWR, 0600); |
| 181 | if (fd < 0) { |
| 182 | perror("open: "); |
| 183 | exit(-1); |
| 184 | } |
| 185 | |
| 186 | fd = open(testfile3, O_CREAT | O_RDWR, 0600); |
| 187 | if (fd < 0) { |
| 188 | perror("open: "); |
| 189 | exit(-1); |
| 190 | } |
| 191 | |
| 192 | fds[0] = fds[1] = fds[4] = dirfd; |
| 193 | fds[2] = fd; |
| 194 | fds[3] = 100; |
subrata_modak | ef37027 | 2008-04-14 13:55:47 +0000 | [diff] [blame] | 195 | fds[5] = AT_FDCWD; |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 196 | |
| 197 | filenames[0] = filenames[2] = filenames[3] = filenames[4] = testfile; |
| 198 | filenames[1] = testfile2; |
subrata_modak | bbaeb93 | 2008-03-27 12:01:59 +0000 | [diff] [blame] | 199 | filenames[5] = testfile3; |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /*************************************************************** |
| 203 | * setup() - performs all ONE TIME setup for this test. |
| 204 | ***************************************************************/ |
| 205 | void setup() |
| 206 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 207 | |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 208 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 209 | |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 210 | TEST_PAUSE; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 211 | } |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 212 | |
| 213 | /*************************************************************** |
| 214 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 215 | * completion or premature exit. |
| 216 | ***************************************************************/ |
| 217 | void cleanup() |
| 218 | { |
| 219 | /* Remove them */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 220 | close(fd); |
vapier | 073ad12 | 2006-09-10 10:06:06 +0000 | [diff] [blame] | 221 | unlink(testfile); |
| 222 | unlink(testfile2); |
| 223 | unlink(testfile3); |
| 224 | rmdir(pathname); |
| 225 | |
| 226 | /* |
| 227 | * print timing stats if that option was specified. |
| 228 | * print errno log if that option was specified. |
| 229 | */ |
| 230 | TEST_CLEANUP; |
| 231 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 232 | } |