diff options
author | Lucas A. M. Magalhaes <lamm@linux.ibm.com> | 2020-07-10 19:41:06 -0300 |
---|---|---|
committer | Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com> | 2020-07-10 19:41:06 -0300 |
commit | 04deeaa9ea74b0679dfc9d9155a37b6425f19a9f (patch) | |
tree | 1c45c61f362a93a31f919fe2d428898720b59e1d /time | |
parent | 7c7bcf3634e44cf7e001aaa302138c1ee0e58f8c (diff) | |
download | glibc-04deeaa9ea74b0679dfc9d9155a37b6425f19a9f.tar.gz glibc-04deeaa9ea74b0679dfc9d9155a37b6425f19a9f.tar.xz glibc-04deeaa9ea74b0679dfc9d9155a37b6425f19a9f.zip |
Fix time/tst-cpuclock1 intermitent failures
This test fails intermittently in systems with heavy load as CLOCK_PROCESS_CPUTIME_ID is subject to scheduler pressure. Thus the test boundaries were relaxed to keep it from failing on such systems. A refactor of the spent time checking was made with some support functions. With the advantage to representing time jitter in percent of the target. The values used by the test boundaries are all empirical. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'time')
-rw-r--r-- | time/tst-cpuclock1.c | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/time/tst-cpuclock1.c b/time/tst-cpuclock1.c index 0120906f23..1ac611a92b 100644 --- a/time/tst-cpuclock1.c +++ b/time/tst-cpuclock1.c @@ -26,6 +26,7 @@ #include <signal.h> #include <stdint.h> #include <sys/wait.h> +#include <support/timespec.h> /* This function is intended to rack up both user and system time. */ static void @@ -155,16 +156,12 @@ do_test (void) printf ("live PID %d after sleep => %ju.%.9ju\n", child, (uintmax_t) after.tv_sec, (uintmax_t) after.tv_nsec); - struct timespec diff = { .tv_sec = after.tv_sec - before.tv_sec, - .tv_nsec = after.tv_nsec - before.tv_nsec }; - if (diff.tv_nsec < 0) - { - --diff.tv_sec; - diff.tv_nsec += 1000000000; - } - if (diff.tv_sec != 0 - || diff.tv_nsec > 600000000 - || diff.tv_nsec < 100000000) + /* The bound values are empirically defined by testing this code over high cpu + usage and different nice values. Of all the values we keep the 90th + percentile of values and use those values for our testing allowed range. */ + struct timespec diff = timespec_sub (support_timespec_normalize (after), + support_timespec_normalize (before)); + if (!support_timespec_check_in_range (sleeptime, diff, .9, 1.1)) { printf ("before - after %ju.%.9ju outside reasonable range\n", (uintmax_t) diff.tv_sec, (uintmax_t) diff.tv_nsec); @@ -194,19 +191,16 @@ do_test (void) } else { - struct timespec d = { .tv_sec = afterns.tv_sec - after.tv_sec, - .tv_nsec = afterns.tv_nsec - after.tv_nsec }; - if (d.tv_nsec < 0) - { - --d.tv_sec; - d.tv_nsec += 1000000000; - } - if (d.tv_sec > 0 - || d.tv_nsec < sleeptime.tv_nsec - || d.tv_nsec > sleeptime.tv_nsec * 2) + /* The bound values are empirically defined by testing this code over + high cpu usage and different nice values. Of all the values we keep + the 90th percentile of values and use those values for our testing + allowed range. */ + diff = timespec_sub (support_timespec_normalize (afterns), + support_timespec_normalize (after)); + if (!support_timespec_check_in_range (sleeptime, diff, .9, 1.2)) { printf ("nanosleep time %ju.%.9ju outside reasonable range\n", - (uintmax_t) d.tv_sec, (uintmax_t) d.tv_nsec); + (uintmax_t) diff.tv_sec, (uintmax_t) diff.tv_nsec); result = 1; } } @@ -240,15 +234,13 @@ do_test (void) /* Should be close to 0.6. */ printf ("dead PID %d => %ju.%.9ju\n", child, (uintmax_t) dead.tv_sec, (uintmax_t) dead.tv_nsec); - - diff.tv_sec = dead.tv_sec - after.tv_sec; - diff.tv_nsec = dead.tv_nsec - after.tv_nsec; - if (diff.tv_nsec < 0) - { - --diff.tv_sec; - diff.tv_nsec += 1000000000; - } - if (diff.tv_sec != 0 || diff.tv_nsec > 200000000) + /* The bound values are empirically defined by testing this code over high cpu + usage and different nice values. Of all the values we keep the 90th + percentile of values and use those values for our testing allowed range. */ + diff = timespec_sub (support_timespec_normalize (dead), + support_timespec_normalize (after)); + sleeptime.tv_nsec = 100000000; + if (!support_timespec_check_in_range (sleeptime, diff, .9, 1.2)) { printf ("dead - after %ju.%.9ju outside reasonable range\n", (uintmax_t) diff.tv_sec, (uintmax_t) diff.tv_nsec); |