mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
tests/float: automated test and added pexpect script
This commit is contained in:
parent
433d2a0765
commit
c4d0f1f12e
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 <oliver.hahm@inria.fr>
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
@ -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;
|
||||
}
|
||||
|
20
tests/float/tests/01-run.py
Executable file
20
tests/float/tests/01-run.py
Executable file
@ -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))
|
Loading…
Reference in New Issue
Block a user