1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/tests/parallel_grouplock.c
38 * Author: You Feng <youfeng@clusterfs.com>
45 #include <sys/types.h>
46 #include <asm/types.h>
49 #include <sys/ioctl.h>
53 #include <lustre/lustre_user.h>
56 #define LPGL_BUF_LEN 8192
57 #define LPGL_TEST_ITEMS 12
61 #define MAX_WAIT_TRIES 10
62 #define WAIT_TIME 1 /* secs */
63 #define ONE_MB 1048576 /* 1 MB */
64 #define MIN_LGBUF_SIZE 536870912 /* 512 MB */
65 #define MAX_LGBUF_SIZE 536870912 /* 512 MB */
66 // #define MAX_LGBUF_SIZE 1073741824 /* 1 GB */
79 char buf[LPGL_BUF_LEN];
82 char filename[MAX_FILENAME_LEN];
83 char errmsg[MAX_FILENAME_LEN+20];
92 lgbuf_size = MAX_LGBUF_SIZE;
93 for (; lgbuf_size >= MIN_LGBUF_SIZE; lgbuf_size -= ONE_MB)
94 if ((lgbuf = (char *)malloc(lgbuf_size)) != NULL)
97 FAIL("malloc of large buffer failed.\n");
105 rc = read(fd, buf, sizeof(buf));
107 pos = lseek(fd, 0, SEEK_CUR);
108 sprintf(errmsg, "read of file %s at pos %d for %lu bytes "
109 "returned %d: (%d) %s.\n",
110 filename, pos, (unsigned long)sizeof(buf), rc, errno, strerror(errno));
112 } else if (rc != sizeof(buf)) {
113 pos = lseek(fd, 0, SEEK_CUR);
114 sprintf(errmsg, "read of file %s at pos %d for %lu bytes "
116 filename, pos, (unsigned long) sizeof(buf), rc);
122 write_buf(int fd, int index)
124 int pos = index * sizeof(buf);
127 memset(buf, index, sizeof(buf));
128 lseek(fd, pos, SEEK_SET);
129 rc = write(fd, buf, sizeof(buf));
131 sprintf(errmsg, "write of file %s at pos %d for %lu bytes "
132 "returned %d: (%d) %s.\n",
133 filename, pos, (unsigned long)sizeof(buf), rc, errno, strerror(errno));
135 } else if (rc != sizeof(buf)) {
136 sprintf(errmsg, "write of file %s at pos %d for %lu bytes "
138 filename, pos, (unsigned long)sizeof(buf), rc);
144 * task0 attempts GR(gid=1) -- granted immediately
145 * task1 attempts PR|PW -- blocked, goes on waiting list
146 * task2 attempts GR(gid=1) -> should be granted
147 * task2 writes to file and releases GR(gid=1)
148 * task0 waits for task2 to complete its processing
149 * task0 writes to file and releases GR(gid=1)
150 * task1 PR|PW should be granted and reads the file
152 void grouplock_test1(char *filename, int fd, int blocking_op, int unlock_op)
154 MPI_Request req1, req2;
155 int iter, flag1, flag2, temp1, temp2;
159 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
161 "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
162 filename, errno, strerror(errno));
167 MPI_Barrier(MPI_COMM_WORLD);
171 if (blocking_op == WRITE) {
173 lseek(fd, 0, SEEK_SET);
176 for (i = 0; i <= 2; i++)
179 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
182 /* Wait for task1 to progress. This could be racey. */
185 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
187 "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
188 filename, errno, strerror(errno));
194 if (unlock_op == CLOSE)
197 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
201 "%s release GROUP_LOCK of file %s: (%d) %s.\n",
202 (unlock_op == CLOSE) ? "close" : "ioctl",
203 filename, errno, strerror(errno));
206 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
209 /* PR|PW task will tell us when it completes */
210 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
211 /* 2nd locking task will tell us when it completes */
212 MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
214 /* Wait for task2 to complete. */
215 iter = MAX_WAIT_TRIES;
219 FAIL("2nd locking task is not progressing\n");
224 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
226 FAIL("PR|PW task progressed even though GROUP "
230 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
233 /* Make sure task1 is still waiting. */
234 iter = MAX_WAIT_TRIES;
238 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
240 FAIL("PR|PW task progressed even though "
241 "GROUP lock is held\n");
247 /* Now we need to release the lock */
248 if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid)) == -1) {
250 "ioctl GROUP_UNLOCK of file %s: (%d) %s.\n",
251 filename, errno, strerror(errno));
255 /* Wait for task1 to complete. */
256 iter = MAX_WAIT_TRIES;
260 FAIL("PR|PW task is not progressing even "
261 "though GROUP lock was released\n");
265 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
273 * task0 attempts GR(gid=1) -- granted immediately
274 * task1 attempts GR(gid=2) -- blocked
275 * task2 attempts PR|PW -- blocked
276 * task3 attempts GR(gid=2) -- blocked
277 * task4 attempts GR(gid=1) -- should be granted
278 * task0,4 writes to file and releases GR(gid=1) --
279 * this allows task2 & 3's GR locks to be granted; task4 remains blocked.
280 * task1 & 3 write to file and release GR(gid=2)
281 * task2 PR|PW should be granted and reads the file.
283 void grouplock_test2(char *filename, int fd, int blocking_op, int unlock_op)
285 int i, iter, rc, gid = 1;
286 int flag1, flag2, flag3, flag4;
287 int temp1, temp2, temp3, temp4;
288 MPI_Request req1, req2, req3, req4;
291 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
293 "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
294 filename, errno, strerror(errno));
299 MPI_Barrier(MPI_COMM_WORLD);
303 /* Wait for task2 to issue its read request. */
307 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
309 "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
310 filename, errno, strerror(errno));
316 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
318 /* Do not release the locks until task 0 is ready to watch
319 for reading task only */
320 MPI_Recv(&temp1, 1, MPI_INT, 0, 1, MPI_COMM_WORLD,
323 if (unlock_op == CLOSE)
326 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
329 "%s release GROUP_LOCK of file %s: (%d) %s.\n",
330 (unlock_op == CLOSE) ? "close" : "ioctl",
331 filename, errno, strerror(errno));
336 /* Give task1 a chance to request its GR lock. */
339 if (blocking_op == WRITE) {
341 lseek(fd, 0, SEEK_SET);
344 for (i = 0; i <= 3; i++)
347 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
350 /* Give task1 & 3 a chance to queue their GR locks. */
353 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
355 "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
356 filename, errno, strerror(errno));
362 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
365 "%s release GROUP_LOCK of file %s: (%d) %s.\n",
366 (unlock_op == CLOSE) ? "close" : "ioctl",
367 filename, errno, strerror(errno));
371 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
374 /* locking tasks will tell us when they complete */
375 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
376 MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
377 MPI_Irecv(&temp3, 1, MPI_INT, 3, 1, MPI_COMM_WORLD, &req3);
378 MPI_Irecv(&temp4, 1, MPI_INT, 4, 1, MPI_COMM_WORLD, &req4);
380 /* Make sure all tasks that should be blocked are waiting. */
381 iter = MAX_WAIT_TRIES;
385 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
386 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
387 MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
388 if (flag1 || flag3) {
389 FAIL("GROUP (gid=2) task progressed even though"
390 " GROUP (gid=1) lock is held.\n");
393 FAIL("PR|PW task progressed even though "
394 "GROUP (gid=1) lock is still held\n");
398 /* Wait for task4 to signal it has completed. */
399 iter = MAX_WAIT_TRIES;
403 FAIL("2nd task GROUP(gid=1) not progressing\n");
406 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
407 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
408 MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
409 MPI_Test(&req4, &flag4, MPI_STATUS_IGNORE);
410 if (flag1 || flag3) {
411 FAIL("GROUP (gid=2) task progressed even though"
412 " GROUP (gid=1) lock is held.\n");
415 FAIL("PR|PW task progressed even though "
416 "GROUP (gid=1) lock is still held\n");
422 /* Now let's release first lock */
423 if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid)) == -1) {
424 sprintf(errmsg, "ioctl GROUP_UNLOCK of file %s "
425 "returned %d", filename, rc);
429 /* Wait for task1 & 3 to signal they have their lock. */
430 iter = MAX_WAIT_TRIES;
434 FAIL("GROUP(gid=2) tasks not progressing\n");
437 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
438 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
439 MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
441 fprintf(stderr, "task2 %d\n", flag2);
442 FAIL("PR task progressed even though GROUP lock"
443 " was on the queue task\n");
445 } while (!(flag1 && flag3));
447 /* Make sure task2 is still waiting. */
448 iter = MAX_WAIT_TRIES;
452 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
454 FAIL("PR task progressed even though GR(gid=2) "
455 "lock was active.\n");
459 /* Tell task1 & 3 to release their GR(gid=2) lock. */
460 MPI_Send(&gid, 1, MPI_INT, 1, 1, MPI_COMM_WORLD);
461 MPI_Send(&gid, 1, MPI_INT, 3, 1, MPI_COMM_WORLD);
463 /* Wait for task2 (PR) to complete. */
464 iter = MAX_WAIT_TRIES;
468 FAIL("reading task is not progressing even "
469 "though GROUP locks are released\n");
473 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
480 * Tests a bug that once existed in the group lock code;
481 * i.e. that a GR lock request on a O_NONBLOCK fd could fail even though
482 * there is no blocking GROUP lock ahead of it on the waitq.
484 * task0 starts a large write (PW). this test could be racey if this
485 * write finishes too quickly.
486 * task1 attempts GR(gid=1) -- blocked
487 * task2 attempts GR(gid=2) with a O_NONBLOCK fs. should not fail.
489 void grouplock_test3(char *filename, int fd)
491 MPI_Request req1, req2;
492 int iter, flag1, flag2, temp1, temp2;
497 } else if (rank == 2) {
498 rc = fcntl(fd, F_SETFL, O_NONBLOCK);
500 sprintf(errmsg, "fcntl(O_NONBLOCK) failed: (%d) %s.\n",
501 errno, strerror(errno));
506 MPI_Barrier(MPI_COMM_WORLD);
514 /* Racey, we have to sleep just long enough for
515 * task0's write to start. */
518 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
520 "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
521 filename, errno, strerror(errno));
525 /* tell task0 we have the lock. */
526 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
528 /* the close of fd will release the lock. */
531 rc = write(fd, lgbuf, lgbuf_size);
533 sprintf(errmsg, "write of file %s for %d bytes "
534 "returned %d: (%d) %s.\n",
535 filename, lgbuf_size,
536 rc, errno, strerror(errno));
538 } else if (rc != lgbuf_size) {
539 sprintf(errmsg, "write of file %s for %d bytes "
541 filename, lgbuf_size, rc);
545 /* GR tasks will tell us when they complete */
546 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
547 MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
549 /* Wait for task1 & 2 to complete. */
550 iter = MAX_WAIT_TRIES;
554 FAIL("GR(gid=1) tasks are not progressing even "
555 "no conflicting locks exist.\n");
559 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
560 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
561 } while (!(flag1 && flag2));
567 * Tests a bug that once existed in the group lock code;
568 * i.e. extent locks without O_NONBLOCK that go on the waitq before a group
569 * lock request came in and was granted. The extent lock would timed out and
572 * task0 starts a large write (PW). this test could be racey if this
573 * write finishes too quickly.
574 * task1 attempts PR -- blocked
575 * task2 attempts GR(gid=1) -- blocked
576 * task0 completes write
577 * task1 should wakeup and complete its read
578 * task2 should wakeup and after task1 complete.
580 void grouplock_test4(char *filename, int fd)
583 int iter, flag1, temp1;
589 MPI_Barrier(MPI_COMM_WORLD);
593 /* Racey, we have to sleep just long enough for
594 * task0's write to start. */
595 MPI_Recv(&temp1, 1, MPI_INT, 0, 1, MPI_COMM_WORLD,
600 /* tell task2 to go. */
601 MPI_Send(&gid, 1, MPI_INT, 2, 1, MPI_COMM_WORLD);
605 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
608 /* Give task0 & 1 a chance to start. */
609 MPI_Recv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD,
614 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
616 "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
617 filename, errno, strerror(errno));
621 /* tell task0 we have the lock. */
622 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
624 /* Do not release the locks until task 0 tells us too.
625 for reading task only */
626 MPI_Recv(&temp1, 1, MPI_INT, 0, 1, MPI_COMM_WORLD,
629 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
632 "ioctl GROUP_UNLOCK of file %s: (%d) %s.\n",
633 filename, errno, strerror(errno));
638 /* tell task1 to go to avoid race */
639 MPI_Send(&gid, 1, MPI_INT, 1, 1, MPI_COMM_WORLD);
640 rc = write(fd, lgbuf, lgbuf_size);
642 sprintf(errmsg, "write of file %s for %d bytes "
643 "returned %d: (%d) %s.\n",
644 filename, lgbuf_size,
645 rc, errno, strerror(errno));
647 } else if (rc != lgbuf_size) {
648 sprintf(errmsg, "write of file %s for %d bytes "
650 filename, lgbuf_size, rc);
654 /* wait for task2 to get its lock. */
655 MPI_Recv(&temp1, 1, MPI_INT, 2, 1, MPI_COMM_WORLD,
658 /* Tell task2 it's ok to release its GR(gid=1) lock. */
659 MPI_Send(&gid, 1, MPI_INT, 2, 1, MPI_COMM_WORLD);
661 /* wait a really long time. */
662 sleep(180 * WAIT_TIME);
664 /* PR task will tell us when it completes */
665 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
667 /* Make sure the PR task is successful and doesn't hang.
669 * XXX - To test properly we need to make sure the read
670 * gets queued before task2's group lock request.
671 * You may need to increase lgbuf_size.
673 iter = MAX_WAIT_TRIES;
677 FAIL("PR task is hung !\n");
681 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
689 * task0 attempts GR(gid=1) -- granted
690 * task1 attempts PR on non-blocking fd -> should return -EWOULDBLOCK
691 * task2 attempts PW on non-blocking fd -> should return -EWOULDBLOCK
692 * task3 attempts GR(gid=2) on non-blocking fd -> should return -EWOULDBLOCK
694 void grouplock_nonblock_test(char *filename, int fd)
696 MPI_Request req1, req2, req3;
697 int iter, flag1, flag2, flag3, temp1, temp2, temp3;
701 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
703 "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
704 filename, errno, strerror(errno));
709 rc = fcntl(fd, F_SETFL, O_NONBLOCK);
711 sprintf(errmsg, "fcntl(O_NONBLOCK) failed: (%d) %s.\n",
712 errno, strerror(errno));
716 MPI_Barrier(MPI_COMM_WORLD);
720 rc = read(fd, buf, sizeof(buf));
721 if ((rc != -1) || (errno != EWOULDBLOCK)) {
722 FAIL("PR lock succeeded while incompatible "
723 "GROUP LOCK (gid=1) is still held\n");
726 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
729 rc = write(fd, buf, sizeof(buf));
730 if ((rc != -1) || (errno != EWOULDBLOCK)) {
731 FAIL("PW lock succeeded while incompatible "
732 "GROUP LOCK (gid=1) is still held\n");
735 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
739 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
740 if ((rc != -1) || (errno != EWOULDBLOCK)) {
741 FAIL("GROUP_LOCK (gid=2) succeeded while incompatible "
742 "GROUP LOCK (gid=1) is still held.\n");
745 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
748 /* reading task will tell us when it completes */
749 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
750 /* writing task will tell us when it completes */
751 MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
752 /* 2nd locking task will tell us when it completes */
753 MPI_Irecv(&temp3, 1, MPI_INT, 3, 1, MPI_COMM_WORLD, &req3);
755 iter = MAX_WAIT_TRIES;
759 FAIL("non-blocking tasks are not progressing\n");
762 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
763 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
764 MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
765 } while (!(flag1 && flag2 && flag3));
767 if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid)) == -1) {
768 sprintf(errmsg, "ioctl GROUP_UNLOCK of file %s",
776 /* Just test some error paths with invalid requests */
777 void grouplock_errorstest(char *filename, int fd)
781 MPI_Barrier(MPI_COMM_WORLD);
785 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
787 "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
788 filename, errno, strerror(errno));
792 /* second group lock on same fd, same gid */
793 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
794 if (errno != EINVAL) {
795 sprintf(errmsg, "Double GROUP lock failed "
796 "with errno %d instead of EINVAL\n",
801 FAIL("Taking second GROUP lock on same fd succeed\n");
804 /* second group lock on same fd, different gid */
805 if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid + 1)) == -1) {
806 if (errno != EINVAL) {
807 sprintf(errmsg, "Double GROUP lock with "
808 "different gid failed with errno %d "
809 "instead of EINVAL\n", errno);
813 FAIL("Taking second GROUP lock on same fd, with "
814 "different gid, succeeded.\n");
817 /* GROUP unlock with wrong gid */
818 if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid + 1)) == -1) {
819 if (errno != EINVAL) {
820 sprintf(errmsg, "GROUP_UNLOCK with wrong gid "
821 "failed with errno %d instead of "
826 FAIL("GROUP unlock with wrong gid succeed\n");
829 if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid)) == -1) {
830 sprintf(errmsg, "ioctl GROUP_UNLOCK of file %s "
831 "returned %d.", filename, rc);
837 /* unlock of never locked fd */
838 if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid)) == -1) {
839 if (errno != EINVAL) {
840 sprintf(errmsg, "GROUP_UNLOCK on never locked "
841 "fd failed with errno %d instead of "
846 FAIL("GROUP unlock on never locked fd succeed\n");
852 void grouplock_file(char *name, int subtest)
855 int flags = O_CREAT|O_RDWR|O_SYNC|O_TRUNC;
858 sprintf(filename, "%s/%s", testdir, name);
860 if ((fd = open(filename, flags, mode)) == -1) {
861 sprintf(errmsg, "open of file %s: (%d) %s.\n",
862 filename, errno, strerror(errno));
866 MPI_Barrier(MPI_COMM_WORLD);
870 grouplock_test1(filename, fd, READ, IOCTL);
873 grouplock_test1(filename, fd, READ, CLOSE);
876 grouplock_test1(filename, fd, WRITE, IOCTL);
879 grouplock_test1(filename, fd, WRITE, CLOSE);
882 grouplock_test2(filename, fd, READ, IOCTL);
885 grouplock_test2(filename, fd, READ, CLOSE);
888 grouplock_test2(filename, fd, WRITE, IOCTL);
891 grouplock_test2(filename, fd, WRITE, CLOSE);
894 grouplock_nonblock_test(filename, fd);
897 grouplock_errorstest(filename, fd);
900 grouplock_test3(filename, fd);
903 grouplock_test4(filename, fd);
906 sprintf(errmsg, "wrong subtest number %d (should be <= %d)",
907 subtest, LPGL_TEST_ITEMS);
916 MPI_Barrier(MPI_COMM_WORLD);
919 void parallel_grouplock(void)
925 sprintf(teststr, "subtest %d", only_test);
927 grouplock_file("parallel_grouplock", only_test);
930 for (i = 1; i <= LPGL_TEST_ITEMS; i++) {
931 sprintf(teststr, "subtest %d", i);
933 grouplock_file("parallel_grouplock", i);
939 void usage(char *proc)
944 printf("Usage: %s [-h] -d <testdir> [-n <num>]\n", proc);
945 printf(" [-t <num>] [-v] [-V #] [-g]\n");
946 printf("\t-h: prints this help message\n");
947 printf("\t-d: the directory in which the tests will run\n");
948 printf("\t-n: repeat test # times\n");
949 printf("\t-t: run a particular test #\n");
950 printf("\t-v: increase the verbositly level by 1\n");
951 printf("\t-V: select a specific verbosity level\n");
952 printf("\t-g: debug mode\n");
956 if (i) MPI_Finalize();
960 int main(int argc, char *argv[])
963 int i, iterations = 1;
968 /* Check for -h parameter before MPI_Init so the binary can be
969 called directly, without, for instance, mpirun */
970 for (i = 1; i < argc; ++i) {
971 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
975 MPI_Init(&argc, &argv);
976 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
977 MPI_Comm_size(MPI_COMM_WORLD, &size);
979 /* Parse command line options */
981 c = getopt(argc, argv, "d:ghn:t:vV:");
996 iterations = atoi(optarg);
999 only_test = atoi(optarg);
1005 verbose = atoi(optarg);
1011 printf("%s is running with %d task(es) %s\n",
1012 argv[0], size, debug ? "in DEBUG mode" : "\b\b");
1014 if (size < MIN_GLHOST) {
1015 fprintf(stderr, "Error: "
1016 "should be at least four tasks to run the test!\n");
1017 MPI_Abort(MPI_COMM_WORLD, 2);
1020 if (testdir == NULL && rank == 0) {
1021 fprintf(stderr, "Please specify a test directory! "
1022 "(\"%s -h\" for help)\n",
1024 MPI_Abort(MPI_COMM_WORLD, 2);
1029 for (i = 0; i < iterations; ++i) {
1031 printf("%s: Running test #%s(iter %d)\n",
1032 timestamp(), argv[0], i);
1034 parallel_grouplock();
1035 MPI_Barrier(MPI_COMM_WORLD);
1039 printf("%s: All tests passed!\n", timestamp());