selftests/timers: Add missing fflush(stdout) calls [Linux 5.2]

selftests/timers: Add missing fflush(stdout) calls [Linux 5.2]

This Linux kernel change "selftests/timers: Add missing fflush(stdout) calls" is included in the Linux 5.2 release. This change is authored by Kees Cook <keescook [at] chromium.org> on Mon May 20 15:37:49 2019 -0700. The commit for this change in Linux stable tree is fe48319 (patch).

selftests/timers: Add missing fflush(stdout) calls

When running under a pipe, some timer tests would not report output in
real-time because stdout flushes were missing after printf()s that lacked
a newline. This adds them to restore real-time status output that humans
can enjoy.

Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>

There are 12 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 tools/testing/selftests/timers/adjtick.c        | 1 +
 tools/testing/selftests/timers/leapcrash.c      | 1 +
 tools/testing/selftests/timers/mqueue-lat.c     | 1 +
 tools/testing/selftests/timers/nanosleep.c      | 1 +
 tools/testing/selftests/timers/nsleep-lat.c     | 1 +
 tools/testing/selftests/timers/raw_skew.c       | 1 +
 tools/testing/selftests/timers/set-tai.c        | 1 +
 tools/testing/selftests/timers/set-tz.c         | 2 ++
 tools/testing/selftests/timers/threadtest.c     | 1 +
 tools/testing/selftests/timers/valid-adjtimex.c | 2 ++
 10 files changed, 12 insertions(+)

diff --git a/tools/testing/selftests/timers/adjtick.c b/tools/testing/selftests/timers/adjtick.c
index 0caca3a..54d8d87 100644
--- a/tools/testing/selftests/timers/adjtick.c
+++ b/tools/testing/selftests/timers/adjtick.c
@@ -136,6 +136,7 @@ int check_tick_adj(long tickval)

    eppm = get_ppm_drift();
    printf("%lld usec, %lld ppm", systick + (systick * eppm / MILLION), eppm);
+   fflush(stdout);

    tx1.modes = 0;
    adjtimex(&tx1);
diff --git a/tools/testing/selftests/timers/leapcrash.c b/tools/testing/selftests/timers/leapcrash.c
index 830c462..dc80728 100644
--- a/tools/testing/selftests/timers/leapcrash.c
+++ b/tools/testing/selftests/timers/leapcrash.c
@@ -101,6 +101,7 @@ int main(void)
        }
        clear_time_state();
        printf(".");
+       fflush(stdout);
    }
    printf("[OK]\n");
    return ksft_exit_pass();
diff --git a/tools/testing/selftests/timers/mqueue-lat.c b/tools/testing/selftests/timers/mqueue-lat.c
index 1867db5..7916cf5 100644
--- a/tools/testing/selftests/timers/mqueue-lat.c
+++ b/tools/testing/selftests/timers/mqueue-lat.c
@@ -102,6 +102,7 @@ int main(int argc, char **argv)
    int ret;

    printf("Mqueue latency :                          ");
+   fflush(stdout);

    ret = mqueue_lat_test();
    if (ret < 0) {
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 8adb0bb..71b5441 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -142,6 +142,7 @@ int main(int argc, char **argv)
            continue;

        printf("Nanosleep %-31s ", clockstring(clockid));
+       fflush(stdout);

        length = 10;
        while (length <= (NSEC_PER_SEC * 10)) {
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index c3c3dc1..eb3e79e 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -155,6 +155,7 @@ int main(int argc, char **argv)
            continue;

        printf("nsleep latency %-26s ", clockstring(clockid));
+       fflush(stdout);

        length = 10;
        while (length <= (NSEC_PER_SEC * 10)) {
diff --git a/tools/testing/selftests/timers/raw_skew.c b/tools/testing/selftests/timers/raw_skew.c
index dcf73c5..b41d8dd 100644
--- a/tools/testing/selftests/timers/raw_skew.c
+++ b/tools/testing/selftests/timers/raw_skew.c
@@ -112,6 +112,7 @@ int main(int argv, char **argc)
        printf("WARNING: ADJ_OFFSET in progress, this will cause inaccurate results\n");

    printf("Estimating clock drift: ");
+   fflush(stdout);
    sleep(120);

    get_monotonic_and_raw(&mon, &raw);
diff --git a/tools/testing/selftests/timers/set-tai.c b/tools/testing/selftests/timers/set-tai.c
index 70fed27..8c4179e 100644
--- a/tools/testing/selftests/timers/set-tai.c
+++ b/tools/testing/selftests/timers/set-tai.c
@@ -55,6 +55,7 @@ int main(int argc, char **argv)
    printf("tai offset started at %i\n", ret);

    printf("Checking tai offsets can be properly set: ");
+   fflush(stdout);
    for (i = 1; i <= 60; i++) {
        ret = set_tai(i);
        ret = get_tai();
diff --git a/tools/testing/selftests/timers/set-tz.c b/tools/testing/selftests/timers/set-tz.c
index 877fd55..62bd33e 100644
--- a/tools/testing/selftests/timers/set-tz.c
+++ b/tools/testing/selftests/timers/set-tz.c
@@ -65,6 +65,7 @@ int main(int argc, char **argv)
    printf("tz_minuteswest started at %i, dst at %i\n", min, dst);

    printf("Checking tz_minuteswest can be properly set: ");
+   fflush(stdout);
    for (i = -15*60; i < 15*60; i += 30) {
        ret = set_tz(i, dst);
        ret = get_tz_min();
@@ -76,6 +77,7 @@ int main(int argc, char **argv)
    printf("[OK]\n");

    printf("Checking invalid tz_minuteswest values are caught: ");
+   fflush(stdout);

    if (!set_tz(-15*60-1, dst)) {
        printf("[FAILED] %i didn't return failure!\n", -15*60-1);
diff --git a/tools/testing/selftests/timers/threadtest.c b/tools/testing/selftests/timers/threadtest.c
index 759c9c0..cf3e489 100644
--- a/tools/testing/selftests/timers/threadtest.c
+++ b/tools/testing/selftests/timers/threadtest.c
@@ -163,6 +163,7 @@ int main(int argc, char **argv)
    strftime(buf, 255, "%a, %d %b %Y %T %z", localtime(&start));
    printf("%s\n", buf);
    printf("Testing consistency with %i threads for %ld seconds: ", thread_count, runtime);
+   fflush(stdout);

    /* spawn */
    for (i = 0; i < thread_count; i++)
diff --git a/tools/testing/selftests/timers/valid-adjtimex.c b/tools/testing/selftests/timers/valid-adjtimex.c
index d9d3ab9..5397de7 100644
--- a/tools/testing/selftests/timers/valid-adjtimex.c
+++ b/tools/testing/selftests/timers/valid-adjtimex.c
@@ -123,6 +123,7 @@ int validate_freq(void)
    /* Set the leap second insert flag */

    printf("Testing ADJ_FREQ... ");
+   fflush(stdout);
    for (i = 0; i < NUM_FREQ_VALID; i++) {
        tx.modes = ADJ_FREQUENCY;
        tx.freq = valid_freq[i];
@@ -250,6 +251,7 @@ int set_bad_offset(long sec, long usec, int use_nano)
 int validate_set_offset(void)
 {
    printf("Testing ADJ_SETOFFSET... ");
+   fflush(stdout);

    /* Test valid values */
    if (set_offset(NSEC_PER_SEC - 1, 1))

Leave a Reply

Your email address will not be published. Required fields are marked *