mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/pkg_libfixmath: refactor test and automatic script
Print the range of iterations for each subtests and catch the value in the Python script. The number of iterations is reduced on boards that are not native, this is because this test takes a lot of time on slow platforms
This commit is contained in:
parent
326f5f1d12
commit
07f7ac5829
@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "kernel_defines.h"
|
||||
#include "fix16.h"
|
||||
@ -59,8 +60,20 @@ static void binary_ops(void)
|
||||
{ "max", fix16_max },
|
||||
};
|
||||
|
||||
for (fix16_t a = fix16_from_dbl(-5.0); a < fix16_from_dbl(5.0); a += fix16_from_dbl(0.25)) {
|
||||
for (fix16_t b = fix16_from_dbl(-5.0); b < fix16_from_dbl(5.0); b += fix16_from_dbl(0.25)) {
|
||||
#ifdef BOARD_NATIVE
|
||||
fix16_t _min = fix16_from_dbl(-5.0);
|
||||
fix16_t _max = fix16_from_dbl(5.0);
|
||||
fix16_t _step = fix16_from_dbl(0.25);
|
||||
#else
|
||||
fix16_t _min = fix16_from_dbl(-2.0);
|
||||
fix16_t _max = fix16_from_dbl(2.0);
|
||||
fix16_t _step = fix16_from_dbl(0.25);
|
||||
#endif
|
||||
|
||||
uint16_t _range = (uint16_t)((fix16_to_int(_max) - fix16_to_int(_min)) / fix16_to_dbl(_step));
|
||||
printf("COUNT: %u\n", (unsigned)(_range * (_range - 1)));
|
||||
for (fix16_t a = _min; a < _max; a += _step) {
|
||||
for (fix16_t b = _min; b < _max; b += _step) {
|
||||
if (b == 0) {
|
||||
continue;
|
||||
}
|
||||
@ -95,8 +108,18 @@ static void unary_ops(void)
|
||||
|
||||
{ "exp", fix16_exp },
|
||||
};
|
||||
|
||||
for (fix16_t input = fix16_from_dbl(-10.0); input < fix16_from_dbl(+10.0); input += fix16_from_dbl(0.25)) {
|
||||
#ifdef BOARD_NATIVE
|
||||
fix16_t _min = fix16_from_dbl(-10.0);
|
||||
fix16_t _max = fix16_from_dbl(10.0);
|
||||
fix16_t _step = fix16_from_dbl(0.25);
|
||||
#else
|
||||
fix16_t _min = fix16_from_dbl(-2.0);
|
||||
fix16_t _max = fix16_from_dbl(2.0);
|
||||
fix16_t _step = fix16_from_dbl(0.25);
|
||||
#endif
|
||||
uint8_t _count = (uint8_t)((fix16_to_int(_max) - fix16_to_int(_min)) / fix16_to_dbl(_step));
|
||||
printf("COUNT: %d\n", _count);
|
||||
for (fix16_t input = _min; input < _max; input += _step) {
|
||||
for (unsigned o = 0; o < ARRAY_SIZE(ops); ++o) {
|
||||
fix16_t result = ops[o].fun(input);
|
||||
|
||||
@ -121,7 +144,16 @@ static void unary_ops(void)
|
||||
{ "tan", fix16_tan },
|
||||
};
|
||||
|
||||
for (fix16_t input = fix16_from_dbl(-M_PI/2); input < fix16_from_dbl(+M_PI/2); input += fix16_from_dbl(0.05)) {
|
||||
fix16_t _min = fix16_from_dbl(-M_PI/2);
|
||||
fix16_t _max = fix16_from_dbl(+M_PI/2);
|
||||
#ifdef BOARD_NATIVE
|
||||
fix16_t _step = fix16_from_dbl(0.05);
|
||||
#else
|
||||
fix16_t _step = fix16_from_dbl(0.1);
|
||||
#endif
|
||||
uint8_t _count = (uint8_t)((fix16_to_dbl(_max) - fix16_to_dbl(_min)) / fix16_to_dbl(_step));
|
||||
printf("COUNT: %d\n", _count);
|
||||
for (fix16_t input = _min; input < _max; input += _step) {
|
||||
for (unsigned o = 0; o < ARRAY_SIZE(ops); ++o) {
|
||||
fix16_t result = ops[o].fun(input);
|
||||
|
||||
@ -144,7 +176,16 @@ static void unary_ops(void)
|
||||
{ "acos", fix16_acos },
|
||||
};
|
||||
|
||||
for (fix16_t input = fix16_from_dbl(-1.0); input < fix16_from_dbl(+1.0); input += fix16_from_dbl(0.05)) {
|
||||
fix16_t _min = fix16_from_dbl(-1.0);
|
||||
fix16_t _max = fix16_from_dbl(1.0);
|
||||
#ifdef BOARD_NATIVE
|
||||
fix16_t _step = fix16_from_dbl(0.05);
|
||||
#else
|
||||
fix16_t _step = fix16_from_dbl(0.2);
|
||||
#endif
|
||||
uint8_t _count = (uint8_t)((fix16_to_int(_max) - fix16_to_int(_min)) / fix16_to_dbl(_step));
|
||||
printf("COUNT: %d\n", _count);
|
||||
for (fix16_t input = _min; input < _max; input += _step) {
|
||||
for (unsigned o = 0; o < ARRAY_SIZE(ops); ++o) {
|
||||
fix16_t result = ops[o].fun(input);
|
||||
|
||||
@ -170,7 +211,18 @@ static void unary_ops(void)
|
||||
{ "slog2", fix16_slog2 },
|
||||
};
|
||||
|
||||
for (fix16_t input = fix16_from_dbl(0.05); input < fix16_from_dbl(+10.0); input += fix16_from_dbl(0.25)) {
|
||||
#ifdef BOARD_NATIVE
|
||||
fix16_t _min = fix16_from_dbl(0.05);
|
||||
fix16_t _max = fix16_from_dbl(+10.0);
|
||||
fix16_t _step = fix16_from_dbl(0.25);
|
||||
#else
|
||||
fix16_t _min = fix16_from_dbl(0.05);
|
||||
fix16_t _max = fix16_from_dbl(+5.0);
|
||||
fix16_t _step = fix16_from_dbl(0.25);
|
||||
#endif
|
||||
uint8_t _count = (uint8_t)((fix16_to_int(_max) - fix16_to_int(_min)) / fix16_to_dbl(_step));
|
||||
printf("COUNT: %d\n", _count);
|
||||
for (fix16_t input = _min; input < _max; input += _step) {
|
||||
for (unsigned o = 0; o < ARRAY_SIZE(ops); ++o) {
|
||||
fix16_t result = ops[o].fun(input);
|
||||
|
||||
|
@ -5,25 +5,40 @@ from testrunner import run, test_utils_interactive_sync
|
||||
|
||||
|
||||
def expect_unary(child):
|
||||
for _ in range(20):
|
||||
child.expect(r'COUNT: (\d+)')
|
||||
count = int(child.match.group(1))
|
||||
assert count > 0
|
||||
for _ in range(count):
|
||||
for op_name in ('abs', 'sq', 'atan', 'exp'):
|
||||
child.expect(r'{}\(-?\d+\.\d+\) = -?\d+\.\d+'.format(op_name))
|
||||
|
||||
for _ in range(20):
|
||||
child.expect(r'COUNT: (\d+)')
|
||||
count = int(child.match.group(1))
|
||||
assert count > 0
|
||||
for _ in range(count):
|
||||
for op_name in ('sin', 'cos', 'tan'):
|
||||
child.expect(r'{}\(-?\d+.\d+\) = -?\d+.\d+'.format(op_name))
|
||||
|
||||
for _ in range(20):
|
||||
child.expect(r'COUNT: (\d+)')
|
||||
count = int(child.match.group(1))
|
||||
assert count > 0
|
||||
for _ in range(count):
|
||||
for op_name in ('asin', 'acos'):
|
||||
child.expect(r'{}\(-?\d+.\d+\) = -?\d+.\d+'.format(op_name))
|
||||
|
||||
for _ in range(20):
|
||||
child.expect(r'COUNT: (\d+)')
|
||||
count = int(child.match.group(1))
|
||||
assert count > 0
|
||||
for _ in range(count):
|
||||
for op_name in ('sqrt', 'log', 'log2', 'slog2'):
|
||||
child.expect(r'{}\(-?\d+.\d+\) = -?\d+.\d+'.format(op_name))
|
||||
|
||||
|
||||
def expect_binary(child):
|
||||
for _ in range(1500):
|
||||
child.expect(r'COUNT: (\d+)')
|
||||
count = int(child.match.group(1))
|
||||
assert count > 0
|
||||
for _ in range(count):
|
||||
for op_name in ('add', 'sub', 'mul', 'div', 'mod', 'sadd', 'ssub',
|
||||
'smul', 'sdiv', 'min', 'max'):
|
||||
child.expect(r'{}\(-?\d+.\d+\, -?\d+.\d+\) = -?\d+.\d+'
|
||||
|
Loading…
Reference in New Issue
Block a user