From 124e1dd3fadb09381b65eac744847cb98e4b300d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= <gaetan.harter@fu-berlin.de> Date: Thu, 21 Feb 2019 16:19:38 +0100 Subject: [PATCH] tests/bloom_bytes: replace %f with fmt/print_float Even if using `%f` the `printf_float` module was not used. When running the test on `samr21-xpro` and `arduino-mega2560` the float is not printed correctly. * samr21-xpro ` false positive rate.` * arduino-mega2560 `? false positive rate.` As the arduino-mega2560 does not handle printf_float use `fmt/print_float`. The output should be flushed before using fmt/print functions if available as they do not use `printf` buffer. --- tests/bloom_bytes/Makefile | 2 ++ tests/bloom_bytes/main.c | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/bloom_bytes/Makefile b/tests/bloom_bytes/Makefile index 1c4de258ca..6167da77d6 100644 --- a/tests/bloom_bytes/Makefile +++ b/tests/bloom_bytes/Makefile @@ -8,6 +8,8 @@ USEMODULE += bloom USEMODULE += random USEMODULE += xtimer +USEMODULE += fmt + DISABLE_MODULE += auto_init TEST_ON_CI_WHITELIST += all diff --git a/tests/bloom_bytes/main.c b/tests/bloom_bytes/main.c index 82288e2836..64a6e78b53 100644 --- a/tests/bloom_bytes/main.c +++ b/tests/bloom_bytes/main.c @@ -23,6 +23,7 @@ #include <inttypes.h> #include "xtimer.h" +#include "fmt.h" #include "hashes.h" #include "bloom.h" @@ -109,7 +110,14 @@ int main(void) printf("%d elements probably in the filter.\n", in); printf("%d elements not in the filter.\n", not_in); double false_positive_rate = (double) in / (double) lenA; - printf("%f false positive rate.\n", false_positive_rate); + /* Use 'fmt/print_float' to work on all platforms (atmega) + * Stdout should be flushed before to prevent garbled output. */ +#ifdef MODULE_NEWLIB + /* no fflush on msp430 */ + fflush(stdout); +#endif + print_float(false_positive_rate, 6); + puts(" false positive rate."); bloom_del(&bloom); printf("\nAll done!\n"); -- GitLab