4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
27 * This file is part of Lustre, http://www.lustre.org/
29 * lustre/tests/parallel_grouplock.c
31 * Author: You Feng <youfeng@clusterfs.com>
39 #include <sys/types.h>
40 #include <asm/types.h>
43 #include <sys/ioctl.h>
49 #define LPGL_BUF_LEN 8192
50 #define LPGL_TEST_ITEMS 12
54 #define MAX_WAIT_TRIES 10
55 #define WAIT_TIME 1 /* secs */
56 #define ONE_MB 1048576 /* 1 MB */
57 #define MIN_LGBUF_SIZE 536870912 /* 512 MB */
58 #define MAX_LGBUF_SIZE 536870912 /* 512 MB */
59 // #define MAX_LGBUF_SIZE 1073741824 /* 1 GB */
72 char buf[LPGL_BUF_LEN];
75 char filename[MAX_FILENAME_LEN];
83 lgbuf_size = MAX_LGBUF_SIZE;
84 for (; lgbuf_size >= MIN_LGBUF_SIZE; lgbuf_size -= ONE_MB)
85 if ((lgbuf = (char *)malloc(lgbuf_size)) != NULL)
88 FAIL("malloc of large buffer failed.\n");
96 rc = read(fd, buf, sizeof(buf));
98 pos = lseek(fd, 0, SEEK_CUR);
99 FAILF("read of file %s at pos %d for %zu bytes returned %d: (%d) %s.\n",
100 filename, pos, sizeof(buf), rc, errno, strerror(errno));
101 } else if (rc != sizeof(buf)) {
102 pos = lseek(fd, 0, SEEK_CUR);
103 FAILF("read of file %s at pos %d for %zu bytes returned %d.\n",
104 filename, pos, sizeof(buf), rc);
109 write_buf(int fd, int index)
111 int pos = index * sizeof(buf);
114 memset(buf, index, sizeof(buf));
115 lseek(fd, pos, SEEK_SET);
116 rc = write(fd, buf, sizeof(buf));
118 FAILF("write of file %s at pos %d for %zu bytes returned %d: (%d) %s.\n",
119 filename, pos, sizeof(buf), rc, errno, strerror(errno));
120 else if (rc != sizeof(buf))
121 FAILF("write of file %s at pos %d for %zu bytes returned %d.\n",
122 filename, pos, sizeof(buf), rc);
126 * task0 attempts GR(gid=1) -- granted immediately
127 * task1 attempts PR|PW -- blocked, goes on waiting list
128 * task2 attempts GR(gid=1) -> should be granted
129 * task2 writes to file and releases GR(gid=1)
130 * task0 waits for task2 to complete its processing
131 * task0 writes to file and releases GR(gid=1)
132 * task1 PR|PW should be granted and reads the file
134 void grouplock_test1(char *filename, int fd, int blocking_op, int unlock_op)
136 MPI_Request req1, req2;
137 int iter, flag1, flag2, temp1, temp2;
141 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
143 FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
144 filename, errno, strerror(errno));
147 MPI_Barrier(MPI_COMM_WORLD);
151 if (blocking_op == WRITE) {
153 lseek(fd, 0, SEEK_SET);
156 for (i = 0; i <= 2; i++)
159 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
162 /* Wait for task1 to progress. This could be racey. */
165 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
167 FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
168 filename, errno, strerror(errno));
172 if (unlock_op == CLOSE)
175 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
178 FAILF("%s release GROUP_LOCK of file %s: (%d) %s.\n",
179 (unlock_op == CLOSE) ? "close" : "ioctl",
180 filename, errno, strerror(errno));
182 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
185 /* PR|PW task will tell us when it completes */
186 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
187 /* 2nd locking task will tell us when it completes */
188 MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
190 /* Wait for task2 to complete. */
191 iter = MAX_WAIT_TRIES;
195 FAIL("2nd locking task is not progressing\n");
199 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
201 FAIL("PR|PW task progressed even though GROUP lock is held\n");
203 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
206 /* Make sure task1 is still waiting. */
207 iter = MAX_WAIT_TRIES;
211 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
213 FAIL("PR|PW task progressed even though GROUP lock is held\n");
218 /* Now we need to release the lock */
219 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
221 FAILF("ioctl GROUP_UNLOCK of file %s: (%d) %s.\n",
222 filename, errno, strerror(errno));
224 /* Wait for task1 to complete. */
225 iter = MAX_WAIT_TRIES;
229 FAIL("PR|PW task is not progressing even though GROUP lock was released\n");
233 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
241 * task0 attempts GR(gid=1) -- granted immediately
242 * task1 attempts GR(gid=2) -- blocked
243 * task2 attempts PR|PW -- blocked
244 * task3 attempts GR(gid=2) -- blocked
245 * task4 attempts GR(gid=1) -- should be granted
246 * task0,4 writes to file and releases GR(gid=1) --
247 * this allows task2 & 3's GR locks to be granted; task4 remains blocked.
248 * task1 & 3 write to file and release GR(gid=2)
249 * task2 PR|PW should be granted and reads the file.
251 void grouplock_test2(char *filename, int fd, int blocking_op, int unlock_op)
253 int i, iter, rc, gid = 1;
254 int flag1, flag2, flag3, flag4;
255 int temp1, temp2, temp3, temp4;
256 MPI_Request req1, req2, req3, req4;
259 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
261 FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
262 filename, errno, strerror(errno));
265 MPI_Barrier(MPI_COMM_WORLD);
269 /* Wait for task2 to issue its read request. */
270 sleep(2 * WAIT_TIME);
273 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
275 FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
276 filename, errno, strerror(errno));
280 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
283 * Do not release the locks until task 0 is ready to watch
284 * for reading task only
286 MPI_Recv(&temp1, 1, MPI_INT, 0, 1, MPI_COMM_WORLD,
289 if (unlock_op == CLOSE)
292 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
294 FAILF("%s release GROUP_LOCK of file %s: (%d) %s.\n",
295 (unlock_op == CLOSE) ? "close" : "ioctl",
296 filename, errno, strerror(errno));
299 /* Give task1 a chance to request its GR lock. */
302 if (blocking_op == WRITE) {
304 lseek(fd, 0, SEEK_SET);
307 for (i = 0; i <= 3; i++)
310 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
313 /* Give task1 & 3 a chance to queue their GR locks. */
314 sleep(3 * WAIT_TIME);
316 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
318 FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
319 filename, errno, strerror(errno));
323 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
325 FAILF("%s release GROUP_LOCK of file %s: (%d) %s.\n",
326 (unlock_op == CLOSE) ? "close" : "ioctl",
327 filename, errno, strerror(errno));
329 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
332 /* locking tasks will tell us when they complete */
333 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
334 MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
335 MPI_Irecv(&temp3, 1, MPI_INT, 3, 1, MPI_COMM_WORLD, &req3);
336 MPI_Irecv(&temp4, 1, MPI_INT, 4, 1, MPI_COMM_WORLD, &req4);
338 /* Make sure all tasks that should be blocked are waiting. */
339 iter = MAX_WAIT_TRIES;
343 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
344 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
345 MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
347 FAIL("GROUP (gid=2) task progressed even though GROUP (gid=1) lock is held.\n");
349 FAIL("PR|PW task progressed even though GROUP (gid=1) lock is still held\n");
352 /* Wait for task4 to signal it has completed. */
353 iter = MAX_WAIT_TRIES;
357 FAIL("2nd task GROUP(gid=1) not progressing\n");
360 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
361 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
362 MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
363 MPI_Test(&req4, &flag4, MPI_STATUS_IGNORE);
365 FAIL("GROUP (gid=2) task progressed even though GROUP (gid=1) lock is held.\n");
367 FAIL("PR|PW task progressed even though GROUP (gid=1) lock is still held\n");
372 /* Now let's release first lock */
373 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
375 FAILF("ioctl GROUP_UNLOCK of file %s returned %d",
378 /* Wait for task1 & 3 to signal they have their lock. */
379 iter = MAX_WAIT_TRIES;
383 FAIL("GROUP(gid=2) tasks not progressing\n");
386 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
387 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
388 MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
390 fprintf(stderr, "task2 %d\n", flag2);
391 FAIL("PR task progressed even though GROUP lock was on the queue task\n");
393 } while (!(flag1 && flag3));
395 /* Make sure task2 is still waiting. */
396 iter = MAX_WAIT_TRIES;
400 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
402 FAIL("PR task progressed even though GR(gid=2) lock was active.\n");
405 /* Tell task1 & 3 to release their GR(gid=2) lock. */
406 MPI_Send(&gid, 1, MPI_INT, 1, 1, MPI_COMM_WORLD);
407 MPI_Send(&gid, 1, MPI_INT, 3, 1, MPI_COMM_WORLD);
409 /* Wait for task2 (PR) to complete. */
410 iter = MAX_WAIT_TRIES;
414 FAIL("reading task is not progressing even though GROUP locks are released\n");
418 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
425 * Tests a bug that once existed in the group lock code;
426 * i.e. that a GR lock request on a O_NONBLOCK fd could fail even though
427 * there is no blocking GROUP lock ahead of it on the waitq.
429 * task0 starts a large write (PW). this test could be racey if this
430 * write finishes too quickly.
431 * task1 attempts GR(gid=1) -- blocked
432 * task2 attempts GR(gid=2) with a O_NONBLOCK fs. should not fail.
434 void grouplock_test3(char *filename, int fd)
436 MPI_Request req1, req2;
437 int iter, flag1, flag2, temp1, temp2;
442 } else if (rank == 2) {
443 rc = fcntl(fd, F_SETFL, O_NONBLOCK);
445 FAILF("fcntl(O_NONBLOCK) failed: (%d) %s.\n",
446 errno, strerror(errno));
449 MPI_Barrier(MPI_COMM_WORLD);
458 * Racey, we have to sleep just long enough for
459 * task0's write to start.
463 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
465 FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
466 filename, errno, strerror(errno));
468 /* tell task0 we have the lock. */
469 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
471 /* the close of fd will release the lock. */
474 rc = write(fd, lgbuf, lgbuf_size);
476 FAILF("write of file %s for %d bytes returned %d: (%d) %s.\n",
477 filename, lgbuf_size, rc, errno, strerror(errno));
478 else if (rc != lgbuf_size)
479 FAILF("write of file %s for %d bytes returned %d.\n",
480 filename, lgbuf_size, rc);
482 /* GR tasks will tell us when they complete */
483 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
484 MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
486 /* Wait for task1 & 2 to complete. */
487 iter = MAX_WAIT_TRIES;
491 FAIL("GR(gid=1) tasks are not progressing even no conflicting locks exist.\n");
495 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
496 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
497 } while (!(flag1 && flag2));
503 * Tests a bug that once existed in the group lock code;
504 * i.e. extent locks without O_NONBLOCK that go on the waitq before a group
505 * lock request came in and was granted. The extent lock would timed out and
508 * task0 starts a large write (PW). this test could be racey if this
509 * write finishes too quickly.
510 * task1 attempts PR -- blocked
511 * task2 attempts GR(gid=1) -- blocked
512 * task0 completes write
513 * task1 should wakeup and complete its read
514 * task2 should wakeup and after task1 complete.
516 void grouplock_test4(char *filename, int fd)
519 int iter, flag1, temp1;
525 MPI_Barrier(MPI_COMM_WORLD);
530 * Racey, we have to sleep just long enough for
531 * task0's write to start.
533 MPI_Recv(&temp1, 1, MPI_INT, 0, 1, MPI_COMM_WORLD,
536 /* tell task2 to go. */
537 MPI_Send(&gid, 1, MPI_INT, 2, 1, MPI_COMM_WORLD);
541 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
544 /* Give task0 & 1 a chance to start. */
545 MPI_Recv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD,
547 sleep(2 * WAIT_TIME);
549 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
551 FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
552 filename, errno, strerror(errno));
554 /* tell task0 we have the lock. */
555 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
558 * Do not release the locks until task 0 tells us too.
559 * for reading task only
561 MPI_Recv(&temp1, 1, MPI_INT, 0, 1, MPI_COMM_WORLD,
564 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
566 FAILF("ioctl GROUP_UNLOCK of file %s: (%d) %s.\n",
567 filename, errno, strerror(errno));
570 /* tell task1 to go to avoid race */
571 MPI_Send(&gid, 1, MPI_INT, 1, 1, MPI_COMM_WORLD);
572 rc = write(fd, lgbuf, lgbuf_size);
574 FAILF("write of file %s for %d bytes returned %d: (%d) %s.\n",
575 filename, lgbuf_size,
576 rc, errno, strerror(errno));
577 else if (rc != lgbuf_size)
578 FAILF("write of file %s for %d bytes returned %d.\n",
579 filename, lgbuf_size, rc);
581 /* wait for task2 to get its lock. */
582 MPI_Recv(&temp1, 1, MPI_INT, 2, 1, MPI_COMM_WORLD,
585 /* Tell task2 it's ok to release its GR(gid=1) lock. */
586 MPI_Send(&gid, 1, MPI_INT, 2, 1, MPI_COMM_WORLD);
588 /* wait a really long time. */
589 sleep(180 * WAIT_TIME);
591 /* PR task will tell us when it completes */
592 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
595 * Make sure the PR task is successful and doesn't hang.
597 * XXX - To test properly we need to make sure the read
598 * gets queued before task2's group lock request.
599 * You may need to increase lgbuf_size.
601 iter = MAX_WAIT_TRIES;
605 FAIL("PR task is hung !\n");
609 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
617 * task0 attempts GR(gid=1) -- granted
618 * task1 attempts PR on non-blocking fd -> should return -EAGAIN
619 * task2 attempts PW on non-blocking fd -> should return -EAGAIN
620 * task3 attempts GR(gid=2) on non-blocking fd -> should return -EAGAIN
622 void grouplock_nonblock_test(char *filename, int fd)
624 MPI_Request req1, req2, req3;
625 int iter, flag1, flag2, flag3, temp1, temp2, temp3;
629 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
631 FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
632 filename, errno, strerror(errno));
635 rc = fcntl(fd, F_SETFL, O_NONBLOCK);
637 FAILF("fcntl(O_NONBLOCK) failed: (%d) %s.\n",
638 errno, strerror(errno));
640 MPI_Barrier(MPI_COMM_WORLD);
644 rc = read(fd, buf, sizeof(buf));
645 if ((rc != -1) || (errno != EAGAIN))
646 FAIL("PR lock succeeded while incompatible GROUP LOCK (gid=1) is still held\n");
648 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
651 rc = write(fd, buf, sizeof(buf));
652 if ((rc != -1) || (errno != EAGAIN))
653 FAIL("PW lock succeeded while incompatible GROUP LOCK (gid=1) is still held\n");
655 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
659 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
660 if ((rc != -1) || (errno != EAGAIN))
661 FAIL("GROUP_LOCK (gid=2) succeeded while incompatible GROUP LOCK (gid=1) is still held.\n");
663 MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
666 /* reading task will tell us when it completes */
667 MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
668 /* writing task will tell us when it completes */
669 MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
670 /* 2nd locking task will tell us when it completes */
671 MPI_Irecv(&temp3, 1, MPI_INT, 3, 1, MPI_COMM_WORLD, &req3);
673 iter = MAX_WAIT_TRIES;
677 FAIL("non-blocking tasks are not progressing\n");
680 MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
681 MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
682 MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
683 } while (!(flag1 && flag2 && flag3));
685 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
687 FAILF("ioctl GROUP_UNLOCK of file %s", filename);
692 /* Just test some error paths with invalid requests */
693 void grouplock_errorstest(char *filename, int fd)
697 MPI_Barrier(MPI_COMM_WORLD);
701 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
703 FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
704 filename, errno, strerror(errno));
706 /* second group lock on same fd, same gid */
707 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
710 FAILF("Double GROUP lock failed with errno %d instead of EINVAL\n",
713 FAIL("Taking second GROUP lock on same fd succeed\n");
716 /* second group lock on same fd, different gid */
717 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid + 1);
720 FAILF("Double GROUP lock with different gid failed with errno %d instead of EINVAL\n",
723 FAIL("Taking second GROUP lock on same fd, with different gid, succeeded.\n");
726 /* GROUP unlock with wrong gid */
727 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid + 1);
730 FAILF("GROUP_UNLOCK with wrong gid failed with errno %d instead of EINVAL\n",
733 FAIL("GROUP unlock with wrong gid succeed\n");
736 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
738 FAILF("ioctl GROUP_UNLOCK of file %s returned %d.",
743 /* unlock of never locked fd */
744 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
747 FAILF("GROUP_UNLOCK on never locked fd failed with errno %d instead of EINVAL.\n",
750 FAIL("GROUP unlock on never locked fd succeed\n");
756 void grouplock_file(char *name, int subtest)
759 int flags = O_CREAT | O_RDWR | O_SYNC | O_TRUNC;
762 sprintf(filename, "%s/%s", testdir, name);
764 fd = open(filename, flags, mode);
766 FAILF("open of file %s: (%d) %s.\n",
767 filename, errno, strerror(errno));
769 MPI_Barrier(MPI_COMM_WORLD);
773 grouplock_test1(filename, fd, READ, IOCTL);
776 grouplock_test1(filename, fd, READ, CLOSE);
779 grouplock_test1(filename, fd, WRITE, IOCTL);
782 grouplock_test1(filename, fd, WRITE, CLOSE);
785 grouplock_test2(filename, fd, READ, IOCTL);
788 grouplock_test2(filename, fd, READ, CLOSE);
791 grouplock_test2(filename, fd, WRITE, IOCTL);
794 grouplock_test2(filename, fd, WRITE, CLOSE);
797 grouplock_nonblock_test(filename, fd);
800 grouplock_errorstest(filename, fd);
803 grouplock_test3(filename, fd);
806 grouplock_test4(filename, fd);
809 FAILF("wrong subtest number %d (should be <= %d)",
810 subtest, LPGL_TEST_ITEMS);
818 MPI_Barrier(MPI_COMM_WORLD);
821 void parallel_grouplock(void)
827 sprintf(teststr, "subtest %d", only_test);
829 grouplock_file("parallel_grouplock", only_test);
832 for (i = 1; i <= LPGL_TEST_ITEMS; i++) {
833 sprintf(teststr, "subtest %d", i);
835 grouplock_file("parallel_grouplock", i);
841 void usage(char *proc)
846 printf("Usage: %s [-h] -d <testdir> [-n <num>]\n", proc);
847 printf(" [-t <num>] [-v] [-V #] [-g]\n");
848 printf("\t-h: prints this help message\n");
849 printf("\t-d: the directory in which the tests will run\n");
850 printf("\t-n: repeat test # times\n");
851 printf("\t-t: run a particular test #\n");
852 printf("\t-v: increase the verbositly level by 1\n");
853 printf("\t-V: select a specific verbosity level\n");
854 printf("\t-g: debug mode\n");
863 int main(int argc, char *argv[])
865 int i, iterations = 1, c;
871 * Check for -h parameter before MPI_Init so the binary can be
872 * called directly, without, for instance, mpirun
874 for (i = 1; i < argc; ++i) {
875 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
879 MPI_Init(&argc, &argv);
880 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
881 MPI_Comm_size(MPI_COMM_WORLD, &size);
883 /* Parse command line options */
885 c = getopt(argc, argv, "d:ghn:t:vV:");
900 iterations = atoi(optarg);
903 only_test = atoi(optarg);
909 verbose = atoi(optarg);
915 printf("%s is running with %d task(es) %s\n",
916 argv[0], size, debug ? "in DEBUG mode" : "\b\b");
918 if (size < MIN_GLHOST) {
920 "Error: %d tasks run, but should be at least %d tasks to run the test!\n",
922 MPI_Abort(MPI_COMM_WORLD, 2);
925 if (!testdir && rank == 0) {
927 "Please specify a test directory! (\"%s -h\" for help)\n",
929 MPI_Abort(MPI_COMM_WORLD, 2);
934 for (i = 0; i < iterations; ++i) {
936 printf("%s: Running test #%s(iter %d)\n",
937 timestamp(), argv[0], i);
939 parallel_grouplock();
940 MPI_Barrier(MPI_COMM_WORLD);
944 printf("%s: All tests passed!\n", timestamp());