Browse Source

tests: try to avoid false positives in times sanity check

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.
Eugene Syromyatnikov 1 month ago
parent
commit
c5ed146fa9
1 changed files with 3 additions and 2 deletions
  1. 3
    2
      tests/times.c

+ 3
- 2
tests/times.c View File

@@ -24,7 +24,8 @@
24 24
 #include <sys/wait.h>
25 25
 
26 26
 enum {
27
-	NUM_USER_ITERS = 1000000,
27
+	NUM_USER_ITERS_SQRT = 1000,
28
+	NUM_USER_ITERS = NUM_USER_ITERS_SQRT * NUM_USER_ITERS_SQRT,
28 29
 	PARENT_CPUTIME_LIMIT_NSEC = 200000000,
29 30
 	CHILD_CPUTIME_LIMIT_NSEC = 300000000
30 31
 };
@@ -48,7 +49,7 @@ main(void)
48 49
 		if (ts.tv_sec || ts.tv_nsec >= cputime_limit)
49 50
 			break;
50 51
 
51
-		if (i && !(ts.tv_sec || ts.tv_nsec))
52
+		if ((i > NUM_USER_ITERS_SQRT) && !(ts.tv_sec || ts.tv_nsec))
52 53
 			error_msg_and_skip("clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {0, 0})");
53 54
 
54 55
 		for (i = 0; i < NUM_USER_ITERS; ++i)

Loading…
Cancel
Save