diff --git a/tests/float/Makefile b/tests/float/Makefile index 09cdd4d62f..e861437e5b 100644 --- a/tests/float/Makefile +++ b/tests/float/Makefile @@ -3,4 +3,12 @@ include ../Makefile.tests_common DISABLE_MODULE += auto_init +# for native we can go do a couple of more operations in reasonable time... +ifneq (,$(filter native,$(BOARD))) + CFLAGS += -DTEST_ITER=100000000 +endif + include $(RIOTBASE)/Makefile.include + +test: + tests/01-run.py diff --git a/tests/float/README.md b/tests/float/README.md index b136c6e325..fe9a3bfc10 100644 --- a/tests/float/README.md +++ b/tests/float/README.md @@ -1,10 +1,14 @@ Expected result =============== -This application should infinitely print '-' characters. If it prints only a single '+' characters the test must be considered as failed. +This application increases a non-even floating point number in steps of 0.1 +starting from from 1234567.0 / 1024.0 ~= 1205.631835938. For each step it checks +if the sum minus its 'floored' values is less than 1.0 (which it should always be +by definition of `floor`). Background ========== -This test was introduced due to an error for floating point handling in an older newlib version. +This test was introduced due to an error for floating point handling in an older +newlib version. The idea for this test is taken from: http://sourceware.org/ml/newlib/2010/msg00149.html diff --git a/tests/float/main.c b/tests/float/main.c index 043e6590dc..35c3cbfacb 100644 --- a/tests/float/main.c +++ b/tests/float/main.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 INRIA + * 2017 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -7,13 +8,14 @@ */ /** - * @ingroup tests + * @ingroup tests * @{ * * @file - * @brief Float test application + * @brief Float test application * * @author Oliver Hahm + * @author Hauke Petersen * * @} */ @@ -23,19 +25,29 @@ #include "board.h" +/* as default we run the test 100k times */ +#ifndef TEST_ITER +#define TEST_ITER (100000UL) +#endif + +#define STEP (0.1) + int main(void) { double x = 1234567.0 / 1024.0; - while (1) { - x += 0.1; - double z = x - floor(x); + puts("Testing floating point arithmetics...\n"); - if (z >= 1) { - putchar('+'); - } - else { - putchar('-'); + for (unsigned long i = 0; i < TEST_ITER; i++) { + x += STEP; + double z = (x - floor(x)); + if (z >= 1.0) { + puts("[FAILED]"); + return 1; } } + + puts("[SUCCESS]"); + + return 0; } diff --git a/tests/float/tests/01-run.py b/tests/float/tests/01-run.py new file mode 100755 index 0000000000..07987991a5 --- /dev/null +++ b/tests/float/tests/01-run.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2017 Freie Universität Berlin +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import os +import sys + +sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) +import testrunner + +def testfunc(child): + child.expect_exact("Testing floating point arithmetics...") + child.expect_exact("[SUCCESS]") + +if __name__ == "__main__": + sys.exit(testrunner.run(testfunc))