]> granicus.if.org Git - strace/commitdiff
tests: robustify select test
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 18 Sep 2015 21:37:09 +0000 (21:37 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 19 Sep 2015 01:04:49 +0000 (04:04 +0300)
* tests/select.c: Do not include <assert.h>.
(main): Skip the test instead of assertions.
Add some padding to the timeval structure.

tests/select.c

index d345add2a3533d8af0caea69a2b90feecd34e5de..86e80c52c060385ba664e6085b4913984a05129d 100644 (file)
@@ -1,7 +1,6 @@
 /*
  * Based on test by Dr. David Alan Gilbert <dave@treblig.org>
  */
-#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -12,10 +11,17 @@ static fd_set set[0x1000000 / sizeof(fd_set)];
 int main(int ac, char **av)
 {
        int fds[2];
-       struct timeval timeout = { .tv_sec = 0, .tv_usec = 100 };
+       struct {
+               struct timeval tv;
+               int pad[2];
+       } tm = {
+               .tv = { .tv_usec = 123 },
+               .pad = { 0xdeadbeef, 0xbadc0ded }
+       };
        int is_select = ac < 2 || strcmp(av[1], "pselect6");
 
-       assert(pipe(fds) == 0);
+       if (pipe(fds))
+               return 77;
 
        /*
         * Start with a nice simple select.
@@ -23,7 +29,8 @@ int main(int ac, char **av)
        FD_ZERO(set);
        FD_SET(fds[0], set);
        FD_SET(fds[1], set);
-       assert(select(fds[1] + 1, set, set, set, NULL) == 1);
+       if (select(fds[1] + 1, set, set, set, NULL) != 1)
+               return 77;
        if (is_select)
                printf("select(%d, [%d %d], [%d %d], [%d %d], NULL) = 1 ()\n",
                       fds[1] + 1, fds[0], fds[1],
@@ -40,7 +47,8 @@ int main(int ac, char **av)
         */
        FD_ZERO(set);
        FD_SET(fds[1],set);
-       assert(select(-1, NULL, set, NULL, NULL) == -1);
+       if (select(-1, NULL, set, NULL, NULL) != -1)
+               return 77;
        if (is_select)
                printf("select(-1, NULL, %p, NULL, NULL) "
                       "= -1 EINVAL (Invalid argument)\n", set);
@@ -53,12 +61,13 @@ int main(int ac, char **av)
         */
        FD_ZERO(set);
        FD_SET(fds[0],set);
-       assert(select(FD_SETSIZE + 1, set, set + 1, NULL, &timeout) == 0);
+       if (select(FD_SETSIZE + 1, set, set + 1, NULL, &tm.tv))
+               return 77;
        if (is_select)
-               printf("select(%d, [%d], [], NULL, {0, 100}) = 0 (Timeout)\n",
+               printf("select(%d, [%d], [], NULL, {0, 123}) = 0 (Timeout)\n",
                       FD_SETSIZE + 1, fds[0]);
        else
-               printf("pselect6(%d, [%d], [], NULL, {0, 100000}, NULL) "
+               printf("pselect6(%d, [%d], [], NULL, {0, 123000}, NULL) "
                       "= 0 (Timeout)\n", FD_SETSIZE + 1, fds[0]);
 
        puts("+++ exited with 0 +++");