Merge pull request #12687 from aabadie/pr/pkg/libfixmath_update

pkg/libfixmath: several improvements and 8bit fix
This commit is contained in:
Alexandre Abadie 2019-11-21 09:55:29 +01:00 committed by GitHub
commit 8f90da6040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 200 additions and 344 deletions

View File

@ -6,6 +6,7 @@ PKG_LICENSE := MIT
.PHONY: all
all:
$(Q)"$(MAKE)" -C $(PKG_BUILDDIR)
$(Q)cp $(CURDIR)/Makefile.$(PKG_NAME) $(PKG_BUILDDIR)/$(PKG_NAME)/Makefile
$(Q)cp $(CURDIR)/Makefile.$(PKG_NAME)-unittests $(PKG_BUILDDIR)/unittests/Makefile
include $(RIOTBASE)/pkg/pkg.mk

View File

@ -0,0 +1,8 @@
ifneq (,$(filter libfixmath-unittests,$(USEMODULE)))
# libfixmath unittests use shift operand incompatible with 8bit
# architecture int type.
FEATURES_BLACKLIST += arch_8bit
# The round function is not provided by the msp430 toolchain
FEATURES_BLACKLIST += arch_msp430
endif

View File

@ -3,8 +3,14 @@ PKG_BUILDDIR ?= $(PKGDIRBASE)/libfixmath
# The static cache is huge, disable it.
CFLAGS += -DFIXMATH_NO_CACHE
ifneq (,$(filter arch_8bit,$(FEATURES_USED)))
CFLAGS += -DFIXMATH_OPTIMIZE_8BIT
endif
DIRS += $(PKG_BUILDDIR)/libfixmath
INCLUDES += -I$(PKG_BUILDDIR)/libfixmath
ifneq (,$(filter libfixmath-unittests,$(USEMODULE)))
DIRS += $(PKG_BUILDDIR)/unittests
INCLUDES += -I$(PKG_BUILDDIR)/unittests
endif

View File

@ -0,0 +1,3 @@
MODULE = libfixmath
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,3 @@
MODULE = libfixmath-unittests
include $(RIOTBASE)/Makefile.base

View File

