]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Remove unreliable parts of rt/tst-cpuclock2
authorDJ Delorie <dj@redhat.com>
Tue, 5 Oct 2021 18:52:05 +0000 (14:52 -0400)
committerDJ Delorie <dj@redhat.com>
Fri, 8 Oct 2021 02:38:49 +0000 (22:38 -0400)
This is a follow-up to the tst-cpuclock1.c change here:
9a29f1a2ae3d4bb253ee368e0d71db0ca9494120

This test, like tst-cpuclock1, may fail on heavily loaded VM
servers (and has occasionally failed on the 32bit trybot),
so tests that rely on "wall time" have been removed.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
rt/tst-cpuclock2.c

index eebc3609d0aa88dadf24137ad4c8461deef38617..32a1b75c2f3f5d18b9276cc12784bd5c7d8287d1 100644 (file)
@@ -62,22 +62,9 @@ chew_cpu (void *arg)
   return NULL;
 }
 
-static unsigned long long int
-tsdiff (const struct timespec *before, const struct timespec *after)
-{
-  struct timespec diff = { .tv_sec = after->tv_sec - before->tv_sec,
-                          .tv_nsec = after->tv_nsec - before->tv_nsec };
-  while (diff.tv_nsec < 0)
-    {
-      --diff.tv_sec;
-      diff.tv_nsec += 1000000000;
-    }
-  return diff.tv_sec * 1000000000ULL + diff.tv_nsec;
-}
-
-static unsigned long long int
+static void
 test_nanosleep (clockid_t clock, const char *which,
-               const struct timespec *before, int *bad)
+               int *bad)
 {
   const struct timespec sleeptime = { .tv_nsec = 100000000 };
   int e = clock_nanosleep (clock, 0, &sleeptime, NULL);
@@ -85,13 +72,13 @@ test_nanosleep (clockid_t clock, const char *which,
     {
       printf ("clock_nanosleep not supported for %s CPU clock: %s\n",
              which, strerror (e));
-      return 0;
+      return;
     }
   if (e != 0)
     {
       printf ("clock_nanosleep on %s CPU clock: %s\n", which, strerror (e));
       *bad = 1;
-      return 0;
+      return;
     }
 
   struct timespec after;
@@ -100,16 +87,7 @@ test_nanosleep (clockid_t clock, const char *which,
       printf ("clock_gettime on %s CPU clock %lx => %s\n",
              which, (unsigned long int) clock, strerror (errno));
       *bad = 1;
-      return 0;
-    }
-
-  unsigned long long int diff = tsdiff (before, &after);
-  if (diff < sleeptime.tv_nsec || diff > sleeptime.tv_nsec * 2)
-    {
-      printf ("clock_nanosleep on %s slept %llu (outside reasonable range)\n",
-             which, diff);
-      *bad = 1;
-      return diff;
+      return;
     }
 
   struct timespec sleeptimeabs = sleeptime;
@@ -126,7 +104,7 @@ test_nanosleep (clockid_t clock, const char *which,
       printf ("absolute clock_nanosleep on %s CPU clock: %s\n",
              which, strerror (e));
       *bad = 1;
-      return diff;
+      return;
     }
 
   struct timespec afterabs;
@@ -135,28 +113,10 @@ test_nanosleep (clockid_t clock, const char *which,
       printf ("clock_gettime on %s CPU clock %lx => %s\n",
              which, (unsigned long int) clock, strerror (errno));
       *bad = 1;
-      return diff;
-    }
-
-  unsigned long long int sleepdiff = tsdiff (&sleeptimeabs, &afterabs);
-  if (sleepdiff > sleeptime.tv_nsec)
-    {
-      printf ("\
-absolute clock_nanosleep on %s %llu past target (outside reasonable range)\n",
-             which, sleepdiff);
-      *bad = 1;
+      return;
     }
 
-  unsigned long long int diffabs = tsdiff (&after, &afterabs);
-  if (diffabs < sleeptime.tv_nsec || diffabs > sleeptime.tv_nsec * 2)
-    {
-      printf ("\
-absolute clock_nanosleep on %s slept %llu (outside reasonable range)\n",
-             which, diffabs);
-      *bad = 1;
-    }
-
-  return diff + diffabs;
+  return;
 }
 
 
@@ -290,37 +250,12 @@ do_test (void)
   printf ("self thread after sleep => %ju.%.9ju\n",
          (uintmax_t) me_after.tv_sec, (uintmax_t) me_after.tv_nsec);
 
-  unsigned long long int th_diff = tsdiff (&before, &after);
-  unsigned long long int pdiff = tsdiff (&process_before, &process_after);
-  unsigned long long int my_diff = tsdiff (&me_before, &me_after);
-
-  if (th_diff < 100000000 || th_diff > 600000000)
-    {
-      printf ("live thread before - after %llu outside reasonable range\n",
-             th_diff);
-      result = 1;
-    }
-
-  if (my_diff > 100000000)
-    {
-      printf ("self thread before - after %llu outside reasonable range\n",
-             my_diff);
-      result = 1;
-    }
-
-  if (pdiff < th_diff)
-    {
-      printf ("process before - after %llu outside reasonable range (%llu)\n",
-             pdiff, th_diff);
-      result = 1;
-    }
-
-  process_after.tv_nsec += test_nanosleep (th_clock, "live thread",
-                                          &after, &result);
-  process_after.tv_nsec += test_nanosleep (process_clock, "process",
-                                          &process_after, &result);
+  test_nanosleep (th_clock, "live thread",
+                 &result);
+  test_nanosleep (process_clock, "process",
+                 &result);
   test_nanosleep (CLOCK_PROCESS_CPUTIME_ID,
-                 "PROCESS_CPUTIME_ID", &process_after, &result);
+                 "PROCESS_CPUTIME_ID", &result);
 
   pthread_cancel (th);