generic/478: fix potential test blocking
authorXiong Zhou <xzhou@redhat.com>
Fri, 23 Mar 2018 02:49:37 +0000 (10:49 +0800)
committerEryu Guan <guaneryu@gmail.com>
Fri, 23 Mar 2018 06:06:33 +0000 (14:06 +0800)
Reduce semtimedop timeout to 5s, 15s is too long if something get
tangled up. Add retry counting to getlk routine, infinite loop is
dangerous. If something goes wrong unexpextedly, test is blocked and
wasting time.

Signed-off-by: Xiong Zhou <xzhou@redhat.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
src/t_ofd_locks.c

index d578cd71fd1ba929401c4b9c79a95bb105ad7d0d..e3b15ddc6ee871aeaf972a59c0d0b69b9f54c2f0 100644 (file)
@@ -317,14 +317,14 @@ int main(int argc, char **argv)
                sop.sem_num = 0;
                sop.sem_op = 1;
                sop.sem_flg = 0;
-               ts.tv_sec = 15;
+               ts.tv_sec = 5;
                ts.tv_nsec = 0;
                if (semtimedop(semid, &sop, 1, &ts) == -1)
                        err_exit("inc sem0 2", errno);
                sop.sem_num = 1;
                sop.sem_op = 1;
                sop.sem_flg = 0;
-               ts.tv_sec = 15;
+               ts.tv_sec = 5;
                ts.tv_nsec = 0;
                if (semtimedop(semid, &sop, 1, &ts) == -1)
                        err_exit("inc sem1 2", errno);
@@ -376,7 +376,7 @@ int main(int argc, char **argv)
                sop.sem_num = 1;
                sop.sem_op = 0;
                sop.sem_flg = 0;
-               ts.tv_sec = 15;
+               ts.tv_sec = 5;
                ts.tv_nsec = 0;
                if (semtimedop(semid, &sop, 1, &ts) == -1)
                        err_exit("wait sem1 0", errno);
@@ -391,14 +391,18 @@ int main(int argc, char **argv)
        /* getlck */
        if (lock_cmd == 0) {
                /* wait sem created and initialized */
+               retry = 5;
                do {
                        semid = semget(semkey, 2, 0);
                        if (semid != -1)
                                break;
-                       if (errno == ENOENT)
+                       if (errno == ENOENT && retry) {
+                               sleep(1);
+                               retry--;
                                continue;
-                       else
+                       } else {
                                err_exit("getlk_semget", errno);
+                       }
                } while (1);
                do {
                        memset(&sem_ds, 0, sizeof(sem_ds));
@@ -410,7 +414,7 @@ int main(int argc, char **argv)
                sop.sem_num = 0;
                sop.sem_op = 0;
                sop.sem_flg = 0;
-               ts.tv_sec = 15;
+               ts.tv_sec = 5;
                ts.tv_nsec = 0;
                if (semtimedop(semid, &sop, 1, &ts) == -1)
                        err_exit("wait sem0 0", errno);