plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2001 |
| 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 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 22 | * fcntl21.c |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | * |
| 24 | * DESCRIPTION |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 25 | * Check locking of regions of a file |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 26 | * |
| 27 | * ALGORITHM |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 28 | * Test changing lock sections around a read lock |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 29 | * |
| 30 | * USAGE |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 31 | * fcntl21 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 32 | * |
| 33 | * HISTORY |
| 34 | * 07/2001 Ported by Wayne Boyer |
| 35 | * |
| 36 | * RESTRICTIONS |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 37 | * None |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | */ |
| 39 | |
| 40 | #include <fcntl.h> |
| 41 | #include <errno.h> |
| 42 | #include <signal.h> |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 43 | #include <sys/types.h> |
| 44 | #include <sys/stat.h> |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 45 | #include <sys/wait.h> |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 46 | #include <inttypes.h> |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 47 | #include "test.h" |
| 48 | #include "usctest.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 49 | |
| 50 | #define STRINGSIZE 27 |
| 51 | #define STRING "abcdefghijklmnopqrstuvwxyz\n" |
| 52 | #define STOP 0xFFF0 |
| 53 | |
| 54 | int parent_pipe[2]; |
| 55 | int child_pipe[2]; |
| 56 | int fd; |
plars | a1e518d | 2002-09-09 18:23:52 +0000 | [diff] [blame] | 57 | pid_t parent_pid, child_pid; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | |
| 59 | void parent_put(); |
| 60 | void parent_get(); |
| 61 | void child_put(); |
| 62 | void child_get(); |
| 63 | void stop_child(); |
plars | a1e518d | 2002-09-09 18:23:52 +0000 | [diff] [blame] | 64 | void compare_lock(struct flock *, short, short, int, int, pid_t); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | void unlock_file(); |
| 66 | void do_test(struct flock *, short, short, int, int); |
| 67 | void catch_child(); |
| 68 | char *str_type(); |
| 69 | int do_lock(int, short, short, int, int); |
| 70 | |
nstraz | fa31d55 | 2002-05-14 16:50:06 +0000 | [diff] [blame] | 71 | char *TCID = "fcntl21"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | |
| 74 | void setup(void); |
| 75 | void cleanup(void); |
| 76 | int fail; |
| 77 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | /* |
| 79 | * setup |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 80 | * performs all ONE TIME setup for this test |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 82 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | { |
| 84 | char *buf = STRING; |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 85 | char template[PATH_MAX]; |
robbiew | 1e4cf0c | 2005-02-24 17:03:42 +0000 | [diff] [blame] | 86 | struct sigaction act; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 89 | |
| 90 | umask(0); |
| 91 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | TEST_PAUSE; |
| 93 | |
| 94 | pipe(parent_pipe); |
| 95 | pipe(child_pipe); |
| 96 | parent_pid = getpid(); |
robbiew | 54f7a71 | 2003-04-16 19:20:30 +0000 | [diff] [blame] | 97 | |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 98 | tst_tmpdir(); |
robbiew | 54f7a71 | 2003-04-16 19:20:30 +0000 | [diff] [blame] | 99 | |
| 100 | snprintf(template, PATH_MAX, "fcntl21XXXXXX"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 102 | if ((fd = mkstemp(template)) < 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 103 | tst_resm(TFAIL, "Couldn't open temp file! errno = %d", errno); |
| 104 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 106 | if (write(fd, buf, STRINGSIZE) < 0) { |
| 107 | tst_resm(TFAIL, "Couldn't write to temp file! errno = %d", |
| 108 | errno); |
| 109 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | |
robbiew | 1e4cf0c | 2005-02-24 17:03:42 +0000 | [diff] [blame] | 111 | memset(&act, 0, sizeof(act)); |
| 112 | act.sa_handler = catch_child; |
| 113 | sigemptyset(&act.sa_mask); |
| 114 | sigaddset(&act.sa_mask, SIGCLD); |
| 115 | if ((sigaction(SIGCLD, &act, NULL)) < 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 116 | tst_resm(TFAIL, "SIGCLD signal setup failed, errno: %d", errno); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 117 | fail = 1; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * cleanup() |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 123 | * performs all ONE TIME cleanup for this test at completion or |
| 124 | * premature exit |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 125 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 126 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 127 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 128 | |
robbiew | 54f7a71 | 2003-04-16 19:20:30 +0000 | [diff] [blame] | 129 | tst_rmdir(); |
| 130 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 133 | void do_child(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 134 | { |
| 135 | struct flock fl; |
| 136 | |
| 137 | close(parent_pipe[1]); |
| 138 | close(child_pipe[0]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | while (1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 140 | child_get(&fl); |
| 141 | if (fcntl(fd, F_GETLK, &fl) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 142 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 143 | errno); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 144 | fail = 1; |
| 145 | } |
| 146 | child_put(&fl); |
| 147 | } |
| 148 | } |
| 149 | |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 150 | int do_lock(int cmd, short type, short whence, int start, int len) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 151 | { |
| 152 | struct flock fl; |
| 153 | |
| 154 | fl.l_type = type; |
| 155 | fl.l_whence = whence; |
| 156 | fl.l_start = start; |
| 157 | fl.l_len = len; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 158 | return (fcntl(fd, cmd, &fl)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 159 | } |
| 160 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 161 | void do_test(struct flock *fl, short type, short whence, int start, int len) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 162 | { |
| 163 | fl->l_type = type; |
| 164 | fl->l_whence = whence; |
| 165 | fl->l_start = start; |
| 166 | fl->l_len = len; |
| 167 | fl->l_pid = (short)0; |
| 168 | |
| 169 | parent_put(fl); |
| 170 | parent_get(fl); |
| 171 | } |
| 172 | |
| 173 | void |
| 174 | compare_lock(struct flock *fl, short type, short whence, int start, int len, |
plars | a1e518d | 2002-09-09 18:23:52 +0000 | [diff] [blame] | 175 | pid_t pid) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 176 | { |
| 177 | if (fl->l_type != type) { |
| 178 | tst_resm(TFAIL, "lock type is wrong should be %s is %s", |
| 179 | str_type(type), str_type(fl->l_type)); |
| 180 | fail = 1; |
| 181 | } |
| 182 | |
| 183 | if (fl->l_whence != whence) { |
| 184 | tst_resm(TFAIL, "lock whence is wrong should be %d is %d", |
| 185 | whence, fl->l_whence); |
| 186 | fail = 1; |
| 187 | } |
| 188 | |
| 189 | if (fl->l_start != start) { |
| 190 | tst_resm(TFAIL, "region starts in wrong place, should be" |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 191 | "%d is %" PRId64, start, (int64_t) fl->l_start); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 192 | fail = 1; |
| 193 | } |
| 194 | |
| 195 | if (fl->l_len != len) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 196 | tst_resm(TFAIL, |
| 197 | "region length is wrong, should be %d is %" PRId64, |
| 198 | len, (int64_t) fl->l_len); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 199 | fail = 1; |
| 200 | } |
| 201 | |
| 202 | if (fl->l_pid != pid) { |
| 203 | tst_resm(TFAIL, "locking pid is wrong, should be %d is %d", |
| 204 | pid, fl->l_pid); |
| 205 | fail = 1; |
| 206 | } |
| 207 | } |
| 208 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 209 | void unlock_file(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 210 | { |
| 211 | struct flock fl; |
| 212 | |
| 213 | if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 0, 0) < 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 214 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", errno); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 215 | fail = 1; |
| 216 | } |
| 217 | do_test(&fl, F_WRLCK, 0, 0, 0); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 218 | compare_lock(&fl, (short)F_UNLCK, (short)0, 0, 0, (pid_t) 0); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 219 | } |
| 220 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 221 | char *str_type(int type) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 222 | { |
| 223 | static char buf[20]; |
| 224 | |
| 225 | switch (type) { |
| 226 | case 1: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 227 | return ("F_RDLCK"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 228 | case 2: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 229 | return ("F_WRLCK"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 230 | case 3: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 231 | return ("F_UNLCK"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 232 | default: |
| 233 | sprintf(buf, "BAD VALUE: %d", type); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 234 | return (buf); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 238 | void parent_put(struct flock *l) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 239 | { |
| 240 | if (write(parent_pipe[1], l, sizeof(*l)) != sizeof(*l)) { |
| 241 | tst_resm(TFAIL, "couldn't send message to child"); |
| 242 | fail = 1; |
| 243 | } |
| 244 | } |
| 245 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 246 | void parent_get(struct flock *l) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 247 | { |
| 248 | if (read(child_pipe[0], l, sizeof(*l)) != sizeof(*l)) { |
| 249 | tst_resm(TFAIL, "couldn't get message from child"); |
| 250 | fail = 1; |
| 251 | } |
| 252 | } |
| 253 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 254 | void child_put(struct flock *l) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 255 | { |
| 256 | if (write(child_pipe[1], l, sizeof(*l)) != sizeof(*l)) { |
| 257 | tst_resm(TFAIL, "couldn't send message to parent"); |
| 258 | fail = 1; |
| 259 | } |
| 260 | } |
| 261 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 262 | void child_get(struct flock *l) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 263 | { |
| 264 | if (read(parent_pipe[0], l, sizeof(*l)) != sizeof(*l)) { |
| 265 | tst_resm(TFAIL, "couldn't get message from parent"); |
| 266 | cleanup(); |
| 267 | } else if (l->l_type == (short)STOP) { |
| 268 | exit(0); |
| 269 | } |
| 270 | } |
| 271 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 272 | void stop_child(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 273 | { |
| 274 | struct flock fl; |
| 275 | |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 276 | signal(SIGCLD, SIG_DFL); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 277 | fl.l_type = STOP; |
| 278 | parent_put(&fl); |
| 279 | wait(0); |
| 280 | } |
| 281 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 282 | void catch_child(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 283 | { |
| 284 | tst_resm(TFAIL, "Unexpected death of child process"); |
| 285 | cleanup(); |
| 286 | } |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 287 | |
| 288 | int main(int ac, char **av) |
| 289 | { |
| 290 | struct flock tl; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 291 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 292 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 293 | const char *msg; |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 294 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 295 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 296 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 297 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 298 | #ifdef UCLINUX |
| 299 | maybe_run_child(&do_child, "ddddd", &parent_pipe[0], &parent_pipe[1], |
| 300 | &child_pipe[0], &child_pipe[1], &fd); |
| 301 | #endif |
| 302 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 303 | setup(); /* global setup */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 304 | |
| 305 | /* Check for looping state if -i option is given */ |
| 306 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 307 | /* reset tst_count in case we are looping */ |
| 308 | tst_count = 0; |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 309 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 310 | if ((child_pid = FORK_OR_VFORK()) == 0) { |
| 311 | #ifdef UCLINUX |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 312 | if (self_exec |
| 313 | (av[0], "ddddd", parent_pipe[0], parent_pipe[1], |
| 314 | child_pipe[0], child_pipe[1], fd) < 0) { |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 315 | tst_resm(TFAIL, "self_exec failed"); |
| 316 | cleanup(); |
| 317 | } |
| 318 | #else |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 319 | do_child(); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 320 | #endif |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 321 | } |
| 322 | if (child_pid < 0) { |
| 323 | tst_resm(TFAIL, "Fork failed"); |
| 324 | cleanup(); |
| 325 | } |
| 326 | |
| 327 | (void)close(parent_pipe[0]); |
| 328 | (void)close(child_pipe[1]); |
| 329 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 330 | /* //block1: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 331 | tst_resm(TINFO, "Enter block 1"); |
| 332 | fail = 0; |
| 333 | /* |
| 334 | * Set a read lock on the whole file |
| 335 | */ |
| 336 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 0, 0) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 337 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 338 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 339 | fail = 1; |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | * Test to make sure it's there. |
| 344 | */ |
| 345 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 346 | compare_lock(&tl, (short)F_RDLCK, (short)0, 0, 0, parent_pid); |
| 347 | |
| 348 | /* |
| 349 | * remove the lock set above |
| 350 | */ |
| 351 | unlock_file(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 352 | |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 353 | if (fail) { |
| 354 | tst_resm(TINFO, "Test block 1: FAILED"); |
| 355 | } else { |
| 356 | tst_resm(TINFO, "Test block 1: PASSED"); |
| 357 | } |
| 358 | tst_resm(TINFO, "Exit block 1"); |
| 359 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 360 | /* //block2: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 361 | tst_resm(TINFO, "Enter block 2"); |
| 362 | fail = 0; |
| 363 | |
| 364 | /* |
| 365 | * Set a write lock on the whole file |
| 366 | */ |
| 367 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 0, 0) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 368 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 369 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 370 | fail = 1; |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * Test to make sure its there |
| 375 | */ |
| 376 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 377 | compare_lock(&tl, (short)F_WRLCK, (short)0, 0, 0, parent_pid); |
| 378 | |
| 379 | /* |
| 380 | * remove the lock set above |
| 381 | */ |
| 382 | unlock_file(); |
| 383 | |
| 384 | if (fail) { |
| 385 | tst_resm(TINFO, "Test block 2: FAILED"); |
| 386 | } else { |
| 387 | tst_resm(TINFO, "Test block 2: PASSED"); |
| 388 | } |
| 389 | |
| 390 | tst_resm(TINFO, "Exit block 2"); |
| 391 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 392 | /* //block3: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 393 | tst_resm(TINFO, "Enter block 3"); |
| 394 | fail = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 395 | |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 396 | /* |
| 397 | * Add a read lock to the middle of the file and a write |
| 398 | * at the begining |
| 399 | */ |
| 400 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 401 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 402 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 403 | fail = 1; |
| 404 | } |
| 405 | |
| 406 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 1, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 407 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 408 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 409 | fail = 1; |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | * Test write lock |
| 414 | */ |
| 415 | do_test(&tl, F_WRLCK, 0, 0, 0); |
| 416 | compare_lock(&tl, (short)F_WRLCK, (short)0, 1, 5, parent_pid); |
| 417 | |
| 418 | /* |
| 419 | * Test read lock |
| 420 | */ |
| 421 | do_test(&tl, F_WRLCK, 0, 6, 0); |
| 422 | compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 5, parent_pid); |
| 423 | |
| 424 | /* |
| 425 | * Test that the rest of the file is unlocked |
| 426 | */ |
| 427 | do_test(&tl, F_WRLCK, 0, 15, 0); |
| 428 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0); |
| 429 | |
| 430 | /* |
| 431 | * remove all the locks set above |
| 432 | */ |
| 433 | unlock_file(); |
| 434 | |
| 435 | if (fail) { |
| 436 | tst_resm(TINFO, "Test block 3: FAILED"); |
| 437 | } else { |
| 438 | tst_resm(TINFO, "Test block 3 : PASSED"); |
| 439 | } |
| 440 | tst_resm(TINFO, "Exit block 3"); |
| 441 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 442 | /* //block4: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 443 | tst_resm(TINFO, "Enter block 4"); |
| 444 | fail = 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 445 | |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 446 | /* |
| 447 | * Set a read lock at the middle of the file and a |
| 448 | * write lock just before |
| 449 | */ |
| 450 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 451 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 452 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 453 | fail = 1; |
| 454 | } |
| 455 | |
| 456 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 5, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 457 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 458 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 459 | fail = 1; |
| 460 | } |
| 461 | |
| 462 | /* |
| 463 | * Test the write lock |
| 464 | */ |
| 465 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 466 | compare_lock(&tl, (short)F_WRLCK, (short)0, 5, 5, parent_pid); |
| 467 | |
| 468 | /* |
| 469 | * Test the read lock. |
| 470 | */ |
| 471 | do_test(&tl, (short)F_WRLCK, (short)0, 10, 0); |
| 472 | compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 5, parent_pid); |
| 473 | |
| 474 | /* |
| 475 | * Test to make sure the rest of the file is unlocked. |
| 476 | */ |
| 477 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 0); |
| 478 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0); |
| 479 | |
| 480 | /* |
| 481 | * remove all the locks set above |
| 482 | */ |
| 483 | unlock_file(); |
| 484 | |
| 485 | if (fail) { |
| 486 | tst_resm(TINFO, "Test block 4: FAILED"); |
| 487 | } else { |
| 488 | tst_resm(TINFO, "Test block 4: PASSED"); |
| 489 | } |
| 490 | tst_resm(TINFO, "Exit block 4"); |
| 491 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 492 | /* //block5: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 493 | tst_resm(TINFO, "Enter block 5"); |
| 494 | fail = 0; |
| 495 | |
| 496 | /* |
| 497 | * Set a read lock in the middle and a write lock that |
| 498 | * ends at the first byte of the read lock |
| 499 | */ |
| 500 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 501 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 502 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 503 | fail = 1; |
| 504 | } |
| 505 | |
| 506 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 5, 6) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 507 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 508 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 509 | fail = 1; |
| 510 | } |
| 511 | |
| 512 | /* |
| 513 | * Test write lock |
| 514 | */ |
| 515 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 516 | compare_lock(&tl, (short)F_WRLCK, (short)0, 5, 6, parent_pid); |
| 517 | |
| 518 | /* |
| 519 | * Test read lock |
| 520 | */ |
| 521 | do_test(&tl, (short)F_WRLCK, (short)0, 11, 0); |
| 522 | compare_lock(&tl, (short)F_RDLCK, (short)0, 11, 4, parent_pid); |
| 523 | |
| 524 | /* |
| 525 | * Test to make sure the rest of the file is unlocked. |
| 526 | */ |
| 527 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 0); |
| 528 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0); |
| 529 | |
| 530 | /* |
| 531 | * remove all the locks set above |
| 532 | */ |
| 533 | unlock_file(); |
| 534 | |
| 535 | if (fail) { |
| 536 | tst_resm(TINFO, "Test block 5: FAILED"); |
| 537 | } else { |
| 538 | tst_resm(TINFO, "Test block 5: PASSED"); |
| 539 | } |
| 540 | tst_resm(TINFO, "Exit block 5"); |
| 541 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 542 | /* //block6: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 543 | tst_resm(TINFO, "Enter block 6"); |
| 544 | fail = 0; |
| 545 | |
| 546 | /* |
| 547 | * Set a read lock on the middle of the file and a write |
| 548 | * lock that overlaps the front of the read. |
| 549 | */ |
| 550 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 551 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 552 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 553 | fail = 1; |
| 554 | } |
| 555 | |
| 556 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 5, 8) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 557 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 558 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 559 | fail = 1; |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * Test the write lock |
| 564 | */ |
| 565 | do_test(&tl, (short)F_WRLCK, (short)0, 5, 0); |
| 566 | compare_lock(&tl, (short)F_WRLCK, (short)0, 5, 8, parent_pid); |
| 567 | |
| 568 | /* |
| 569 | * Test the read lock |
| 570 | */ |
| 571 | do_test(&tl, (short)F_WRLCK, (short)0, 13, 0); |
| 572 | compare_lock(&tl, (short)F_RDLCK, (short)0, 13, 2, parent_pid); |
| 573 | |
| 574 | /* |
| 575 | * Test to make sure the rest of the file is unlocked. |
| 576 | */ |
| 577 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 0); |
| 578 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0); |
| 579 | |
| 580 | /* |
| 581 | * remove all the locks set above |
| 582 | */ |
| 583 | unlock_file(); |
| 584 | |
| 585 | if (fail) { |
| 586 | tst_resm(TINFO, "Test block 6 FAILED"); |
| 587 | } else { |
| 588 | tst_resm(TINFO, "Test block 6 PASSED"); |
| 589 | } |
| 590 | tst_resm(TINFO, "Exit block 6"); |
| 591 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 592 | /* //block7: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 593 | tst_resm(TINFO, "Enter block 7"); |
| 594 | fail = 0; |
| 595 | |
| 596 | /* |
| 597 | * Set a read lock in the middle of a file and a write |
| 598 | * lock in the middle of it |
| 599 | */ |
| 600 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 10) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 601 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 602 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 603 | fail = 1; |
| 604 | } |
| 605 | |
| 606 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 13, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 607 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 608 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 609 | fail = 1; |
| 610 | } |
| 611 | |
| 612 | /* |
| 613 | * Test the first read lock |
| 614 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 615 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 616 | compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 3, parent_pid); |
| 617 | |
| 618 | /* |
| 619 | * Test the write lock |
| 620 | */ |
| 621 | do_test(&tl, (short)F_WRLCK, (short)0, 13, 0); |
| 622 | compare_lock(&tl, (short)F_WRLCK, (short)0, 13, 5, parent_pid); |
| 623 | |
| 624 | /* |
| 625 | * Test the second read lock |
| 626 | */ |
| 627 | do_test(&tl, (short)F_WRLCK, (short)0, 18, 0); |
| 628 | compare_lock(&tl, (short)F_RDLCK, (short)0, 18, 2, parent_pid); |
| 629 | |
| 630 | /* |
| 631 | * Test to make sure the rest of the file is unlocked |
| 632 | */ |
| 633 | do_test(&tl, (short)F_WRLCK, (short)0, 20, 0); |
| 634 | compare_lock(&tl, (short)F_UNLCK, (short)0, 20, 0, 0); |
| 635 | |
| 636 | /* |
| 637 | * remove all the locks set above. |
| 638 | */ |
| 639 | unlock_file(); |
| 640 | if (fail) { |
| 641 | tst_resm(TINFO, "Test block 7: FAILED"); |
| 642 | } else { |
| 643 | tst_resm(TINFO, "Test block 7: PASSED"); |
| 644 | } |
| 645 | tst_resm(TINFO, "Exit block 7"); |
| 646 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 647 | /* //block8: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 648 | tst_resm(TINFO, "Enter block 8"); |
| 649 | fail = 0; |
| 650 | /* |
| 651 | * Set a read lock in the middle of the file and a write |
| 652 | * lock that overlaps the end |
| 653 | */ |
| 654 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 655 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 656 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 657 | fail = 1; |
| 658 | } |
| 659 | |
| 660 | /* |
| 661 | * Set a write lock on the whole file |
| 662 | */ |
| 663 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 13, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 664 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 665 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 666 | fail = 1; |
| 667 | } |
| 668 | |
| 669 | /* |
| 670 | * Test the read lock |
| 671 | */ |
| 672 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 673 | compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 3, parent_pid); |
| 674 | |
| 675 | /* |
| 676 | * Test the write lock |
| 677 | */ |
| 678 | do_test(&tl, (short)F_WRLCK, (short)0, 13, 0); |
| 679 | compare_lock(&tl, (short)F_WRLCK, (short)0, 13, 5, parent_pid); |
| 680 | |
| 681 | /* |
| 682 | * Test to make sure the rest of the file is unlocked |
| 683 | */ |
| 684 | do_test(&tl, (short)F_WRLCK, (short)0, 18, 0); |
| 685 | compare_lock(&tl, (short)F_UNLCK, (short)0, 18, 0, 0); |
| 686 | |
| 687 | /* |
| 688 | * remove all the locks set above |
| 689 | */ |
| 690 | unlock_file(); |
| 691 | |
| 692 | if (fail) { |
| 693 | tst_resm(TINFO, "Test block 8: FAILED"); |
| 694 | } else { |
| 695 | tst_resm(TINFO, "Test block 8: PASSED"); |
| 696 | } |
| 697 | tst_resm(TINFO, "Exit block 8"); |
| 698 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 699 | /* //block9: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 700 | tst_resm(TINFO, "Enter block 9"); |
| 701 | fail = 0; |
| 702 | |
| 703 | /* |
| 704 | * Set a read lock in the middle of the file and a write |
| 705 | * lock starting at the last byte of the read lock |
| 706 | */ |
| 707 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 708 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 709 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 710 | fail = 1; |
| 711 | } |
| 712 | |
| 713 | /* |
| 714 | * Set a write lock on the whole file. |
| 715 | */ |
| 716 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 14, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 717 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 718 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 719 | fail = 1; |
| 720 | } |
| 721 | |
| 722 | /* |
| 723 | * Test read lock |
| 724 | */ |
| 725 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 726 | compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 4, parent_pid); |
| 727 | |
| 728 | /* |
| 729 | * Test the write lock |
| 730 | */ |
| 731 | do_test(&tl, (short)F_WRLCK, (short)0, 14, 0); |
| 732 | compare_lock(&tl, (short)F_WRLCK, (short)0, 14, 5, parent_pid); |
| 733 | |
| 734 | /* |
| 735 | * Test to make sure the end of the file is unlocked |
| 736 | */ |
| 737 | do_test(&tl, (short)F_WRLCK, (short)0, 19, 0); |
| 738 | compare_lock(&tl, (short)F_UNLCK, (short)0, 19, 0, 0); |
| 739 | |
| 740 | /* |
| 741 | * remove all the locks set above |
| 742 | */ |
| 743 | unlock_file(); |
| 744 | |
| 745 | if (fail) { |
| 746 | tst_resm(TINFO, "Test block 9: FAILED"); |
| 747 | } else { |
| 748 | tst_resm(TINFO, "Test block 9: PASSED"); |
| 749 | } |
| 750 | tst_resm(TINFO, "Exit block 9"); |
| 751 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 752 | /* //block10: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 753 | tst_resm(TINFO, "Enter block 10"); |
| 754 | fail = 0; |
| 755 | |
| 756 | /* |
| 757 | * Set a read lock in the middle of the file and a write |
| 758 | * lock that starts just after the last byte of the |
| 759 | * read lock. |
| 760 | */ |
| 761 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 762 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 763 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 764 | fail = 1; |
| 765 | } |
| 766 | |
| 767 | /* |
| 768 | * Set a write lock on the whole file |
| 769 | */ |
| 770 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 15, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 771 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 772 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 773 | fail = 1; |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Test the read lock |
| 778 | */ |
| 779 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 780 | compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 5, parent_pid); |
| 781 | |
| 782 | /* |
| 783 | * Test the write lock |
| 784 | */ |
| 785 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 0); |
| 786 | compare_lock(&tl, (short)F_WRLCK, (short)0, 15, 5, parent_pid); |
| 787 | |
| 788 | /* |
| 789 | * Test to make sure the rest of the file is unlocked |
| 790 | */ |
| 791 | do_test(&tl, (short)F_WRLCK, (short)0, 20, 0); |
| 792 | compare_lock(&tl, (short)F_UNLCK, (short)0, 20, 0, 0); |
| 793 | |
| 794 | /* |
| 795 | * remove all the locks set above |
| 796 | */ |
| 797 | unlock_file(); |
| 798 | |
| 799 | if (fail) { |
| 800 | tst_resm(TINFO, "Test block 10: FAILED"); |
| 801 | } else { |
| 802 | tst_resm(TINFO, "Test block 10: PASSED"); |
| 803 | } |
| 804 | tst_resm(TINFO, "Exit block 10"); |
| 805 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 806 | /* //block11: */ |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 807 | tst_resm(TINFO, "Enter block 11"); |
| 808 | fail = 0; |
| 809 | |
| 810 | /* |
| 811 | * Set a read lock at the middle of the file and a write |
| 812 | * lock that starts past the end of the read lock. |
| 813 | */ |
| 814 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 815 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 816 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 817 | fail = 1; |
| 818 | } |
| 819 | |
| 820 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 16, 5) < 0) { |
robbiew | dad2271 | 2003-04-16 19:14:05 +0000 | [diff] [blame] | 821 | tst_resm(TFAIL, "fcntl on file failed, errno =%d", |
| 822 | errno); |
robbiew | 5aab8a7 | 2003-03-26 18:05:30 +0000 | [diff] [blame] | 823 | fail = 1; |
| 824 | } |
| 825 | |
| 826 | /* |
| 827 | * Test the read lock |
| 828 | */ |
| 829 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 830 | compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 5, parent_pid); |
| 831 | |
| 832 | /* |
| 833 | * Test that byte in between is unlocked |
| 834 | */ |
| 835 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 1); |
| 836 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 1, 0); |
| 837 | |
| 838 | /* |
| 839 | * Test the write lock |
| 840 | */ |
| 841 | do_test(&tl, (short)F_WRLCK, (short)0, 16, 0); |
| 842 | compare_lock(&tl, (short)F_WRLCK, (short)0, 16, 5, parent_pid); |
| 843 | |
| 844 | /* |
| 845 | * Test to make sure the rest of the file is unlocked |
| 846 | */ |
| 847 | do_test(&tl, (short)F_WRLCK, (short)0, 21, 0); |
| 848 | compare_lock(&tl, (short)F_UNLCK, (short)0, 21, 0, 0); |
| 849 | |
| 850 | /* |
| 851 | * remove all the locks set above |
| 852 | */ |
| 853 | unlock_file(); |
| 854 | |
| 855 | if (fail) { |
| 856 | tst_resm(TINFO, "Test block 11: FAILED"); |
| 857 | } else { |
| 858 | tst_resm(TINFO, "Test block 11: PASSED"); |
| 859 | } |
| 860 | tst_resm(TINFO, "Exit block 11"); |
| 861 | |
| 862 | stop_child(); |
| 863 | close(fd); |
| 864 | } |
| 865 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 866 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 867 | } |