1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
4 * Copyright (c) 2019 Intel Corp.
9 * Synchronized byte range lock and lease exerciser
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <netinet/tcp.h>
24 #include <sys/types.h>
32 #define HEX_2_ASC(x) ((x) > 9) ? (x)-10+'a' : (x)+'0'
33 #define FILE_SIZE 1024
34 #define PLATFORM_INIT() /*no-op*/
35 #define PLATFORM_CLEANUP() /*no-op*/
40 #define inet_aton(STRING, INADDRP) \
41 (((INADDRP)->s_addr = inet_addr(STRING)) == -1 ? 0 : 1)
43 /* this assumes 32 bit pointers */
44 #define PTR_TO_U64(P) ((unsigned __int64)(unsigned int)(P))
45 #define U64_TO_PTR(T,U) ((T)(void *)(unsigned int)(U))
47 #if __BYTE_ORDER == __LITTLE_ENDIAN
48 #define bswap_uint16(x) (uint16_t)bswap_16(x)
49 #define bswap_uint32(x) (uint32_t)bswap_32(x)
50 #define bswap_uint64(x) (uint64_t)bswap_64(x)
52 #define bswap_uint16(x) x
53 #define bswap_uint32(x) x
54 #define bswap_uint64(x) x
58 #define SOCKET_READ read
59 #define SOCKET_WRITE write
60 #define SOCKET_CLOSE(S) (close(S))
61 #define INVALID_SOCKET -1
66 #define INVALID_HANDLE -1
67 #define SEEK(H, O) (lseek(H, O, SEEK_SET))
68 #define READ(H, B, L) (read(H, B, L))
69 #define WRITE(H, B, L) (write(H, B, L))
70 #define CLOSE(H) (close(H))
72 #define RAND() (rand())
73 #define SRAND(s) (srand(s))
75 #define MIN(A,B) (((A)<(B))?(A):(B))
76 #define MAX(A,B) (((A)>(B))?(A):(B))
78 #define ALLOC_ALIGNED(S) (memalign(65536, S))
79 #define FREE_ALIGNED(P) (free(P))
82 static char *filename = 0;
84 static int server = 1;
86 static int testnumber = -1;
87 static int saved_errno = 0;
88 static int got_sigio = 0;
90 static SOCKET s_fd = -1; /* listen socket */
91 static SOCKET c_fd = -1; /* IPC socket */
92 static HANDLE f_fd = INVALID_HANDLE; /* shared file */
101 #define CMD_SETLEASE 7
102 #define CMD_GETLEASE 8
104 #define CMD_WAIT_SIGIO 10
118 #define FLAGS 2 /* index 2 is also used for do_open() flag, see below */
119 #define ARG FLAGS /* Arguments for Lease operations */
120 #define TIME FLAGS /* Time for waiting on sigio */
122 static char *get_cmd_str(int cmd)
125 case CMD_WRLOCK: return "write lock"; break;
126 case CMD_RDLOCK: return "read lock"; break;
127 case CMD_UNLOCK: return "unlock"; break;
128 case CMD_CLOSE: return "close"; break;
129 case CMD_OPEN: return "open"; break;
130 case CMD_WRTEST: return "Wait for SIGIO"; break;
131 case CMD_RDTEST: return "Truncate"; break;
132 case CMD_SETLEASE: return "Set Lease"; break;
133 case CMD_GETLEASE: return "Get Lease"; break;
134 case CMD_SIGIO: return "Setup SIGIO"; break;
135 case CMD_WAIT_SIGIO: return "Wait for SIGIO"; break;
140 * flags for Mac OS X do_open()
157 * When adding tests be sure to add to both the descriptions AND tests array.
158 * Also, be sure to undo whatever is set for each test (eg unlock any locks)
159 * There is no need to have a matching client command for each server command
163 char *lock_descriptions[] = {
164 /* 1 */"Add a lock to an empty lock list",
165 /* 2 */"Add a lock to the start and end of a list - no overlaps",
166 /* 3 */"Add a lock to the middle of a list - no overlap",
167 /* 4 */"Add different lock types to middle of the list - overlap exact match",
168 /* 5 */"Add new lock which completely overlaps any old lock in the list",
169 /* 6 */"Add new lock which itself is completely overlaped by any old lock in the list",
170 /* 7 */"Add new lock which starts before any old lock in the list",
171 /* 8 */"Add new lock which starts in the middle of any old lock in the list and ends after",
172 /* 9 */"Add different new lock types which completely overlaps any old lock in the list",
173 /* 10 */"Add different new locks which are completely overlaped by an old lock in the list",
174 /* 11 */"Add different new lock types which start before the old lock in the list",
175 /* 12 */"Add different new lock types which start in the middle of an old lock in the list and end after",
176 /* 13 */"Add new lock, differing types and processes, to middle of the list - exact overlap match",
177 /* 14 */"Add new lock, differing types and processes, which completely overlap any of the locks in the list",
178 /* 15 */"Add new lock, differing types and processes, which are completely overlaped by locks in the list",
179 /* 16 */"Add new lock, differing types and processes, which start before a lock in the list",
180 /* 17 */"Add new lock, differing types and processes, which starts in the middle of a lock, and ends after",
181 /* 18 */"Acquire write locks with overlapping ranges",
182 /* 19 */"Acquire write locks with non-overlapping ranges extending beyond EOF",
183 /* 20 */"Acquire write locks with overlapping ranges extending beyond EOF",
184 /* 21 */"Acquire write locks on whole files",
185 /* 22 */"Acquire write lock on whole file and range write lock",
186 /* 23 */"Acquire read locks with non-overlapping ranges",
187 /* 24 */"Acquire read locks with overlapping ranges",
188 /* 25 */"Acquire read and write locks with no overlapping ranges",
189 /* 26 */"Acquire read and write locks with overlapping ranges",
190 /* 27 */"Acquire whole file write lock and then close without unlocking (and attempt a lock)",
191 /* 28 */"Acquire two read locks, close and reopen the file, and test if the inital lock is still there",
192 /* 29 */"Verify that F_GETLK for F_WRLCK doesn't require that file be opened for write",
194 /* 30 */"Close the opened file and open the file with SHLOCK, other client will try to open with SHLOCK too",
195 /* 31 */"Close the opened file and open the file with SHLOCK, other client will try to open with EXLOCK",
196 /* 32 */"Close the opened file and open the file with EXLOCK, other client will try to open with EXLOCK too"
200 static int64_t lock_tests[][6] =
201 /* test # Action [offset|flags] length expected server/client */
203 /* Various simple tests exercising the list */
205 /* SECTION 1: WRITE and CMD_UNLOCK with the same process (SERVER) */
206 /* Add a lock to an empty list */
207 {1, CMD_WRLOCK, 1, 10, PASS, SERVER },
208 {1, CMD_UNLOCK, 1, 10, PASS, SERVER },
210 /* Add a lock to the start and end of a list - 1, 13 - no overlap */
211 {2, CMD_WRLOCK, 10, 10, PASS, SERVER },
212 {2, CMD_WRLOCK, 30, 10, PASS, SERVER },
213 {2, CMD_WRLOCK, 50, 10, PASS, SERVER },
214 {2, CMD_WRLOCK, 1, 5, PASS, SERVER },
215 {2, CMD_WRLOCK, 70, 5, PASS, SERVER },
217 {2, CMD_UNLOCK, 10, 10, PASS, SERVER },
218 {2, CMD_UNLOCK, 30, 10, PASS, SERVER },
219 {2, CMD_UNLOCK, 50, 10, PASS, SERVER },
220 {2, CMD_UNLOCK, 1, 5, PASS, SERVER },
221 {2, CMD_UNLOCK, 70, 5, PASS, SERVER },
223 /* Add a lock to the middle of a list - no overlap */
224 {3, CMD_WRLOCK, 10, 10, PASS, SERVER },
225 {3, CMD_WRLOCK, 30, 10, PASS, SERVER },
226 {3, CMD_WRLOCK, 50, 10, PASS, SERVER },
227 {3, CMD_WRLOCK, 42, 5, PASS, SERVER },
229 {3, CMD_UNLOCK, 10, 10, PASS, SERVER },
230 {3, CMD_UNLOCK, 30, 10, PASS, SERVER },
231 {3, CMD_UNLOCK, 50, 10, PASS, SERVER },
232 {3, CMD_UNLOCK, 42, 5, PASS, SERVER },
234 /* Add different lock types to middle of the list - overlap exact match - 3 */
235 {4, CMD_WRLOCK, 10, 10, PASS, SERVER },
236 {4, CMD_WRLOCK, 30, 10, PASS, SERVER },
237 {4, CMD_WRLOCK, 50, 10, PASS, SERVER },
238 /* Exact match - same lock type */
239 {4, CMD_WRLOCK, 30, 10, PASS, SERVER },
240 /* Exact match - different lock type */
241 {4, CMD_RDLOCK, 30, 10, PASS, SERVER },
242 /* Exact match - unlock */
243 {4, CMD_UNLOCK, 30, 10, PASS, SERVER },
244 /* New lock - as above, inserting in the list again */
245 {4, CMD_WRLOCK, 30, 10, PASS, SERVER },
247 {4, CMD_UNLOCK, 10, 10, PASS, SERVER },
248 {4, CMD_UNLOCK, 30, 10, PASS, SERVER },
249 {4, CMD_UNLOCK, 50, 10, PASS, SERVER },
251 /* Add new lock which completely overlaps any old lock in the list - 4,5,6 */
252 {5, CMD_WRLOCK, 10, 10, PASS, SERVER },
253 {5, CMD_WRLOCK, 30, 10, PASS, SERVER },
254 {5, CMD_WRLOCK, 50, 10, PASS, SERVER },
255 /* The start is the same, end overlaps */
256 {5, CMD_WRLOCK, 30, 15, PASS, SERVER },
257 /* The start is before, end is the same */
258 {5, CMD_WRLOCK, 25, 20, PASS, SERVER },
259 /* Both start and end overlap */
260 {5, CMD_WRLOCK, 22, 26, PASS, SERVER },
262 {5, CMD_UNLOCK, 10, 10, PASS, SERVER },
263 {5, CMD_UNLOCK, 22, 26, PASS, SERVER },
264 {5, CMD_UNLOCK, 50, 10, PASS, SERVER },
266 /* Add new lock which itself is completely overlaped by any old lock in the list - 7,8,10 */
267 {6, CMD_WRLOCK, 10, 10, PASS, SERVER },
268 {6, CMD_WRLOCK, 30, 10, PASS, SERVER },
269 {6, CMD_WRLOCK, 50, 10, PASS, SERVER },
270 /* The start is the same, end is in the middle of old lock - NOP */
271 {6, CMD_WRLOCK, 30, 5, PASS, SERVER },
272 /* The start and end are in the middle of old lock - NOP */
273 {6, CMD_WRLOCK, 32, 6, PASS, SERVER },
274 /* Start in the middle and end is the same - NOP */
275 {6, CMD_WRLOCK, 32, 8, PASS, SERVER },
277 {6, CMD_UNLOCK, 10, 10, PASS, SERVER },
278 {6, CMD_UNLOCK, 30, 10, PASS, SERVER },
279 {6, CMD_UNLOCK, 32, 8, PASS, SERVER },
280 {6, CMD_UNLOCK, 50, 10, PASS, SERVER },
282 /* Add new lock which starts before any old lock in the list - 2,9 */
283 {7, CMD_WRLOCK, 10, 10, PASS, SERVER },
284 {7, CMD_WRLOCK, 30, 10, PASS, SERVER },
285 {7, CMD_WRLOCK, 50, 10, PASS, SERVER },
286 /* Here is the new lock */
287 {7, CMD_WRLOCK, 27, 10, PASS, SERVER },
288 /* Go again with the end of the new lock matching the start of old lock */
289 {7, CMD_WRLOCK, 25, 2, PASS, SERVER },
291 {7, CMD_UNLOCK, 10, 10, PASS, SERVER },
292 {7, CMD_UNLOCK, 25, 15, PASS, SERVER },
293 {7, CMD_UNLOCK, 50, 10, PASS, SERVER },
295 /* Add new lock which starts in the middle of any old lock in the list and ends after - 11,12 */
296 {8, CMD_WRLOCK, 10, 10, PASS, SERVER },
297 {8, CMD_WRLOCK, 30, 10, PASS, SERVER },
298 {8, CMD_WRLOCK, 50, 10, PASS, SERVER },
299 /* Here is the new lock */
300 {8, CMD_WRLOCK, 35, 10, PASS, SERVER },
301 /* Go again with the end of the new lock matching the start of old lock */
302 {8, CMD_WRLOCK, 45, 2, PASS, SERVER },
304 {8, CMD_UNLOCK, 10, 10, PASS, SERVER },
305 {8, CMD_UNLOCK, 30, 17, PASS, SERVER },
306 {8, CMD_UNLOCK, 50, 10, PASS, SERVER },
307 /* SECTION 2: Overlapping READ and WRITE and CMD_UNLOCK with the same process (SERVER) */
308 /* Add different new lock types which completely overlaps any old lock in the list - 4,5,6 */
309 {9, CMD_WRLOCK, 10, 10, PASS, SERVER },
310 {9, CMD_WRLOCK, 30, 10, PASS, SERVER },
311 {9, CMD_WRLOCK, 50, 10, PASS, SERVER },
312 /* The start is the same, end overlaps */
313 {9, CMD_RDLOCK, 30, 15, PASS, SERVER },
314 /* The start is before, end is the same */
315 {9, CMD_WRLOCK, 25, 20, PASS, SERVER },
316 /* Both start and end overlap */
317 {9, CMD_RDLOCK, 22, 26, PASS, SERVER },
319 {9, CMD_UNLOCK, 10, 10, PASS, SERVER },
320 {9, CMD_UNLOCK, 22, 26, PASS, SERVER },
321 {9, CMD_UNLOCK, 50, 10, PASS, SERVER },
323 /* Add different new locks which are completely overlaped by an old lock in the list - 7,8,10 */
324 {10, CMD_WRLOCK, 10, 10, PASS, SERVER },
325 {10, CMD_WRLOCK, 30, 10, PASS, SERVER },
326 {10, CMD_WRLOCK, 50, 10, PASS, SERVER },
327 /* The start is the same, end is in the middle of old lock */
328 {10, CMD_RDLOCK, 30, 5, PASS, SERVER },
329 /* The start and end are in the middle of a lock */
330 {10, CMD_WRLOCK, 32, 2, PASS, SERVER },
331 /* Start in the middle and end is the same */
332 {10, CMD_RDLOCK, 36, 5, PASS, SERVER },
334 {10, CMD_UNLOCK, 10, 10, PASS, SERVER },
335 {10, CMD_UNLOCK, 30, 11, PASS, SERVER },
336 {10, CMD_UNLOCK, 50, 10, PASS, SERVER },
338 /* Add different new lock types which start before the old lock in the list - 2,9 */
339 {11, CMD_WRLOCK, 10, 10, PASS, SERVER },
340 {11, CMD_WRLOCK, 30, 10, PASS, SERVER },
341 {11, CMD_WRLOCK, 50, 10, PASS, SERVER },
342 /* Here is the new lock */
343 {11, CMD_RDLOCK, 27, 10, PASS, SERVER },
344 /* Go again with the end of the new lock matching the start of lock */
345 {11, CMD_WRLOCK, 25, 3, PASS, SERVER },
347 {11, CMD_UNLOCK, 10, 10, PASS, SERVER },
348 {11, CMD_UNLOCK, 25, 15, PASS, SERVER },
349 {11, CMD_UNLOCK, 50, 10, PASS, SERVER },
351 /* Add different new lock types which start in the middle of an old lock in the list and end after - 11,12 */
352 {12, CMD_WRLOCK, 10, 10, PASS, SERVER },
353 {12, CMD_WRLOCK, 30, 10, PASS, SERVER },
354 {12, CMD_WRLOCK, 50, 10, PASS, SERVER },
355 /* Here is the new lock */
356 {12, CMD_RDLOCK, 35, 10, PASS, SERVER },
357 /* Go again with the end of the new lock matching the start of old lock */
358 {12, CMD_WRLOCK, 44, 3, PASS, SERVER },
360 {12, CMD_UNLOCK, 10, 10, PASS, SERVER },
361 {12, CMD_UNLOCK, 30, 18, PASS, SERVER },
362 {12, CMD_UNLOCK, 50, 10, PASS, SERVER },
364 /* SECTION 3: Overlapping READ and WRITE and CMD_UNLOCK with the different processes (CLIENT/SERVER) */
365 /* Add new lock, differing types and processes, to middle of the list - exact overlap match - 3 */
366 {13, CMD_WRLOCK, 10, 10, PASS, SERVER },
367 {13, CMD_WRLOCK, 30, 10, PASS, SERVER },
368 {13, CMD_RDLOCK, 50, 10, PASS, SERVER },
369 /* Same lock type, different process */
370 {13, CMD_WRLOCK, 30, 10, FAIL, CLIENT },
371 {13, CMD_RDLOCK, 50, 10, PASS, CLIENT },
372 /* Exact match - different lock type, different process */
373 {13, CMD_RDLOCK, 30, 10, FAIL, CLIENT },
374 /* Exact match - unlock */
375 {13, CMD_UNLOCK, 30, 10, PASS, CLIENT },
376 /* New lock - as above, inserting in the list again */
377 {13, CMD_UNLOCK, 30, 10, PASS, SERVER },
378 /* Exact match - same lock type, different process */
379 {13, CMD_WRLOCK, 30, 10, PASS, CLIENT },
381 {13, CMD_UNLOCK, 10, 10, PASS, SERVER },
382 {13, CMD_UNLOCK, 30, 10, PASS, CLIENT },
383 {13, CMD_UNLOCK, 50, 10, PASS, SERVER },
385 /* Add new lock, differing types and processes, which completely overlap any of the locks in the list - 4,5,6 */
386 {14, CMD_WRLOCK, 10, 10, PASS, SERVER },
387 {14, CMD_WRLOCK, 30, 10, PASS, SERVER },
388 {14, CMD_RDLOCK, 50, 10, PASS, SERVER },
389 /* The start is the same, end overlaps */
390 {14, CMD_RDLOCK, 30, 15, FAIL, CLIENT },
391 {14, CMD_WRLOCK, 30, 15, FAIL, CLIENT },
392 /* The start is before, end is the same */
393 {14, CMD_RDLOCK, 25, 20, FAIL, CLIENT },
394 {14, CMD_WRLOCK, 25, 20, FAIL, CLIENT },
395 /* Both start and end overlap */
396 {14, CMD_RDLOCK, 22, 26, FAIL, CLIENT },
397 {14, CMD_WRLOCK, 22, 26, FAIL, CLIENT },
399 /* The start is the same, end overlaps */
400 {14, CMD_RDLOCK, 50, 15, PASS, CLIENT },
401 {14, CMD_WRLOCK, 50, 17, FAIL, CLIENT },
402 /* The start is before, end is the same */
403 {14, CMD_RDLOCK, 45, 20, PASS, CLIENT },
404 {14, CMD_WRLOCK, 43, 22, FAIL, CLIENT },
405 /* Both start and end overlap */
406 {14, CMD_RDLOCK, 42, 26, PASS, CLIENT },
407 {14, CMD_WRLOCK, 41, 28, FAIL, CLIENT },
409 {14, CMD_UNLOCK, 10, 10, PASS, SERVER },
410 {14, CMD_UNLOCK, 22, 26, PASS, SERVER },
411 {14, CMD_UNLOCK, 42, 26, PASS, CLIENT },
413 /* Add new lock, differing types and processes, which are completely overlaped by an old lock in the list - 7,8,10 */
414 {15, CMD_WRLOCK, 10, 10, PASS, SERVER },
415 {15, CMD_RDLOCK, 30, 10, PASS, SERVER },
416 {15, CMD_WRLOCK, 50, 10, PASS, SERVER },
417 /* The start is the same, end is in the middle of old lock */
418 {15, CMD_RDLOCK, 50, 5, FAIL, CLIENT },
419 {15, CMD_WRLOCK, 50, 5, FAIL, CLIENT },
420 /* The start and end are in the middle of old lock */
421 {15, CMD_RDLOCK, 52, 6, FAIL, CLIENT },
422 {15, CMD_WRLOCK, 52, 6, FAIL, CLIENT },
423 /* Start in the middle and end is the same */
424 {15, CMD_RDLOCK, 52, 8, FAIL, CLIENT },
425 {15, CMD_WRLOCK, 52, 8, FAIL, CLIENT },
426 /* The start is the same, end is in the middle of old lock */
427 {15, CMD_RDLOCK, 30, 5, PASS, CLIENT },
428 {15, CMD_WRLOCK, 30, 5, FAIL, CLIENT },
429 /* The start and end are in the middle of old lock */
430 {15, CMD_RDLOCK, 32, 6, PASS, CLIENT },
431 {15, CMD_WRLOCK, 32, 6, FAIL, CLIENT },
432 /* Start in the middle and end is the same */
433 {15, CMD_RDLOCK, 32, 8, PASS, CLIENT },
434 {15, CMD_WRLOCK, 32, 8, FAIL, CLIENT },
436 {15, CMD_UNLOCK, 10, 10, PASS, SERVER },
437 {15, CMD_UNLOCK, 30, 10, PASS, SERVER },
438 {15, CMD_UNLOCK, 50, 10, PASS, SERVER },
439 /* Add new lock, differing types and processes, which start before a lock in the list - 2,9 */
440 {16, CMD_RDLOCK, 10, 10, PASS, SERVER },
441 {16, CMD_WRLOCK, 50, 10, PASS, SERVER },
442 /* Start is before, end is the start of the old lock in list */
443 {16, CMD_RDLOCK, 5, 6, PASS, CLIENT },
444 {16, CMD_WRLOCK, 5, 6, FAIL, CLIENT },
445 /* Start is before, end is in the middle of the old lock */
446 {16, CMD_RDLOCK, 5, 10, PASS, CLIENT },
447 {16, CMD_WRLOCK, 5, 10, FAIL, CLIENT },
448 /* Start is before, end is the start of the old lock in list */
449 {16, CMD_RDLOCK, 45, 6, FAIL, CLIENT },
450 {16, CMD_WRLOCK, 45, 6, FAIL, CLIENT },
451 /* Start is before, end is in the middle of the old lock */
452 {16, CMD_RDLOCK, 45, 10, FAIL, CLIENT },
453 {16, CMD_WRLOCK, 45, 10, FAIL, CLIENT },
455 {16, CMD_UNLOCK, 5, 15, PASS, CLIENT },
456 {16, CMD_UNLOCK, 30, 10, PASS, SERVER },
457 {16, CMD_UNLOCK, 50, 10, PASS, SERVER },
459 /* Add new lock, differing types and processes, which starts in the middle of a lock, and ends after - 11,12 */
460 {17, CMD_WRLOCK, 10, 10, PASS, SERVER },
461 {17, CMD_RDLOCK, 30, 10, PASS, SERVER },
462 {17, CMD_WRLOCK, 50, 10, PASS, SERVER },
463 /* Start in the middle, end after lock in list */
464 {17, CMD_WRLOCK, 35, 10, FAIL, CLIENT },
465 /* Start matches end of lock in list */
466 {17, CMD_RDLOCK, 35, 10, PASS, CLIENT },
467 {17, CMD_RDLOCK, 44, 2, PASS, CLIENT },
468 /* Start in the middle, end after lock in list */
469 {17, CMD_RDLOCK, 55, 10, FAIL, CLIENT },
470 {17, CMD_WRLOCK, 55, 10, FAIL, CLIENT },
471 /* Start matches end of lock in list */
472 {17, CMD_RDLOCK, 59, 5, FAIL, CLIENT },
473 {17, CMD_WRLOCK, 59, 5, FAIL, CLIENT },
475 {17, CMD_UNLOCK, 10, 10, PASS, SERVER },
476 {17, CMD_UNLOCK, 30, 16, PASS, CLIENT },
477 {17, CMD_UNLOCK, 50, 10, PASS, SERVER },
479 /* SECTION 4: overlapping and EOF tests */
480 /* Acquire overlapping ranges */
481 {18, CMD_WRLOCK, 11, 7, PASS, SERVER },
482 {18, CMD_WRLOCK, 13, 8, FAIL, CLIENT },
483 {18, CMD_UNLOCK, 11, 7, PASS, SERVER },
484 /* Acquire different ranges beyond EOF */
485 {19, CMD_WRLOCK, 10, FILE_SIZE, PASS, SERVER },
486 {19, CMD_WRLOCK, FILE_SIZE + 10, 10, PASS, CLIENT },
487 {19, CMD_UNLOCK, 10, FILE_SIZE, PASS, SERVER },
488 {19, CMD_UNLOCK, FILE_SIZE + 10, 10, PASS, CLIENT },
489 /* Acquire same range beyong EOF */
490 {20, CMD_WRLOCK, 10, FILE_SIZE, PASS, SERVER, },
491 {20, CMD_WRLOCK, 10, FILE_SIZE, FAIL, CLIENT, },
492 {20, CMD_UNLOCK, 10, FILE_SIZE, PASS, SERVER, },
493 /* Acquire whole file lock */
494 {21, CMD_WRLOCK, 0, 0, PASS, SERVER, },
495 {21, CMD_WRLOCK, 0, 0, FAIL, CLIENT, },
496 {21, CMD_UNLOCK, 0, 0, PASS, SERVER, },
497 /* Acquire whole file lock, then range */
498 {22, CMD_WRLOCK, 0, 0, PASS, SERVER, },
499 {22, CMD_WRLOCK, 1, 5, FAIL, CLIENT, },
500 {22, CMD_UNLOCK, 0, 0, PASS, SERVER, },
501 /* Acquire non-overlapping read locks */
502 {23, CMD_RDLOCK, 1, 5, PASS, SERVER, },
503 {23, CMD_RDLOCK, 7, 6, PASS, CLIENT, },
504 {23, CMD_UNLOCK, 1, 5, PASS, SERVER, },
505 {23, CMD_UNLOCK, 7, 6, PASS, CLIENT, },
506 /* Acquire overlapping read locks */
507 {24, CMD_RDLOCK, 1, 5, PASS, SERVER, },
508 {24, CMD_RDLOCK, 2, 6, PASS, CLIENT, },
509 {24, CMD_UNLOCK, 1, 5, PASS, SERVER, },
510 {24, CMD_UNLOCK, 1, 7, PASS, CLIENT, },
511 /* Acquire non-overlapping read and write locks */
512 {25, CMD_RDLOCK, 1, 5, PASS, SERVER, },
513 {25, CMD_WRLOCK, 7, 6, PASS, CLIENT, },
514 {25, CMD_UNLOCK, 1, 5, PASS, SERVER, },
515 {25, CMD_UNLOCK, 7, 6, PASS, CLIENT, },
516 /* Acquire overlapping read and write locks */
517 {26, CMD_RDLOCK, 1, 5, PASS, SERVER, },
518 {26, CMD_WRLOCK, 2, 6, FAIL, CLIENT, },
519 {26, CMD_UNLOCK, 1, 5, PASS, SERVER, },
520 /* Acquire whole file lock, then close (without unlocking) */
521 {27, CMD_WRLOCK, 0, 0, PASS, SERVER, },
522 {27, CMD_WRLOCK, 1, 5, FAIL, CLIENT, },
523 {27, CMD_CLOSE,0, 0, PASS, SERVER, },
524 {27, CMD_WRLOCK, 1, 5, PASS, CLIENT, },
525 {27, CMD_OPEN, O_RDWR, 0, PASS, SERVER, },
526 {27, CMD_UNLOCK, 1, 5, PASS, CLIENT, },
527 /* Acquire two read locks, close one file and then reopen to check that first lock still exists */
528 {28, CMD_RDLOCK, 1, 5, PASS, SERVER, },
529 {28, CMD_RDLOCK, 1, 5, PASS, CLIENT, },
530 {28, CMD_CLOSE,0, 0, PASS, SERVER, },
531 {28, CMD_OPEN, O_RDWR, 0, PASS, SERVER, },
532 {28, CMD_WRLOCK, 0, 0, FAIL, SERVER, },
533 {28, CMD_UNLOCK, 1, 5, PASS, SERVER, },
534 /* Verify that F_GETLK for F_WRLCK doesn't require that file be opened for write */
535 {29, CMD_CLOSE, 0, 0, PASS, SERVER, },
536 {29, CMD_OPEN, O_RDONLY, 0, PASS, SERVER, },
537 {29, CMD_WRTEST, 0, 0, PASS, SERVER, },
538 {29, CMD_CLOSE,0, 0, PASS, SERVER, },
539 {29, CMD_OPEN, O_RDWR, 0, PASS, SERVER, },
541 /* Close the opened file and open the file with SHLOCK, other client will try to open with SHLOCK too */
542 {30, CMD_CLOSE,0, 0, PASS, SERVER, },
543 {30, CMD_OPEN, O_RDWR|O_SHLOCK|O_NONBLOCK, 0, PASS, SERVER, },
544 {30, CMD_CLOSE,0, 0, PASS, CLIENT, },
545 {30, CMD_OPEN, O_RDWR|O_SHLOCK|O_NONBLOCK, 0, PASS, CLIENT, },
546 /* Close the opened file and open the file with SHLOCK, other client will try to open with EXLOCK */
547 {31, CMD_CLOSE,0, 0, PASS, SERVER, },
548 {31, CMD_CLOSE,0, 0, PASS, CLIENT, },
549 {31, CMD_OPEN, O_RDWR|O_SHLOCK|O_NONBLOCK, 0, PASS, SERVER, },
550 {31, CMD_OPEN, O_RDWR|O_EXLOCK|O_NONBLOCK, 0, FAIL, CLIENT, },
551 /* Close the opened file and open the file with EXLOCK, other client will try to open with EXLOCK too */
552 {32, CMD_CLOSE,0, 0, PASS, SERVER, },
553 {32, CMD_CLOSE,0, 0, FAIL, CLIENT, },
554 {32, CMD_OPEN, O_RDWR|O_EXLOCK|O_NONBLOCK, 0, PASS, SERVER, },
555 {32, CMD_OPEN, O_RDWR|O_EXLOCK|O_NONBLOCK, 0, FAIL, CLIENT, },
556 {32, CMD_CLOSE,0, 0, PASS, SERVER, },
557 {32, CMD_CLOSE,0, 0, FAIL, CLIENT, },
558 {32, CMD_OPEN, O_RDWR, 0, PASS, SERVER, },
559 {32, CMD_OPEN, O_RDWR, 0, PASS, CLIENT, },
562 /* indicate end of array */
568 char *lease_descriptions[] = {
569 /* 1 */"Take Read Lease",
570 /* 2 */"Take Write Lease",
571 /* 3 */"Fail Write Lease if file is open somewhere else",
572 /* 4 */"Fail Read Lease if opened with write permissions",
573 /* 5 */"Read lease gets SIGIO on write open",
574 /* 6 */"Write lease gets SIGIO on read open",
575 /* 7 */"Read lease does _not_ get SIGIO on read open",
576 /* 8 */"Read lease gets SIGIO on write open",
579 static int64_t lease_tests[][6] =
580 /* test # Action [offset|flags|arg] length expected server/client */
581 /* [sigio_wait_time] */
583 /* Various tests to exercise leases */
585 /* SECTION 1: Simple verification of being able to take leases */
586 /* Take Read Lease */
587 {1, CMD_CLOSE, 0, 0, PASS, CLIENT },
588 {1, CMD_OPEN, O_RDONLY, 0, PASS, CLIENT },
589 {1, CMD_CLOSE, 0, 0, PASS, SERVER },
590 {1, CMD_OPEN, O_RDONLY, 0, PASS, SERVER },
591 {1, CMD_SETLEASE, F_RDLCK, 0, PASS, SERVER },
592 {1, CMD_GETLEASE, F_RDLCK, 0, PASS, SERVER },
593 {1, CMD_SETLEASE, F_UNLCK, 0, PASS, SERVER },
594 {1, CMD_CLOSE, 0, 0, PASS, SERVER },
595 {1, CMD_CLOSE, 0, 0, PASS, CLIENT },
597 /* Take Write Lease */
598 {2, CMD_OPEN, O_RDWR, 0, PASS, SERVER },
599 {2, CMD_SETLEASE, F_WRLCK, 0, PASS, SERVER },
600 {2, CMD_GETLEASE, F_WRLCK, 0, PASS, SERVER },
601 {2, CMD_SETLEASE, F_UNLCK, 0, PASS, SERVER },
602 {2, CMD_CLOSE, 0, 0, PASS, SERVER },
603 /* Fail Write Lease with other users */
604 {3, CMD_OPEN, O_RDONLY, 0, PASS, CLIENT },
605 {3, CMD_OPEN, O_RDWR, 0, PASS, SERVER },
606 {3, CMD_SETLEASE, F_WRLCK, 0, FAIL, SERVER },
607 {3, CMD_GETLEASE, F_WRLCK, 0, FAIL, SERVER },
608 {3, CMD_CLOSE, 0, 0, PASS, SERVER },
609 {3, CMD_CLOSE, 0, 0, PASS, CLIENT },
610 /* Fail Read Lease if opened for write */
611 {4, CMD_OPEN, O_RDWR, 0, PASS, SERVER },
612 {4, CMD_SETLEASE, F_RDLCK, 0, FAIL, SERVER },
613 {4, CMD_GETLEASE, F_RDLCK, 0, FAIL, SERVER },
614 {4, CMD_CLOSE, 0, 0, PASS, SERVER },
616 /* SECTION 2: Proper SIGIO notifications */
617 /* Get SIGIO when read lease is broken by write */
618 {5, CMD_OPEN, O_RDONLY, 0, PASS, CLIENT },
619 {5, CMD_SETLEASE, F_RDLCK, 0, PASS, CLIENT },
620 {5, CMD_GETLEASE, F_RDLCK, 0, PASS, CLIENT },
621 {5, CMD_SIGIO, 0, 0, PASS, CLIENT },
622 {5, CMD_OPEN, O_RDWR, 0, PASS, SERVER },
623 {5, CMD_WAIT_SIGIO, 5, 0, PASS, CLIENT },
624 {5, CMD_CLOSE, 0, 0, PASS, SERVER },
625 {5, CMD_CLOSE, 0, 0, PASS, CLIENT },
627 /* Get SIGIO when write lease is broken by read */
628 {6, CMD_OPEN, O_RDWR, 0, PASS, CLIENT },
629 {6, CMD_SETLEASE, F_WRLCK, 0, PASS, CLIENT },
630 {6, CMD_GETLEASE, F_WRLCK, 0, PASS, CLIENT },
631 {6, CMD_SIGIO, 0, 0, PASS, CLIENT },
632 {6, CMD_OPEN, O_RDONLY, 0, PASS, SERVER },
633 {6, CMD_WAIT_SIGIO, 5, 0, PASS, CLIENT },
634 {6, CMD_CLOSE, 0, 0, PASS, SERVER },
635 {6, CMD_CLOSE, 0, 0, PASS, CLIENT },
637 /* Don't get SIGIO when read lease is taken by read */
638 {7, CMD_OPEN, O_RDONLY, 0, PASS, CLIENT },
639 {7, CMD_SETLEASE, F_RDLCK, 0, PASS, CLIENT },
640 {7, CMD_GETLEASE, F_RDLCK, 0, PASS, CLIENT },
641 {7, CMD_SIGIO, 0, 0, PASS, CLIENT },
642 {7, CMD_OPEN, O_RDONLY, 0, PASS, SERVER },
643 {7, CMD_WAIT_SIGIO, 5, 0, FAIL, CLIENT },
644 {7, CMD_CLOSE, 0, 0, PASS, SERVER },
645 {7, CMD_CLOSE, 0, 0, PASS, CLIENT },
647 /* Get SIGIO when Read lease is broken by Write */
648 {8, CMD_OPEN, O_RDONLY, 0, PASS, CLIENT },
649 {8, CMD_SETLEASE, F_RDLCK, 0, PASS, CLIENT },
650 {8, CMD_GETLEASE, F_RDLCK, 0, PASS, CLIENT },
651 {8, CMD_SIGIO, 0, 0, PASS, CLIENT },
652 {8, CMD_OPEN, O_RDWR, 0, PASS, SERVER },
653 {8, CMD_WAIT_SIGIO, 5, 0, PASS, CLIENT },
654 {8, CMD_CLOSE, 0, 0, PASS, SERVER },
655 {8, CMD_CLOSE, 0, 0, PASS, CLIENT },
657 /* indicate end of array */
670 int32_t padding; /* So mac and irix have the same size struct (bloody alignment) */
677 fprintf(stderr, "Usage: %s [options] sharedfile\n\
680 -p port TCP/IP port number for client-server communication\n\
681 -d enable debug tracing\n\
682 -n # test number to run\n\
683 -h host run as client and connect to server on remote host\n\
684 [default run as server]\n", prog);
688 #define INIT_BUFSZ 512
691 initialize(HANDLE fd)
697 int togo = FILE_SIZE;
699 ibuf = (char*)malloc(INIT_BUFSZ);
700 memset(ibuf, ':', INIT_BUFSZ);
705 j = togo > INIT_BUFSZ ? INIT_BUFSZ : togo;
707 if ((nwrite = WRITE(fd, ibuf, j)) != j) {
709 perror("initialize write:");
711 fprintf(stderr, "initialize: write() returns %d, not %d as expected\n",
720 void release_lease(int fd)
724 rc = fcntl(fd, F_SETLEASE, F_UNLCK);
726 fprintf(stderr, "%s Failed to remove lease %d : %d %s\n",
727 __FILE__, rc, errno, strerror(errno));
730 void lease_break(int sig, siginfo_t *info, void *p)
733 fprintf(stderr, "lease break %d %p fd %d\n",
734 sig, info, info->si_fd);
739 struct sigaction lease_break_action = {
740 .sa_sigaction = lease_break,
741 .sa_flags = SA_SIGINFO,
744 int do_setup_sigio(int fd)
750 rc = sigaction(SIGIO, &lease_break_action, NULL);
752 fprintf(stderr, "%s Set '%s' sigaction failed %d\n",
753 __FILE__, strsignal(SIGIO), rc);
758 fprintf(stderr, "Set '%s' sigaction on %d\n",
759 strsignal(SIGIO), fd);
761 rc = fcntl(fd, F_SETSIG, SIGIO);
763 fprintf(stderr, "%s Set '%s' sigaction failed %d\n",
764 __FILE__, strsignal(SIGIO), rc);
766 return (rc == 0 ? PASS : FAIL);
769 int do_wait_sigio(int32_t time)
774 while (!got_sigio && time--) {
778 if (debug > 1 && !got_sigio)
779 fprintf(stderr, "%s failed to get sigio\n",
782 return (got_sigio ? PASS: FAIL);
785 int do_open(int flag)
787 int flags = flag|O_CREAT|O_BINARY;
790 fprintf(stderr, "do_open %s 0x%x\n", filename, flags);
792 if ((f_fd = open(filename, flags, 0666)) == INVALID_HANDLE) {
793 perror("shared file create");
800 static int do_lock(int cmd, int type, int start, int length)
807 fprintf(stderr, "do_lock: cmd=%d type=%d start=%d, length=%d\n", cmd, type, start, length);
815 fl.l_whence = SEEK_SET;
821 ret = fcntl(filedes, cmd, &fl);
825 fprintf(stderr, "do_lock: ret = %d, errno = %d (%s)\n", ret, errno, strerror(errno));
827 return(ret==0?PASS:FAIL);
830 static int do_lease(int cmd, int arg, int expected)
835 fprintf(stderr, "do_lease: cmd=%d arg=%d exp=%X\n",
843 ret = fcntl(f_fd, cmd, arg);
846 if (expected && (expected == ret))
850 fprintf(stderr, "%s do_lease: ret = %d, errno = %d (%s)\n",
851 __FILE__, ret, errno, strerror(errno));
853 return(ret==0?PASS:FAIL);
859 fprintf(stderr, "do_close\n");
864 f_fd = INVALID_HANDLE;
869 fprintf(stderr, "%s errno = %d (%s)\n",
870 __FILE__, errno, strerror(errno));
876 static void init_ctl(int64_t tests[][6], int32_t index)
878 ctl.test= (int32_t)tests[index][TEST_NUM];
879 ctl.command = (int32_t)tests[index][COMMAND];
880 ctl.offset = tests[index][OFFSET];
881 ctl.length = tests[index][LENGTH];
883 ctl.result = (int32_t)tests[index][RESULT];
893 fprintf(stderr, "send_ctl: test=%d, command=%d offset=%"LL"d, length=%"LL"d, result=%d, error=%d\n",
894 ctl.test, ctl.command, (long long)ctl.offset, (long long)ctl.length,ctl.result, ctl.error);
897 ctl.test= bswap_uint32(ctl.test);
898 ctl.command = bswap_uint32(ctl.command);
899 ctl.offset = bswap_uint64(ctl.offset);
900 ctl.length = bswap_uint64(ctl.length);
901 ctl.result = bswap_uint32(ctl.result);
902 ctl.index= bswap_uint32(ctl.index);
903 ctl.error = bswap_uint32(ctl.error);
904 nwrite = SOCKET_WRITE(c_fd, (char*)&ctl, sizeof(ctl));
906 ctl.test= bswap_uint32(ctl.test);
907 ctl.command = bswap_uint32(ctl.command);
908 ctl.offset = bswap_uint64(ctl.offset);
909 ctl.length = bswap_uint64(ctl.length);
910 ctl.result = bswap_uint32(ctl.result);
911 ctl.index= bswap_uint32(ctl.index);
912 ctl.error= bswap_uint32(ctl.error);
913 if (nwrite != sizeof(ctl)) {
915 perror("send_ctl: write");
917 fprintf(stderr, "send_ctl[%d]: write() returns %d, not %zu as expected\n",
918 ctl.test, nwrite, sizeof(ctl));
929 if ((nread = SOCKET_READ(c_fd, (char*)&ctl, sizeof(ctl))) != sizeof(ctl)) {
933 perror("recv_ctl: read");
935 fprintf(stderr, "recv_ctl[%d]: read() returns %d, not %zu as expected\n",
936 ctl.test, nread, sizeof(ctl));
937 fprintf(stderr, "socket might has been closed by other locktest\n");
942 ctl.test= bswap_uint32(ctl.test);
943 ctl.command = bswap_uint32(ctl.command);
944 ctl.offset = bswap_uint64(ctl.offset);
945 ctl.length = bswap_uint64(ctl.length);
946 ctl.result = bswap_uint32(ctl.result);
947 ctl.index= bswap_uint32(ctl.index);
948 ctl.error= bswap_uint32(ctl.error);
951 fprintf(stderr, "recv_ctl: test=%d, command=%d offset=%"LL"d, length=%"LL"d, result=%d, error=%d\n",
952 ctl.test, ctl.command, (long long)ctl.offset, (long long)ctl.length, ctl.result, ctl.error);
972 run(int64_t tests[][6], char *descriptions[]);
975 main(int argc, char *argv[])
979 struct sockaddr_in myAddr;
980 struct linger noLinger = {1, 0};
994 /* trim command name of leading directory components */
996 for (p = prog; *p; p++) {
1001 while ((c = getopt(argc, argv, "dLn:h:p:?")) != EOF) {
1004 case 'd': /* debug flag */
1008 case 'L': /* Lease testing */
1012 case 'h': /* (server) hostname */
1018 testnumber = atoi(optarg);
1021 case 'p': /* TCP/IP port */
1022 port = (int)strtol(optarg, &endnum, 10);
1023 if (*endnum != '\0') {
1024 fprintf(stderr, "%s: -p argument must be a numeric\n",
1038 if (errflag || optind != argc-1) {
1043 filename=argv[optind];
1045 fprintf(stderr, "Working on file : %s\n", filename);
1046 if (do_open(O_RDWR) == FAIL)
1049 setbuf(stderr, NULL);
1054 s_fd = socket(AF_INET, SOCK_STREAM, 0);
1055 if (s_fd == INVALID_SOCKET) {
1060 if (setsockopt(s_fd, IPPROTO_TCP, TCP_NODELAY, (char*)&one, sizeof(one)) < 0) {
1061 perror("setsockopt(nodelay)");
1065 if (setsockopt(s_fd, SOL_SOCKET, SO_REUSEADDR, (char*)&one, sizeof(one))<0) {
1066 perror("setsockopt(reuseaddr)");
1071 if (setsockopt(s_fd, SOL_SOCKET, SO_REUSEPORT, (char*)&one, sizeof(one))<0) {
1072 perror("setsockopt(reuseport)");
1078 memset(&myAddr, 0, sizeof(myAddr));
1079 myAddr.sin_family = AF_INET;
1080 myAddr.sin_addr.s_addr = htonl(INADDR_ANY);
1081 myAddr.sin_port = htons((short)port);
1082 sts = bind(s_fd, (struct sockaddr*)&myAddr, sizeof(myAddr));
1089 sts = listen(s_fd, 5); /* Max. of 5 pending connection requests */
1097 socklen_t addr_len = sizeof(myAddr);
1099 if (getsockname(s_fd, &myAddr, &addr_len)) {
1100 perror("getsockname");
1104 port = ntohs(myAddr.sin_port);
1107 printf("server port: %d\n", port);
1110 c_fd = accept(s_fd, NULL, NULL);
1111 if (c_fd == INVALID_SOCKET) {
1117 if (debug) fprintf(stderr, "Client accepted\n");
1121 struct hostent *servInfo;
1123 if ((servInfo = gethostbyname(host)) == NULL) {
1124 fprintf(stderr, "Couldn't get hostbyname for %s", host);
1125 if (h_errno == HOST_NOT_FOUND)
1126 fprintf(stderr, ": host not found");
1127 fprintf(stderr, "\n");
1132 c_fd = socket(AF_INET, SOCK_STREAM, 0);
1133 if (c_fd == INVALID_SOCKET) {
1138 /* avoid 200 ms delay */
1139 if (setsockopt(c_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&i, sizeof(i)) < 0) {
1140 perror("setsockopt(nodelay)");
1144 /* Don't linger on close */
1145 if (setsockopt(c_fd, SOL_SOCKET, SO_LINGER, (char *)&noLinger, sizeof(noLinger)) < 0) {
1146 perror("setsockopt(nolinger)");
1151 memset(&myAddr, 0, sizeof(myAddr)); /* Arrgh! &myAddr, not myAddr */
1152 myAddr.sin_family = AF_INET;
1153 memcpy(&myAddr.sin_addr, servInfo->h_addr, servInfo->h_length);
1154 myAddr.sin_port = htons((short)port);
1156 if (connect(c_fd, (struct sockaddr*)&myAddr, sizeof(myAddr)) < 0) {
1157 perror("unable to connect");
1158 fprintf(stderr, "Server might still initializing the shared file\n ");
1163 if (debug) fprintf(stderr, "Connected to server\n");
1168 /* only server need do shared file */
1172 * TCP/IP connection to be established, safe to proceed.
1174 * real work is in here ...
1177 fail_count = run(lease_tests, lease_descriptions);
1179 fail_count = run(lock_tests, lock_descriptions);
1185 int run(int64_t tests[][6], char *descriptions[])
1191 int test_count = -1;
1196 if(testnumber > 0) {
1197 last_test = testnumber - 1;
1198 while(tests[index][TEST_NUM] != testnumber && tests[index][TEST_NUM] != 0) {
1202 /* If we have a server command, deal with it */
1203 if(tests[index][WHO] == SERVER) {
1205 fprintf(stderr, "Got a server command (%d)\n", index);
1206 if(tests[index][TEST_NUM] == 0) {
1210 memset(&ctl, 0, sizeof(ctl));
1211 ctl.test = tests[index][TEST_NUM];
1213 if(tests[index][TEST_NUM] != 0) {
1214 switch(tests[index][COMMAND]) {
1216 result = do_lock(F_SETLK, F_WRLCK, tests[index][OFFSET], tests[index][LENGTH]);
1219 result = do_lock(F_SETLK, F_RDLCK, tests[index][OFFSET], tests[index][LENGTH]);
1222 result = do_lock(F_SETLK, F_UNLCK, tests[index][OFFSET], tests[index][LENGTH]);
1225 result = do_close();
1228 result = do_open(tests[index][FLAGS]);
1231 result = do_lock(F_GETLK, F_WRLCK, tests[index][OFFSET], tests[index][LENGTH]);
1234 result = do_lock(F_GETLK, F_RDLCK, tests[index][OFFSET], tests[index][LENGTH]);
1237 result = do_lease(F_SETLEASE, tests[index][ARG], 0);
1240 result = do_lease(F_GETLEASE, tests[index][ARG], tests[index][ARG]);
1243 result = do_setup_sigio(f_fd);
1245 case CMD_WAIT_SIGIO:
1246 result = do_wait_sigio(tests[index][TIME]);
1249 if( result != tests[index][RESULT]) {
1251 /* We have a failure */
1252 fprintf(stderr, " ***** Server failure *****\n");
1253 fprintf(stderr, " in test %d, while %sing using offset %lld, length %lld - err = %d:%s\n",
1254 ctl.test, get_cmd_str(tests[index][COMMAND]),
1255 (long long)tests[index][OFFSET],
1256 (long long)tests[index][LENGTH],
1257 saved_errno, strerror(saved_errno));
1258 fprintf(stderr, " %d:%s\n",
1259 ctl.test, descriptions[ctl.test - 1]);
1262 /* else send it off to the client */
1263 } else if (tests[index][WHO] == CLIENT) {
1264 if(tests[index][TEST_NUM] == 0) {
1268 /* get the client to do something */
1269 init_ctl(tests, index);
1271 fprintf(stderr, "Sending command to client (%d) - %s - %lld:%lld\n",
1273 get_cmd_str(ctl.command),
1274 (long long)tests[index][OFFSET],
1275 (long long)tests[index][LENGTH]);
1276 /* get the client to do something */
1280 /* Get the clients response */
1282 /* this is the whether the test passed or failed,
1283 * not what the command returned */
1284 if( ctl.result == FAIL ) {
1286 fprintf(stderr, " ***** Client failure *****\n");
1287 fprintf(stderr, " in test %d, while %sing using offset %lld, length %lld - err = %d:%s\n",
1288 ctl.test, get_cmd_str(ctl.command),
1289 (long long)ctl.offset, (long long)ctl.length,
1290 ctl.error, strerror(ctl.error));
1291 fprintf(stderr, " %d:%s\n",
1292 ctl.test, descriptions[ctl.test - 1]);
1297 if(last_test != tests[index][TEST_NUM]) {
1302 last_test = tests[index][TEST_NUM];
1306 } else { /* CLIENT */
1308 fprintf(stderr,"client: waiting...\n");
1309 /* wait for the server to do something */
1312 /* check for a client command */
1314 if (tests[index][WHO] != CLIENT) {
1315 fprintf(stderr, "not a client command index (%d)\n", index);
1324 switch(ctl.command) {
1326 result = do_lock(F_SETLK, F_WRLCK, ctl.offset, ctl.length);
1329 result = do_lock(F_SETLK, F_RDLCK, ctl.offset, ctl.length);
1332 result = do_lock(F_SETLK, F_UNLCK, ctl.offset, ctl.length);
1335 result = do_close();
1338 result = do_open(tests[index][FLAGS]);
1341 result = do_lock(F_GETLK, F_WRLCK, ctl.offset, ctl.length);
1344 result = do_lock(F_GETLK, F_RDLCK, ctl.offset, ctl.length);
1346 /* NOTE offset carries the argument values */
1348 result = do_lease(F_SETLEASE, ctl.offset, 0);
1351 result = do_lease(F_GETLEASE, ctl.offset, ctl.offset);
1354 result = do_setup_sigio(f_fd);
1356 case CMD_WAIT_SIGIO:
1357 result = do_wait_sigio(ctl.offset);
1360 if( result != ctl.result ) {
1361 fprintf(stderr,"Failure in %d:%s\n",
1362 ctl.test, descriptions[ctl.test - 1]);
1363 fprintf(stderr," Got %d, wanted %d\n",
1364 result, ctl.result);
1366 ctl.error = saved_errno;
1373 fprintf(stderr,"client: sending result to server (%d)\n", ctl.index);
1374 /* Send result to the server */
1376 if(last_test != tests[index][TEST_NUM]) {
1378 last_test = tests[index][TEST_NUM];
1382 fprintf(stderr, "%d tests run, %d failed\n", test_count, fail_count);