]> granicus.if.org Git - strace/commitdiff
tests: try to avoid false positives in times sanity check
authorEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 11 Oct 2019 11:36:15 +0000 (13:36 +0200)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 11 Oct 2019 11:38:42 +0000 (13:38 +0200)
Checking clock_gettime(CLOCK_PROCESS_CPUTIME_ID) starting from the
second iteration may produce false positives sometimes, try to spend
more iterations before starting checking it.

* tests/times.c (NUM_USER_ITERS_SQRT): New enum entity.
(NUM_USER_ITERS): Define via NUM_USER_ITERS_SQRT.
(main): Check i against NUM_USER_ITERS_SQRT first before checking
the returned CPU time for sanity.

tests/times.c

index 4f7e361e918e4aa5241d176463bc18e389a0b036..06a0f25789f4364c389540d242d8dcf3ccba8823 100644 (file)
@@ -24,7 +24,8 @@
 #include <sys/wait.h>
 
 enum {
-       NUM_USER_ITERS = 1000000,
+       NUM_USER_ITERS_SQRT = 1000,
+       NUM_USER_ITERS = NUM_USER_ITERS_SQRT * NUM_USER_ITERS_SQRT,
        PARENT_CPUTIME_LIMIT_NSEC = 200000000,
        CHILD_CPUTIME_LIMIT_NSEC = 300000000
 };
@@ -48,7 +49,7 @@ main(void)
                if (ts.tv_sec || ts.tv_nsec >= cputime_limit)
                        break;
 
-               if (i && !(ts.tv_sec || ts.tv_nsec))
+               if ((i > NUM_USER_ITERS_SQRT) && !(ts.tv_sec || ts.tv_nsec))
                        error_msg_and_skip("clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {0, 0})");
 
                for (i = 0; i < NUM_USER_ITERS; ++i)