From 27b42d34d34ff07b4cba2590c6b37eaafa15e569 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= <gaetan.harter@fu-berlin.de>
Date: Tue, 12 Feb 2019 13:46:37 +0100
Subject: [PATCH] tests/rng: replace printf_float with fmt/print_float

When running the test on `arduino-mega2560` printing the float failed
and was printed as ` ?`.

    Calculated  ? bits of entropy from 10000 samples.

Replace using `printf` floating point printing by using `fmt/print_float`.
Now the test succeeds on `arduino-mega2560`.

As `print_float` does not buffer and is used with `printf` the output
should be flushed before calling it if `fflush` is available.
---
 tests/rng/Makefile |  1 -
 tests/rng/test.c   | 10 +++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tests/rng/Makefile b/tests/rng/Makefile
index ad8461b476..3c75d2f5e3 100644
--- a/tests/rng/Makefile
+++ b/tests/rng/Makefile
@@ -8,7 +8,6 @@ BOARD_INSUFFICIENT_MEMORY += arduino-duemilanove arduino-uno
 # USEMODULE += prng_minstd
 
 USEMODULE += fmt
-USEMODULE += printf_float
 USEMODULE += random
 USEMODULE += shell
 USEMODULE += xtimer
diff --git a/tests/rng/test.c b/tests/rng/test.c
index 02555a3344..c09414b52c 100644
--- a/tests/rng/test.c
+++ b/tests/rng/test.c
@@ -382,7 +382,15 @@ void test_entropy(uint32_t samples)
     }
 
     /* print results */
-    printf("Calculated %02f bits of entropy from %" PRIu32 " samples.\n", (double) entropy, samples);
+    /* Use 'fmt/print_float' to work on all platforms (atmega)
+     * Stdout should be flushed before to prevent garbled output. */
+    printf("Calculated ");
+#ifdef MODULE_NEWLIB
+    /* no fflush on msp430 */
+    fflush(stdout);
+#endif
+    print_float(entropy, 6);
+    printf(" bits of entropy from %" PRIu32 " samples.\n", samples);
 }
 
 void cb_speed_timeout(void *arg)
-- 
GitLab