@ -1,22 +1,20 @@
From 14eaa181746c7fe54b554a9dd98c2c37fd41b5bd Mon Sep 17 00:00:00 2001
From 7bcfa3205fc5f36445cc9b03d400278be2dad673 Mon Sep 17 00:00:00 2001
From: Martine Lenders <mail@martine-lenders.eu>
Date: Thu, 12 May 2016 16:07:35 +0200
Subject: [PATCH 2/4] Fix warnings
Subject: [PATCH] Fix warnings
---
libfixmath/fix16_str.c | 8 ++++----
libfixmath/uint32.c | 10 +++++-----
unittests/libfixmath-unittests.h | 18 ++++++++++++++++++
unittests/unittests.h | 18 ------------------
4 files changed, 27 insertions(+), 27 deletions(-)
create mode 100644 unittests/libfixmath-unittests.h
delete mode 100644 unittests/unittests.h
libfixmath/fix16_str.c | 8 ++++----
libfixmath/uint32.c | 10 +++++-----
unittests/{unittests.h => libfixmath-unittests.h} | 1 -
3 files changed, 9 insertions(+), 10 deletions(-)
rename unittests/{unittests.h => libfixmath-unittests.h} (99%)
diff --git a/libfixmath/fix16_str.c b/libfixmath/fix16_str.c
index eff906f..2c02c21 100644
index 07df864..f533907 100644
--- a/libfixmath/fix16_str.c
+++ b/libfixmath/fix16_str.c
@@ -59,7 +59,7 @@ void fix16_to_str(fix16_t value, char *buf, int decimals)
@@ -71,7 +71,7 @@ void fix16_to_str(fix16_t value, char *buf, int decimals)
fix16_t fix16_from_str(const char *buf)
{
@ -25,7 +23,7 @@ index eff906f..2c02c21 100644
buf++;
/* Decode the sign */
@@ -70,7 +70,7 @@ fix16_t fix16_from_str(const char *buf)
@@ -82,7 +82,7 @@ fix16_t fix16_from_str(const char *buf)
/* Decode the integer part */
uint32_t intpart = 0;
int count = 0;
@ -34,7 +32,7 @@ index eff906f..2c02c21 100644
{
intpart *= 10;
intpart += *buf++ - '0';
@@ -90,7 +90,7 @@ fix16_t fix16_from_str(const char *buf)
@@ -102,7 +102,7 @@ fix16_t fix16_from_str(const char *buf)
uint32_t fracpart = 0;
uint32_t scale = 1;
@ -43,7 +41,7 @@ index eff906f..2c02c21 100644
{
scale *= 10;
fracpart *= 10;
@@ -103,7 +103,7 @@ fix16_t fix16_from_str(const char *buf)
@@ -115,7 +115,7 @@ fix16_t fix16_from_str(const char *buf)
/* Verify that there is no garbage left over */
while (*buf != '\0')
{
@ -72,54 +70,18 @@ index 2980ab9..855774d 100644
+ if(inVal >= ((uint32_t) 1 << 1)) { tempOut += 1; }
return tempOut;
}
diff --git a/unittests/libfixmath-unittests.h b/unittests/libfixmath-unittests.h
new file mode 100644
index 0000000..bac57d2
--- /dev/null
+++ b/unittests/libfixmath-unittests.h
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+#define COMMENT(x) printf("\n----" x "----\n");
+#define STR(x) #x
+#define STR2(x) STR(x)
+#define TEST(x) \
+ if (!(x)) { \
+ fflush(stdout); \
+ fflush(stderr); \
+ fprintf(stderr, "\033[31;1mFAILED:\033[22;39m " __FILE__ ":" STR2(__LINE__) " " #x "\n"); \
+ status = 1; \
+ } else { \
+ fflush(stdout); \
+ fflush(stderr); \
+ printf("\033[32;1mOK:\033[22;39m " #x "\n"); \
+ }
+
+
diff --git a/unittests/unittests.h b/unittests/unittests.h
deleted file mode 100644
index bac57d2..0000000
diff --git a/unittests/unittests.h b/unittests/libfixmath-unittests.h
similarity index 99%
rename from unittests/unittests.h
rename to unittests/libfixmath-unittests.h
index bac57d2..57ad8f8 100644
--- a/unittests/unittests.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <stdio.h>
-
-#define COMMENT(x) printf("\n----" x "----\n");
-#define STR(x) #x
-#define STR2(x) STR(x)
-#define TEST(x) \
- if (!(x)) { \
- fflush(stdout); \
- fflush(stderr); \
- fprintf(stderr, "\033[31;1mFAILED:\033[22;39m " __FILE__ ":" STR2(__LINE__) " " #x "\n"); \
- status = 1; \
- } else { \
- fflush(stdout); \
- fflush(stderr); \
- printf("\033[32;1mOK:\033[22;39m " #x "\n"); \
- }
-
+++ b/unittests/libfixmath-unittests.h
@@ -15,4 +15,3 @@
printf("\033[32;1mOK:\033[22;39m " #x "\n"); \
}
-
--
2.7.4
2.20.1

View File

@ -1,164 +0,0 @@
From 0f5bcfdbc93d40c47da70ea6aade3fbe89120b10 Mon Sep 17 00:00:00 2001
From: Martine Lenders <mail@martine-lenders.eu>
Date: Thu, 12 May 2016 14:55:13 +0200
Subject: [PATCH 1/4] Move to RIOT Makefiles
---
Makefile | 8 ++++++
libfixmath/Makefile | 51 +++----------------------------------
unittests/Makefile | 73 ++---------------------------------------------------
3 files changed, 13 insertions(+), 119 deletions(-)
create mode 100644 Makefile
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b65e4b5
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+ifneq (,$(filter libfixmath,$(USEMODULE)))
+ DIRS += libfixmath
+endif
+ifneq (,$(filter libfixmath-unittests,$(USEMODULE)))
+ DIRS += unittests
+endif
+
+include $(RIOTBASE)/Makefile.base
diff --git a/libfixmath/Makefile b/libfixmath/Makefile
index b284590..c875b98 100644
--- a/libfixmath/Makefile
+++ b/libfixmath/Makefile
@@ -1,48 +1,3 @@
-#Project settings
-PROJECT = libfixmath
-LIB =
-SRC = .
-INC =
-
-#Compiler settings
-CPP = gcc
-CC = gcc
-AS = gcc
-LD = gcc
-AR = ar
-CPP_FLAGS = -O2 $(INC) -Wall -Wextra -c
-CC_FLAGS = -O2 $(INC) -Wall -Wextra -c
-AS_FLAGS = $(CC_FLAGS) -D_ASSEMBLER_
-LD_FLAGS = -Wall
-
-# Find all source files
-SRC_CPP = $(foreach dir, $(SRC), $(wildcard $(dir)/*.cpp))
-SRC_C = $(foreach dir, $(SRC), $(wildcard $(dir)/*.c))
-SRC_S = $(foreach dir, $(SRC), $(wildcard $(dir)/*.S))
-OBJ_CPP = $(patsubst %.cpp, %.o, $(SRC_CPP))
-OBJ_C = $(patsubst %.c, %.o, $(SRC_C))
-OBJ_S = $(patsubst %.S, %.o, $(SRC_S))
-OBJ = $(OBJ_CPP) $(OBJ_C) $(OBJ_S)
-
-# Compile rules.
-.PHONY : all
-all: $(PROJECT).a
-
-$(PROJECT).a: $(OBJ)
- $(AR) rcs $(PROJECT).a $(OBJ)
-
-$(OBJ_CPP) : %.o : %.cpp
- $(CPP) $(CPP_FLAGS) -o $@ $<
-
-$(OBJ_C) : %.o : %.c
- $(CC) $(CC_FLAGS) -o $@ $<
-
-$(OBJ_S) : %.o : %.S
- $(AS) $(AS_FLAGS) -o $@ $<
-
-
-
-# Clean rules
-.PHONY : clean
-clean:
- rm -f $(PROJECT).a $(OBJ)
+MODULE = libfixmath
+
+include $(RIOTBASE)/Makefile.base
diff --git a/unittests/Makefile b/unittests/Makefile
index 329caf4..245ffb9 100644
--- a/unittests/Makefile
+++ b/unittests/Makefile
@@ -1,72 +1,3 @@
-# Makefile for running the unittests of libfixmath.
-CC = gcc
-
-# Basic CFLAGS for debugging
-CFLAGS = -g -O0 -I../libfixmath -Wall -Wextra -Werror
-
-# The files required for tests
-FIX16_SRC = ../libfixmath/fix16.c ../libfixmath/fix16_sqrt.c ../libfixmath/fix16_str.c \
- ../libfixmath/fix16_exp.c ../libfixmath/fix16.h
-
-all: run_fix16_unittests run_fix16_exp_unittests run_fix16_str_unittests run_fix16_macros_unittests
-
-clean:
- rm -f fix16_unittests_????
-
-# The library is tested automatically under different compilations
-# options.
-#
-# Test naming:
-# r = rounding, n = no rounding
-# o = overflow detection, n = no overflow detection
-# 64 = int64_t math, 32 = int32_t math
-
-run_fix16_unittests: \
- fix16_unittests_ro64 fix16_unittests_no64 \
- fix16_unittests_rn64 fix16_unittests_nn64 \
- fix16_unittests_ro32 fix16_unittests_no32 \
- fix16_unittests_rn32 fix16_unittests_nn32 \
- fix16_unittests_ro08 fix16_unittests_no08 \
- fix16_unittests_rn08 fix16_unittests_nn08
- $(foreach test, $^, \
- echo $(test) && \
- ./$(test) > /dev/null && \
- ) true
-
-fix16_unittests_no64: DEFINES=-DFIXMATH_NO_ROUNDING
-fix16_unittests_rn64: DEFINES=-DFIXMATH_NO_OVERFLOW
-fix16_unittests_nn64: DEFINES=-DFIXMATH_NO_ROUNDING -DFIXMATH_NO_OVERFLOW
-fix16_unittests_ro32: DEFINES=-DFIXMATH_NO_64BIT
-fix16_unittests_no32: DEFINES=-DFIXMATH_NO_ROUNDING -DFIXMATH_NO_64BIT
-fix16_unittests_rn32: DEFINES=-DFIXMATH_NO_OVERFLOW -DFIXMATH_NO_64BIT
-fix16_unittests_nn32: DEFINES=-DFIXMATH_NO_OVERFLOW -DFIXMATH_NO_ROUNDING -DFIXMATH_NO_64BIT
-fix16_unittests_ro08: DEFINES=-DFIXMATH_OPTIMIZE_8BIT
-fix16_unittests_no08: DEFINES=-DFIXMATH_NO_ROUNDING -DFIXMATH_OPTIMIZE_8BIT
-fix16_unittests_rn08: DEFINES=-DFIXMATH_NO_OVERFLOW -DFIXMATH_OPTIMIZE_8BIT
-fix16_unittests_nn08: DEFINES=-DFIXMATH_NO_OVERFLOW -DFIXMATH_NO_ROUNDING -DFIXMATH_OPTIMIZE_8BIT
-
-fix16_unittests_% : fix16_unittests.c $(FIX16_SRC)
- $(CC) $(CFLAGS) $(DEFINES) -o $@ $^ -lm
-
-
-# Tests for the exponential function, run only in default config
-run_fix16_exp_unittests: fix16_exp_unittests
- ./fix16_exp_unittests > /dev/null
-
-fix16_exp_unittests: fix16_exp_unittests.c $(FIX16_SRC)
- $(CC) $(CFLAGS) $(DEFINES) -o $@ $^ -lm
-
-# Tests for string conversion, run only in default config
-run_fix16_str_unittests: fix16_str_unittests
- ./fix16_str_unittests > /dev/null
-
-fix16_str_unittests: fix16_str_unittests.c $(FIX16_SRC)
- $(CC) $(CFLAGS) $(DEFINES) -o $@ $^ -lm
-
-# Tests for literal macros, run only in default config
-run_fix16_macros_unittests: fix16_macros_unittests
- ./fix16_macros_unittests > /dev/null
-
-fix16_macros_unittests: fix16_macros_unittests.c $(FIX16_SRC)
- $(CC) $(CFLAGS) $(DEFINES) -o $@ $^ -lm
+MODULE = libfixmath-unittests
+include $(RIOTBASE)/Makefile.base
--
2.7.4

View File

@ -1,7 +1,7 @@
From bf974ff27fd48b8964bbe4813511adbe4c673a98 Mon Sep 17 00:00:00 2001
From 00aa19d5a431e414008e1475421cae8704ad775a Mon Sep 17 00:00:00 2001
From: Martine Lenders <mail@martine-lenders.eu>
Date: Thu, 12 May 2016 15:08:39 +0200
Subject: [PATCH 3/4] Adapt unittests for RIOT
Subject: [PATCH] Adapt unittests for RIOT
---
unittests/fix16_exp_unittests.c | 12 ++++++------
@ -247,10 +247,10 @@ index 9a301a1..b9fbf1a 100644
return status;
}
diff --git a/unittests/libfixmath-unittests.h b/unittests/libfixmath-unittests.h
index bac57d2..a72d025 100644
index 57ad8f8..a3324bf 100644
--- a/unittests/libfixmath-unittests.h
+++ b/unittests/libfixmath-unittests.h
@@ -5,14 +5,14 @@
@@ -5,13 +5,13 @@
#define STR2(x) STR(x)
#define TEST(x) \
if (!(x)) { \
@ -265,11 +265,10 @@ index bac57d2..a72d025 100644
printf("\033[32;1mOK:\033[22;39m " #x "\n"); \
}
+int fix16_exp_unittests(void);
+int fix16_macros_unittests(void);
+int fix16_str_unittests(void);
+int fix16_unittests(void);
--
2.7.4
2.20.1

View File

@ -1,20 +1,19 @@
From 8d0c6f21ba52fb0b00e95a218fd60a4f16b7ccde Mon Sep 17 00:00:00 2001
From 6033cf22749bfa20fe0a9b039b7725f9a372b6ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= <gaetan.harter@fu-berlin.de>
Date: Thu, 26 Jul 2018 17:47:59 +0200
Subject: [PATCH 5/5] Replace __FILE__ by RIOT_FILE_NOPATH
Subject: [PATCH] Replace __FILE__ by RIOT_FILE_NOPATH
The binary file size changes when the RIOT directory is moved.
This caused the `libfixmath_unittests` to fail on my computer.
I used RIOT_FILE_NOPATH instead of RIOT_FILE_RELATIVE as 'TEST' is used a lot
and it would allow more boards to be tested, full path is not that important.
---
unittests/libfixmath-unittests.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/unittests/libfixmath-unittests.h b/unittests/libfixmath-unittests.h
index a72d025..52ad7cb 100644
index a3324bf..bf6b063 100644
--- a/unittests/libfixmath-unittests.h
+++ b/unittests/libfixmath-unittests.h
@@ -5,7 +5,7 @@
@ -27,5 +26,5 @@ index a72d025..52ad7cb 100644
} else { \
printf("\033[32;1mOK:\033[22;39m " #x "\n"); \
--
2.7.4
2.20.1

View File

@ -1,23 +0,0 @@
From a32404a5acb702ffb28bada70cd6204ab74a771d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= <gaetan.harter@fu-berlin.de>
Date: Tue, 7 Nov 2017 16:42:27 +0100
Subject: [PATCH 4/4] Change conflicting module name for pkg root directory
Root directory and libfixmath both had 'libfixmath' module name.
---
Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Makefile b/Makefile
index b65e4b5..2cc24d1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+MODULE = pkg-libfixmath
+
ifneq (,$(filter libfixmath,$(USEMODULE)))
DIRS += libfixmath
endif
--
2.7.4

View File

@ -1,43 +0,0 @@
#!/usr/bin/env python3
import sys
from testrunner import run, test_utils_interactive_sync
def expect_unary(child):
for _ in range(20):
for op_name in ('abs', 'sq', 'atan', 'exp'):
child.expect('{}\(-?\d+\.\d+\) = -?\d+\.\d+'.format(op_name))
for _ in range(20):
for op_name in ('sin', 'cos', 'tan'):
child.expect('{}\(-?\d+.\d+\) = -?\d+.\d+'.format(op_name))
for _ in range(20):
for op_name in ('asin', 'acos'):
child.expect('{}\(-?\d+.\d+\) = -?\d+.\d+'.format(op_name))
for _ in range(20):
for op_name in ('sqrt', 'log', 'log2', 'slog2'):
child.expect('{}\(-?\d+.\d+\) = -?\d+.\d+'.format(op_name))
def expect_binary(child):
for _ in range(1500):
for op_name in ('add', 'sub', 'mul', 'div', 'mod', 'sadd', 'ssub',
'smul', 'sdiv', 'min', 'max'):
child.expect('{}\(-?\d+.\d+\, -?\d+.\d+\) = -?\d+.\d+'
.format(op_name))
def testfunc(child):
test_utils_interactive_sync(child)
child.expect_exact('Unary.')
expect_unary(child)
child.expect_exact('Binary.')
expect_binary(child)
child.expect_exact('SUCCESS')
if __name__ == "__main__":
sys.exit(run(testfunc))

View File

@ -1,22 +0,0 @@
include ../Makefile.tests_common
BOARD_BLACKLIST := arduino-duemilanove arduino-leonardo \
arduino-mega2560 arduino-nano arduino-uno avr-rss2 \
atmega328p atmega256rfr2-xpro atmega1284p mega-xplained \
microduino-corerf waspmote-pro
# arduino-mega2560: builds locally but breaks travis (possibly because of
# differences in the toolchain)
# The MSP boards don't feature round(), exp(), and log(), which are used in the unittests
BOARD_BLACKLIST += chronos msb-430 msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1
USEMODULE += libfixmath-unittests
ifneq (,$(filter native,$(BOARD)))
export LINKFLAGS += -lm
endif
USEMODULE += printf_float
TEST_ON_CI_WHITELIST += native
include $(RIOTBASE)/Makefile.include

View File

@ -78,12 +78,16 @@ def main():
abs_error = abs(res_locals['result'] - float(res_locals['expected']))
res_locals['result'] = '{:.4f}'.format(res_locals['result'])
if abs_error > ABS_ERROR_LIMIT:
print('{}: {} != {}, {:.4f} > {}'.format(res_locals['input'], res_locals['result'], res_locals['expected'],
abs_error, ABS_ERROR_LIMIT))
print('{}: {} != {}, {:.4f} > {}'.format(
res_locals['input'],
res_locals['result'],
res_locals['expected'],
abs_error,
ABS_ERROR_LIMIT))
errors += 1
except:
except Exception as exc:
errors += 1
print('ERROR {}'.format(line))
print('ERROR: {}: {}'.format(line, exc))
print('{} calculations passed.'.format(total - errors))
if errors:

View File

@ -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);

View File

@ -0,0 +1,58 @@
#!/usr/bin/env python3
import sys
from testrunner import run, test_utils_interactive_sync
def expect_unary(child):
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))
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))
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))
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):
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+'
.format(op_name))
def testfunc(child):
test_utils_interactive_sync(child)
child.expect_exact('Unary.')
expect_unary(child)
child.expect_exact('Binary.')
expect_binary(child)
child.expect_exact('SUCCESS')
if __name__ == "__main__":
sys.exit(run(testfunc))

View File

@ -0,0 +1,13 @@
include ../Makefile.tests_common
USEMODULE += libfixmath-unittests
ifneq (,$(filter native,$(BOARD)))
export LINKFLAGS += -lm
endif
USEMODULE += printf_float
TEST_ON_CI_WHITELIST += native
include $(RIOTBASE)/Makefile.include