From 8e281f8b025d9cf5f26a37af5dc8fad7f0684a76 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 11 Nov 2019 15:15:16 +0100 Subject: [PATCH 1/7] pkg/libfixmath: cleanup Makefiles and patches --- pkg/libfixmath/Makefile | 3 +- pkg/libfixmath/Makefile.include | 2 + pkg/libfixmath/Makefile.libfixmath | 3 + pkg/libfixmath/Makefile.libfixmath-unittests | 3 + ...warnings.patch => 0001-Fix-warnings.patch} | 94 +++------- .../patches/0001-Move-to-RIOT-Makefiles.patch | 164 ------------------ ...ch => 0002-Adapt-unittests-for-RIOT.patch} | 15 +- ...eplace-__FILE__-by-RIOT_FILE_NOPATH.patch} | 11 +- ...ng-module-name-for-pkg-root-director.patch | 23 --- 9 files changed, 50 insertions(+), 268 deletions(-) create mode 100644 pkg/libfixmath/Makefile.libfixmath create mode 100644 pkg/libfixmath/Makefile.libfixmath-unittests rename pkg/libfixmath/patches/{0002-Fix-warnings.patch => 0001-Fix-warnings.patch} (51%) delete mode 100644 pkg/libfixmath/patches/0001-Move-to-RIOT-Makefiles.patch rename pkg/libfixmath/patches/{0003-Adapt-unittests-for-RIOT.patch => 0002-Adapt-unittests-for-RIOT.patch} (98%) rename pkg/libfixmath/patches/{0005-Replace-__FILE__-by-RIOT_FILE_NOPATH.patch => 0003-Replace-__FILE__-by-RIOT_FILE_NOPATH.patch} (86%) delete mode 100644 pkg/libfixmath/patches/0004-Change-conflicting-module-name-for-pkg-root-director.patch diff --git a/pkg/libfixmath/Makefile b/pkg/libfixmath/Makefile index 6f50c031b7..3d49b6d721 100644 --- a/pkg/libfixmath/Makefile +++ b/pkg/libfixmath/Makefile @@ -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 diff --git a/pkg/libfixmath/Makefile.include b/pkg/libfixmath/Makefile.include index c5ed678375..3c5f82ead9 100644 --- a/pkg/libfixmath/Makefile.include +++ b/pkg/libfixmath/Makefile.include @@ -3,8 +3,10 @@ PKG_BUILDDIR ?= $(PKGDIRBASE)/libfixmath # The static cache is huge, disable it. CFLAGS += -DFIXMATH_NO_CACHE +DIRS += $(PKG_BUILDDIR)/libfixmath INCLUDES += -I$(PKG_BUILDDIR)/libfixmath ifneq (,$(filter libfixmath-unittests,$(USEMODULE))) + DIRS += $(PKG_BUILDDIR)/unittests INCLUDES += -I$(PKG_BUILDDIR)/unittests endif diff --git a/pkg/libfixmath/Makefile.libfixmath b/pkg/libfixmath/Makefile.libfixmath new file mode 100644 index 0000000000..c875b98543 --- /dev/null +++ b/pkg/libfixmath/Makefile.libfixmath @@ -0,0 +1,3 @@ +MODULE = libfixmath + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/libfixmath/Makefile.libfixmath-unittests b/pkg/libfixmath/Makefile.libfixmath-unittests new file mode 100644 index 0000000000..245ffb9416 --- /dev/null +++ b/pkg/libfixmath/Makefile.libfixmath-unittests @@ -0,0 +1,3 @@ +MODULE = libfixmath-unittests + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/libfixmath/patches/0002-Fix-warnings.patch b/pkg/libfixmath/patches/0001-Fix-warnings.patch similarity index 51% rename from pkg/libfixmath/patches/0002-Fix-warnings.patch rename to pkg/libfixmath/patches/0001-Fix-warnings.patch index 2de4009e10..9d3ed8edc4 100644 --- a/pkg/libfixmath/patches/0002-Fix-warnings.patch +++ b/pkg/libfixmath/patches/0001-Fix-warnings.patch @@ -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 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') { @@ -65,61 +63,25 @@ index 2980ab9..855774d 100644 - if(inVal >= (1 << 4)) { inVal >>= 4; tempOut += 4; } - if(inVal >= (1 << 2)) { inVal >>= 2; tempOut += 2; } - if(inVal >= (1 << 1)) { tempOut += 1; } -+ if(inVal >= ((uint32_t) 1 << 16)) { inVal >>= 16; tempOut += 16; } -+ if(inVal >= ((uint32_t) 1 << 8)) { inVal >>= 8; tempOut += 8; } -+ if(inVal >= ((uint32_t) 1 << 4)) { inVal >>= 4; tempOut += 4; } -+ if(inVal >= ((uint32_t) 1 << 2)) { inVal >>= 2; tempOut += 2; } -+ if(inVal >= ((uint32_t) 1 << 1)) { tempOut += 1; } ++ if(inVal >= ((uint32_t) 1 << 16)) { inVal >>= 16; tempOut += 16; } ++ if(inVal >= ((uint32_t) 1 << 8)) { inVal >>= 8; tempOut += 8; } ++ if(inVal >= ((uint32_t) 1 << 4)) { inVal >>= 4; tempOut += 4; } ++ if(inVal >= ((uint32_t) 1 << 2)) { inVal >>= 2; tempOut += 2; } ++ 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 -+ -+#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 -- --#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 diff --git a/pkg/libfixmath/patches/0001-Move-to-RIOT-Makefiles.patch b/pkg/libfixmath/patches/0001-Move-to-RIOT-Makefiles.patch deleted file mode 100644 index 10462a23c6..0000000000 --- a/pkg/libfixmath/patches/0001-Move-to-RIOT-Makefiles.patch +++ /dev/null @@ -1,164 +0,0 @@ -From 0f5bcfdbc93d40c47da70ea6aade3fbe89120b10 Mon Sep 17 00:00:00 2001 -From: Martine Lenders -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 - diff --git a/pkg/libfixmath/patches/0003-Adapt-unittests-for-RIOT.patch b/pkg/libfixmath/patches/0002-Adapt-unittests-for-RIOT.patch similarity index 98% rename from pkg/libfixmath/patches/0003-Adapt-unittests-for-RIOT.patch rename to pkg/libfixmath/patches/0002-Adapt-unittests-for-RIOT.patch index 881f4456ea..ece918e563 100644 --- a/pkg/libfixmath/patches/0003-Adapt-unittests-for-RIOT.patch +++ b/pkg/libfixmath/patches/0002-Adapt-unittests-for-RIOT.patch @@ -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 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 ++++++------ @@ -74,7 +74,7 @@ index cdfcfaf..6141021 100644 #include -#include "unittests.h" +#include "libfixmath-unittests.h" - + #define DO_TEST(i,m) \ TEST(F16(i ## . ## m) == F16C(i,m)) \ TEST(F16(i ## . ## m) == fix16_from_dbl(i ## . ## m)) @@ -145,7 +145,7 @@ index 9a301a1..b9fbf1a 100644 #include -#include "unittests.h" +#include "libfixmath-unittests.h" - + const fix16_t testcases[] = { // Small numbers @@ -47,7 +47,7 @@ const fix16_t max_delta = 1; @@ -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 diff --git a/pkg/libfixmath/patches/0005-Replace-__FILE__-by-RIOT_FILE_NOPATH.patch b/pkg/libfixmath/patches/0003-Replace-__FILE__-by-RIOT_FILE_NOPATH.patch similarity index 86% rename from pkg/libfixmath/patches/0005-Replace-__FILE__-by-RIOT_FILE_NOPATH.patch rename to pkg/libfixmath/patches/0003-Replace-__FILE__-by-RIOT_FILE_NOPATH.patch index f4037cf599..4785935122 100644 --- a/pkg/libfixmath/patches/0005-Replace-__FILE__-by-RIOT_FILE_NOPATH.patch +++ b/pkg/libfixmath/patches/0003-Replace-__FILE__-by-RIOT_FILE_NOPATH.patch @@ -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?= 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 @@ @@ -26,6 +25,6 @@ index a72d025..52ad7cb 100644 status = 1; \ } else { \ printf("\033[32;1mOK:\033[22;39m " #x "\n"); \ --- -2.7.4 +-- +2.20.1 diff --git a/pkg/libfixmath/patches/0004-Change-conflicting-module-name-for-pkg-root-director.patch b/pkg/libfixmath/patches/0004-Change-conflicting-module-name-for-pkg-root-director.patch deleted file mode 100644 index 67aed3aa8a..0000000000 --- a/pkg/libfixmath/patches/0004-Change-conflicting-module-name-for-pkg-root-director.patch +++ /dev/null @@ -1,23 +0,0 @@ -From a32404a5acb702ffb28bada70cd6204ab74a771d Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= -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 - From b32dd168a13548995ebc81ed7fdf47526ba45224 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 11 Nov 2019 15:30:06 +0100 Subject: [PATCH 2/7] pkg/libfixmath: fix computations on 8bit architectures --- pkg/libfixmath/Makefile.include | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/libfixmath/Makefile.include b/pkg/libfixmath/Makefile.include index 3c5f82ead9..790e292959 100644 --- a/pkg/libfixmath/Makefile.include +++ b/pkg/libfixmath/Makefile.include @@ -3,6 +3,10 @@ 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 From a4bff5f8033c5c4ffadc0dafd29e65320b16a4c5 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 11 Nov 2019 15:36:42 +0100 Subject: [PATCH 3/7] pkg/libfixmath: blacklist architectures not supported by unittests 8bit architectures are not compatible. round function is not provided by the msp430 toolchain. --- pkg/libfixmath/Makefile.dep | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 pkg/libfixmath/Makefile.dep diff --git a/pkg/libfixmath/Makefile.dep b/pkg/libfixmath/Makefile.dep new file mode 100644 index 0000000000..c249341fc0 --- /dev/null +++ b/pkg/libfixmath/Makefile.dep @@ -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 From e4bea426d5b5d061f1b620f1d9158d40e1e5c4c7 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 11 Nov 2019 15:37:45 +0100 Subject: [PATCH 4/7] tests/libfixmath_unittests: remove useless BOARD_BLACKLIST The implementation of libfixmath is not compatible with architecture smaller than 32bit --- tests/libfixmath_unittests/Makefile | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/libfixmath_unittests/Makefile b/tests/libfixmath_unittests/Makefile index d115dca0e7..67c993d7c7 100644 --- a/tests/libfixmath_unittests/Makefile +++ b/tests/libfixmath_unittests/Makefile @@ -1,14 +1,5 @@ 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))) From 19917f18b7c50940b9168e16c2f4ee95679bf9e3 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 11 Nov 2019 15:39:01 +0100 Subject: [PATCH 5/7] tests/libfixmath*: rename test applications Use pkg_ prefix to have a consistent name with other pkg tests applications --- tests/{libfixmath => pkg_libfixmath}/Makefile | 0 tests/{libfixmath => pkg_libfixmath}/do-test.py | 0 tests/{libfixmath => pkg_libfixmath}/main.c | 0 tests/{libfixmath => pkg_libfixmath}/tests/01-run.py | 0 tests/{libfixmath_unittests => pkg_libfixmath_unittests}/Makefile | 0 .../Makefile.ci | 0 tests/{libfixmath_unittests => pkg_libfixmath_unittests}/main.c | 0 .../tests/01-run.py | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename tests/{libfixmath => pkg_libfixmath}/Makefile (100%) rename tests/{libfixmath => pkg_libfixmath}/do-test.py (100%) rename tests/{libfixmath => pkg_libfixmath}/main.c (100%) rename tests/{libfixmath => pkg_libfixmath}/tests/01-run.py (100%) rename tests/{libfixmath_unittests => pkg_libfixmath_unittests}/Makefile (100%) rename tests/{libfixmath_unittests => pkg_libfixmath_unittests}/Makefile.ci (100%) rename tests/{libfixmath_unittests => pkg_libfixmath_unittests}/main.c (100%) rename tests/{libfixmath_unittests => pkg_libfixmath_unittests}/tests/01-run.py (100%) diff --git a/tests/libfixmath/Makefile b/tests/pkg_libfixmath/Makefile similarity index 100% rename from tests/libfixmath/Makefile rename to tests/pkg_libfixmath/Makefile diff --git a/tests/libfixmath/do-test.py b/tests/pkg_libfixmath/do-test.py similarity index 100% rename from tests/libfixmath/do-test.py rename to tests/pkg_libfixmath/do-test.py diff --git a/tests/libfixmath/main.c b/tests/pkg_libfixmath/main.c similarity index 100% rename from tests/libfixmath/main.c rename to tests/pkg_libfixmath/main.c diff --git a/tests/libfixmath/tests/01-run.py b/tests/pkg_libfixmath/tests/01-run.py similarity index 100% rename from tests/libfixmath/tests/01-run.py rename to tests/pkg_libfixmath/tests/01-run.py diff --git a/tests/libfixmath_unittests/Makefile b/tests/pkg_libfixmath_unittests/Makefile similarity index 100% rename from tests/libfixmath_unittests/Makefile rename to tests/pkg_libfixmath_unittests/Makefile diff --git a/tests/libfixmath_unittests/Makefile.ci b/tests/pkg_libfixmath_unittests/Makefile.ci similarity index 100% rename from tests/libfixmath_unittests/Makefile.ci rename to tests/pkg_libfixmath_unittests/Makefile.ci diff --git a/tests/libfixmath_unittests/main.c b/tests/pkg_libfixmath_unittests/main.c similarity index 100% rename from tests/libfixmath_unittests/main.c rename to tests/pkg_libfixmath_unittests/main.c diff --git a/tests/libfixmath_unittests/tests/01-run.py b/tests/pkg_libfixmath_unittests/tests/01-run.py similarity index 100% rename from tests/libfixmath_unittests/tests/01-run.py rename to tests/pkg_libfixmath_unittests/tests/01-run.py From 326f5f1d122af4cf7f23fb1fa37300fd459cf743 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 11 Nov 2019 15:48:23 +0100 Subject: [PATCH 6/7] tests/pkg_libfixmath: fix PEP8 issues --- tests/pkg_libfixmath/do-test.py | 12 ++++++++---- tests/pkg_libfixmath/tests/01-run.py | 10 +++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/pkg_libfixmath/do-test.py b/tests/pkg_libfixmath/do-test.py index 2577a511c6..930e297097 100755 --- a/tests/pkg_libfixmath/do-test.py +++ b/tests/pkg_libfixmath/do-test.py @@ -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: diff --git a/tests/pkg_libfixmath/tests/01-run.py b/tests/pkg_libfixmath/tests/01-run.py index 21e42d95fa..c68fe3b9ae 100755 --- a/tests/pkg_libfixmath/tests/01-run.py +++ b/tests/pkg_libfixmath/tests/01-run.py @@ -7,26 +7,26 @@ 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)) + child.expect(r'{}\(-?\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)) + child.expect(r'{}\(-?\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)) + child.expect(r'{}\(-?\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)) + child.expect(r'{}\(-?\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+' + child.expect(r'{}\(-?\d+.\d+\, -?\d+.\d+\) = -?\d+.\d+' .format(op_name)) From 07f7ac582926a69a818c03e98b130cdee590d76c Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Thu, 14 Nov 2019 20:01:28 +0100 Subject: [PATCH 7/7] 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 --- tests/pkg_libfixmath/main.c | 66 +++++++++++++++++++++++++--- tests/pkg_libfixmath/tests/01-run.py | 25 ++++++++--- 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/tests/pkg_libfixmath/main.c b/tests/pkg_libfixmath/main.c index 48094637e1..b66aeaf5a9 100644 --- a/tests/pkg_libfixmath/main.c +++ b/tests/pkg_libfixmath/main.c @@ -29,6 +29,7 @@ */ #include +#include #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); diff --git a/tests/pkg_libfixmath/tests/01-run.py b/tests/pkg_libfixmath/tests/01-run.py index c68fe3b9ae..a32a2471c2 100755 --- a/tests/pkg_libfixmath/tests/01-run.py +++ b/tests/pkg_libfixmath/tests/01-run.py @@ -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+'