Merge pull request #6738 from andrejpodzimek/per_target_tests

Adding a per-target unit test for timer metadata consistency.
This commit is contained in:
borisbstyle 2018-09-12 21:59:56 +02:00 committed by GitHub
commit 93c6f93ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 443 additions and 150 deletions

View File

@ -1,58 +1,13 @@
OFFICIAL_TARGETS = ALIENFLIGHTF3 ALIENFLIGHTF4 ANYFCF7 BETAFLIGHTF3 BLUEJAYF4 FURYF4 REVO SIRINFPV SPARKY SPRACINGF3 SPRACINGF3EVO SPRACINGF3NEO SPRACINGF4EVO SPRACINGF7DUAL STM32F3DISCOVERY include $(ROOT)/make/targets_list.mk
ALT_TARGETS = $(sort $(filter-out target, $(basename $(notdir $(wildcard $(ROOT)/src/main/target/*/*.mk)))))
NOBUILD_TARGETS = $(sort $(filter-out target, $(basename $(notdir $(wildcard $(ROOT)/src/main/target/*/*.nomk)))))
OPBL_TARGETS = $(filter %_OPBL, $(ALT_TARGETS))
VALID_TARGETS = $(dir $(wildcard $(ROOT)/src/main/target/*/target.mk))
VALID_TARGETS := $(subst /,, $(subst ./src/main/target/,, $(VALID_TARGETS)))
VALID_TARGETS := $(VALID_TARGETS) $(ALT_TARGETS)
VALID_TARGETS := $(sort $(VALID_TARGETS))
VALID_TARGETS := $(filter-out $(NOBUILD_TARGETS), $(VALID_TARGETS))
ifeq ($(filter $(TARGET),$(NOBUILD_TARGETS)), $(TARGET)) ifeq ($(filter $(TARGET),$(NOBUILD_TARGETS)), $(TARGET))
ALTERNATES := $(sort $(filter-out target, $(basename $(notdir $(wildcard $(ROOT)/src/main/target/$(TARGET)/*.mk))))) ALTERNATES := $(sort $(filter-out target, $(basename $(notdir $(wildcard $(ROOT)/src/main/target/$(TARGET)/*.mk)))))
$(error The target specified, $(TARGET), cannot be built. Use one of the ALT targets: $(ALTERNATES)) $(error The target specified, $(TARGET), cannot be built. Use one of the ALT targets: $(ALTERNATES))
endif endif
UNSUPPORTED_TARGETS := \ BASE_TARGET := $(call get_base_target,$(TARGET))
AFROMINI \ ifneq ($(TARGET),$(BASE_TARGET))
ALIENFLIGHTF1 \
BEEBRAIN \
CC3D \
CC3D_OPBL \
CJMCU \
MICROSCISKY \
NAZE
SUPPORTED_TARGETS := $(filter-out $(UNSUPPORTED_TARGETS), $(VALID_TARGETS))
TARGETS_TOTAL := $(words $(SUPPORTED_TARGETS))
TARGET_GROUPS := 5
TARGETS_PER_GROUP := $(shell expr $(TARGETS_TOTAL) / $(TARGET_GROUPS) )
ST := 1
ET := $(shell expr $(ST) + $(TARGETS_PER_GROUP))
GROUP_1_TARGETS := $(wordlist $(ST), $(ET), $(SUPPORTED_TARGETS))
ST := $(shell expr $(ET) + 1)
ET := $(shell expr $(ST) + $(TARGETS_PER_GROUP))
GROUP_2_TARGETS := $(wordlist $(ST), $(ET), $(SUPPORTED_TARGETS))
ST := $(shell expr $(ET) + 1)
ET := $(shell expr $(ST) + $(TARGETS_PER_GROUP))
GROUP_3_TARGETS := $(wordlist $(ST), $(ET), $(SUPPORTED_TARGETS))
ST := $(shell expr $(ET) + 1)
ET := $(shell expr $(ST) + $(TARGETS_PER_GROUP))
GROUP_4_TARGETS := $(wordlist $(ST), $(ET), $(SUPPORTED_TARGETS))
GROUP_OTHER_TARGETS := $(filter-out $(GROUP_1_TARGETS) $(GROUP_2_TARGETS) $(GROUP_3_TARGETS) $(GROUP_4_TARGETS), $(SUPPORTED_TARGETS))
ifeq ($(filter $(TARGET),$(ALT_TARGETS)), $(TARGET))
BASE_TARGET := $(firstword $(subst /,, $(subst ./src/main/target/,, $(dir $(wildcard $(ROOT)/src/main/target/*/$(TARGET).mk)))))
include $(ROOT)/src/main/target/$(BASE_TARGET)/$(TARGET).mk include $(ROOT)/src/main/target/$(BASE_TARGET)/$(TARGET).mk
else
BASE_TARGET := $(TARGET)
endif endif
ifeq ($(filter $(TARGET),$(OPBL_TARGETS)), $(TARGET)) ifeq ($(filter $(TARGET),$(OPBL_TARGETS)), $(TARGET))

67
make/targets_list.mk Normal file
View File

@ -0,0 +1,67 @@
OFFICIAL_TARGETS = \
ALIENFLIGHTF3 \
ALIENFLIGHTF4 \
ANYFCF7 \
BETAFLIGHTF3 \
BLUEJAYF4 \
FURYF4 REVO \
SIRINFPV \
SPARKY \
SPRACINGF3 \
SPRACINGF3EVO \
SPRACINGF3NEO \
SPRACINGF4EVO \
SPRACINGF7DUAL \
STM32F3DISCOVERY
ALT_TARGET_PATHS = $(filter-out %/target,$(basename $(wildcard $(ROOT)/src/main/target/*/*.mk)))
ALT_TARGET_NAMES = $(notdir $(ALT_TARGET_PATHS))
BASE_TARGET_NAMES = $(notdir $(patsubst %/,%,$(dir $(ALT_TARGET_PATHS))))
BASE_ALT_PAIRS = $(join $(BASE_TARGET_NAMES:=/),$(ALT_TARGET_NAMES))
ALT_TARGETS = $(sort $(notdir $(BASE_ALT_PAIRS)))
BASE_TARGETS = $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(ROOT)/src/main/target/*/target.mk)))))
NOBUILD_TARGETS = $(sort $(filter-out target,$(basename $(notdir $(wildcard $(ROOT)/src/main/target/*/*.nomk)))))
OPBL_TARGETS = $(sort $(filter %_OPBL,$(ALT_TARGETS)))
VALID_TARGETS = $(sort $(filter-out $(NOBUILD_TARGETS),$(BASE_TARGETS) $(ALT_TARGETS)))
# For alt targets, returns their base target name.
# For base targets, returns the (same) target name.
# param $1 = target name
find_target_pair = $(filter %/$(1),$(BASE_ALT_PAIRS))
get_base_target = $(if $(call find_target_pair,$(1)),$(patsubst %/,%,$(dir $(call find_target_pair,$(1)))),$(1))
UNSUPPORTED_TARGETS := \
AFROMINI \
ALIENFLIGHTF1 \
BEEBRAIN \
CC3D \
CC3D_OPBL \
CJMCU \
MICROSCISKY \
NAZE
SUPPORTED_TARGETS := $(filter-out $(UNSUPPORTED_TARGETS), $(VALID_TARGETS))
TARGETS_TOTAL := $(words $(SUPPORTED_TARGETS))
TARGET_GROUPS := 5
TARGETS_PER_GROUP := $(shell expr $(TARGETS_TOTAL) / $(TARGET_GROUPS) )
ST := 1
ET := $(shell expr $(ST) + $(TARGETS_PER_GROUP))
GROUP_1_TARGETS := $(wordlist $(ST), $(ET), $(SUPPORTED_TARGETS))
ST := $(shell expr $(ET) + 1)
ET := $(shell expr $(ST) + $(TARGETS_PER_GROUP))
GROUP_2_TARGETS := $(wordlist $(ST), $(ET), $(SUPPORTED_TARGETS))
ST := $(shell expr $(ET) + 1)
ET := $(shell expr $(ST) + $(TARGETS_PER_GROUP))
GROUP_3_TARGETS := $(wordlist $(ST), $(ET), $(SUPPORTED_TARGETS))
ST := $(shell expr $(ET) + 1)
ET := $(shell expr $(ST) + $(TARGETS_PER_GROUP))
GROUP_4_TARGETS := $(wordlist $(ST), $(ET), $(SUPPORTED_TARGETS))
GROUP_OTHER_TARGETS := $(filter-out $(GROUP_1_TARGETS) $(GROUP_2_TARGETS) $(GROUP_3_TARGETS) $(GROUP_4_TARGETS), $(SUPPORTED_TARGETS))

View File

@ -141,5 +141,5 @@
#define TARGET_IO_PORTC ( BIT(12) | BIT(11) | BIT(10) | BIT(9) | BIT(8) | BIT(7) | BIT(6) | BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0) ) #define TARGET_IO_PORTC ( BIT(12) | BIT(11) | BIT(10) | BIT(9) | BIT(8) | BIT(7) | BIT(6) | BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0) )
#define TARGET_IO_PORTD ( BIT(2) ) #define TARGET_IO_PORTD ( BIT(2) )
#define USABLE_TIMER_CHANNEL_COUNT 16 #define USABLE_TIMER_CHANNEL_COUNT 13
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9) ) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9) )

View File

@ -110,4 +110,4 @@
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(3)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(3)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 10 #define USABLE_TIMER_CHANNEL_COUNT 10
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(15) | TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(15) | TIM_N(16) | TIM_N(17))

View File

@ -100,4 +100,4 @@
#define TARGET_IO_PORTF (BIT(4)) #define TARGET_IO_PORTF (BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 14 #define USABLE_TIMER_CHANNEL_COUNT 14
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) ) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) )

View File

@ -130,4 +130,4 @@
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 11 #define USABLE_TIMER_CHANNEL_COUNT 11
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(15) | TIM_N(17) ) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8) | TIM_N(15) | TIM_N(16) | TIM_N(17) )

View File

@ -169,4 +169,4 @@
#define TARGET_IO_PORTD 0xffff #define TARGET_IO_PORTD 0xffff
#define TARGET_IO_PORTE 0xffff #define TARGET_IO_PORTE 0xffff
#define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11)) #define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9) | TIM_N(12) )

View File

@ -162,4 +162,4 @@
#define TARGET_IO_PORTD (BIT(2)) #define TARGET_IO_PORTD (BIT(2))
#define USABLE_TIMER_CHANNEL_COUNT 10 #define USABLE_TIMER_CHANNEL_COUNT 10
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9)) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(9) )

View File

@ -157,4 +157,4 @@
#define TARGET_IO_PORTC (BIT(13)|BIT(14)|BIT(15)) #define TARGET_IO_PORTC (BIT(13)|BIT(14)|BIT(15))
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(3)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(3)|BIT(4))
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(15) | TIM_N(16) | TIM_N(17) ) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(16) | TIM_N(17) )

View File

@ -175,4 +175,4 @@
#define TARGET_IO_PORTD (BIT(2)) #define TARGET_IO_PORTD (BIT(2))
#define USABLE_TIMER_CHANNEL_COUNT 8 #define USABLE_TIMER_CHANNEL_COUNT 8
#define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(8) | TIM_N(9) ) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(8) )

View File

@ -138,4 +138,4 @@
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 12 #define USABLE_TIMER_CHANNEL_COUNT 12
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(15)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8) | TIM_N(15) | TIM_N(16))

View File

@ -142,4 +142,4 @@
#define TARGET_IO_PORTC (BIT(13)|BIT(14)|BIT(15)) #define TARGET_IO_PORTC (BIT(13)|BIT(14)|BIT(15))
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 4 #define USABLE_TIMER_CHANNEL_COUNT 4
#define USED_TIMERS (TIM_N(2) | TIM_N(8) | TIM_N(15)) #define USED_TIMERS (TIM_N(2) | TIM_N(8))

View File

@ -37,11 +37,11 @@
#define USBD_PRODUCT_STRING "Crazyflie 2.0" #define USBD_PRODUCT_STRING "Crazyflie 2.0"
#endif #endif
#define USABLE_TIMER_CHANNEL_COUNT 14
#if defined(CRAZYFLIE2BQ) #if defined(CRAZYFLIE2BQ)
#define USABLE_TIMER_CHANNEL_COUNT 5
#define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(14) ) #define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(14) )
#else #else
#define USABLE_TIMER_CHANNEL_COUNT 4
#define USED_TIMERS ( TIM_N(2) | TIM_N(4) ) #define USED_TIMERS ( TIM_N(2) | TIM_N(4) )
#endif #endif

View File

@ -140,4 +140,4 @@
// channel mapping in drivers/pwm_mapping.c // channel mapping in drivers/pwm_mapping.c
// only 6 outputs available on hardware // only 6 outputs available on hardware
#define USABLE_TIMER_CHANNEL_COUNT 10 #define USABLE_TIMER_CHANNEL_COUNT 10
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(15)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8) | TIM_N(16))

View File

@ -159,4 +159,4 @@
#define TARGET_IO_PORTE 0xffff #define TARGET_IO_PORTE 0xffff
#define USABLE_TIMER_CHANNEL_COUNT 17 #define USABLE_TIMER_CHANNEL_COUNT 17
#define USED_TIMERS ( TIM_N(1) |TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9)) #define USED_TIMERS ( TIM_N(1) |TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(9) )

View File

@ -165,4 +165,4 @@
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 9 #define USABLE_TIMER_CHANNEL_COUNT 9
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8) | TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8))

View File

@ -130,4 +130,4 @@
#define TARGET_IO_PORTD BIT(2) #define TARGET_IO_PORTD BIT(2)
#define USABLE_TIMER_CHANNEL_COUNT 13 #define USABLE_TIMER_CHANNEL_COUNT 13
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9)) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) )

View File

@ -143,4 +143,4 @@
#define TARGET_IO_PORTD 0xffff #define TARGET_IO_PORTD 0xffff
#define USABLE_TIMER_CHANNEL_COUNT 10 #define USABLE_TIMER_CHANNEL_COUNT 10
#define USED_TIMERS (TIM_N(1)|TIM_N(2)|TIM_N(3)|TIM_N(4)|TIM_N(8)|TIM_N(12)) #define USED_TIMERS (TIM_N(1) | TIM_N(3 ) |TIM_N(4) | TIM_N(8) | TIM_N(12))

View File

@ -112,4 +112,4 @@
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 17 #define USABLE_TIMER_CHANNEL_COUNT 17
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(15) | TIM_N(16) |TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(15) | TIM_N(17))

View File

@ -112,4 +112,4 @@
#define TARGET_IO_PORTF (BIT(4)) #define TARGET_IO_PORTF (BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 11 #define USABLE_TIMER_CHANNEL_COUNT 11
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(15) | TIM_N(16) | TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(15) | TIM_N(17))

View File

@ -114,4 +114,4 @@
#define USABLE_TIMER_CHANNEL_COUNT 8 #define USABLE_TIMER_CHANNEL_COUNT 8
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11)) #define USED_TIMERS ( TIM_N(2) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9) )

View File

@ -182,6 +182,6 @@
#define TARGET_IO_PORTC 0xffff #define TARGET_IO_PORTC 0xffff
#define TARGET_IO_PORTD (BIT(2)) #define TARGET_IO_PORTD (BIT(2))
#define USABLE_TIMER_CHANNEL_COUNT 12 #define USABLE_TIMER_CHANNEL_COUNT 5
#define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(8) | TIM_N(9) ) #define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(4) )

View File

@ -177,7 +177,8 @@
#ifdef LUXV2_RACE #ifdef LUXV2_RACE
#define USABLE_TIMER_CHANNEL_COUNT 6 #define USABLE_TIMER_CHANNEL_COUNT 6
#define USED_TIMERS (TIM_N(1) | TIM_N(3) | TIM_N(8) | TIM_N(16))
#else #else
#define USABLE_TIMER_CHANNEL_COUNT 12 #define USABLE_TIMER_CHANNEL_COUNT 12
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8) | TIM_N(15) | TIM_N(16))
#endif #endif
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8) | TIM_N(15))

View File

@ -107,4 +107,4 @@
#define TARGET_IO_PORTC (BIT(13)|BIT(14)|BIT(15)) #define TARGET_IO_PORTC (BIT(13)|BIT(14)|BIT(15))
#define USABLE_TIMER_CHANNEL_COUNT 10 #define USABLE_TIMER_CHANNEL_COUNT 10
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(15) | TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(15) | TIM_N(16) | TIM_N(17))

View File

@ -174,5 +174,5 @@
#define TARGET_IO_PORTC (0xffff & ~(BIT(15)|BIT(14)|BIT(13))) #define TARGET_IO_PORTC (0xffff & ~(BIT(15)|BIT(14)|BIT(13)))
#define TARGET_IO_PORTD BIT(2) #define TARGET_IO_PORTD BIT(2)
#define USABLE_TIMER_CHANNEL_COUNT 12 #define USABLE_TIMER_CHANNEL_COUNT 8
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) ) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8))

View File

@ -58,7 +58,7 @@
#define USE_FAKE_BARO #define USE_FAKE_BARO
#define USE_BARO_MS5611 #define USE_BARO_MS5611
#define USABLE_TIMER_CHANNEL_COUNT 16 #define USABLE_TIMER_CHANNEL_COUNT 11
#define USE_VCP #define USE_VCP
#define USE_USB_DETECT #define USE_USB_DETECT
@ -158,4 +158,4 @@
#define TARGET_IO_PORTF 0xffff #define TARGET_IO_PORTF 0xffff
#define TARGET_IO_PORTG 0xffff #define TARGET_IO_PORTG 0xffff
#define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11)) #define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(9) | TIM_N(12) )

View File

@ -58,7 +58,7 @@
#define USE_FAKE_BARO #define USE_FAKE_BARO
#define USE_BARO_MS5611 #define USE_BARO_MS5611
#define USABLE_TIMER_CHANNEL_COUNT 11 #define USABLE_TIMER_CHANNEL_COUNT 9
#define USE_VCP #define USE_VCP
#define USE_USB_DETECT #define USE_USB_DETECT
@ -164,4 +164,4 @@
#define TARGET_IO_PORTE 0xffff #define TARGET_IO_PORTE 0xffff
#define TARGET_IO_PORTF 0xffff #define TARGET_IO_PORTF 0xffff
#define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11)) #define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(9) | TIM_N(12) )

View File

@ -282,5 +282,5 @@
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(10) | TIM_N(12) | TIM_N(8) | TIM_N(9)) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(10) | TIM_N(12) | TIM_N(8) | TIM_N(9))
#else #else
#define USABLE_TIMER_CHANNEL_COUNT 14 #define USABLE_TIMER_CHANNEL_COUNT 14
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9)) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(8) | TIM_N(12) )
#endif #endif

View File

@ -178,5 +178,9 @@
#define TARGET_IO_PORTC (0xffff & ~(BIT(15)|BIT(14)|BIT(13))) #define TARGET_IO_PORTC (0xffff & ~(BIT(15)|BIT(14)|BIT(13)))
#define TARGET_IO_PORTD BIT(2) #define TARGET_IO_PORTD BIT(2)
#if defined(OMNIBUSF4FW) || defined(OMNIBUSF4FW1)
#define USABLE_TIMER_CHANNEL_COUNT 15 #define USABLE_TIMER_CHANNEL_COUNT 15
#else
#define USABLE_TIMER_CHANNEL_COUNT 14
#endif
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11)) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11))

View File

@ -197,5 +197,5 @@
#define TARGET_IO_PORTC (0xffff) #define TARGET_IO_PORTC (0xffff)
#define TARGET_IO_PORTD BIT(2) #define TARGET_IO_PORTD BIT(2)
#define USABLE_TIMER_CHANNEL_COUNT 22 #define USABLE_TIMER_CHANNEL_COUNT 21
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11) | TIM_N(12)) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11) | TIM_N(12))

View File

@ -144,4 +144,4 @@
#endif #endif
#define USABLE_TIMER_CHANNEL_COUNT 6 #define USABLE_TIMER_CHANNEL_COUNT 6
#define USED_TIMERS (TIM_N(2) | TIM_N(3)| TIM_N(4) | TIM_N(8) | TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2)| TIM_N(3) | TIM_N(8) | TIM_N(17))

View File

@ -133,4 +133,4 @@
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 7 #define USABLE_TIMER_CHANNEL_COUNT 7
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(16) | TIM_N(17))

View File

@ -171,5 +171,5 @@
#define TARGET_IO_PORTC 0xffff #define TARGET_IO_PORTC 0xffff
#define TARGET_IO_PORTD (BIT(2)) #define TARGET_IO_PORTD (BIT(2))
#define USABLE_TIMER_CHANNEL_COUNT 11 #define USABLE_TIMER_CHANNEL_COUNT 6
#define USED_TIMERS ( TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(11) ) #define USED_TIMERS ( TIM_N(2) | TIM_N(4) | TIM_N(8) | TIM_N(11) )

View File

@ -146,6 +146,6 @@
#define TARGET_IO_PORTD (BIT(2)) #define TARGET_IO_PORTD (BIT(2))
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4))
#define USED_TIMERS (TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(16) | TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(16))
#define USABLE_TIMER_CHANNEL_COUNT 9 #define USABLE_TIMER_CHANNEL_COUNT 9

View File

@ -105,5 +105,5 @@
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(3)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(3)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 10 #define USABLE_TIMER_CHANNEL_COUNT 10
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(15) | TIM_N(16) |TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(15) | TIM_N(16) |TIM_N(17))

View File

@ -107,4 +107,4 @@
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 11 #define USABLE_TIMER_CHANNEL_COUNT 11
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(15) | TIM_N(17)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(15) | TIM_N(16) | TIM_N(17))

View File

@ -132,4 +132,4 @@
#define TARGET_IO_PORTC 0xffff #define TARGET_IO_PORTC 0xffff
#define USABLE_TIMER_CHANNEL_COUNT 11 #define USABLE_TIMER_CHANNEL_COUNT 11
#define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9)) #define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(8) | TIM_N(12))

View File

@ -218,14 +218,10 @@
#define TARGET_IO_PORTD (BIT(2)) #define TARGET_IO_PORTD (BIT(2))
#define USABLE_TIMER_CHANNEL_COUNT 16 // 4xPWM, 8xESC, 2xESC via UART3 RX/TX, 1xLED Strip, 1xIR. #define USABLE_TIMER_CHANNEL_COUNT 16 // 4xPWM, 8xESC, 2xESC via UART3 RX/TX, 1xLED Strip, 1xIR.
#if (SPRACINGF4NEO_REV >= 2) #if (SPRACINGF4EVO_REV >= 2)
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(9)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(9))
#else #else
#define USE_TIM10_TIM11_FOR_MOTORS #define USE_TIM10_TIM11_FOR_MOTORS
#ifdef USE_TIM10_TIM11_FOR_MOTORS
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11))
#else
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(9))
#endif
#endif #endif

View File

@ -224,4 +224,8 @@
#define TARGET_IO_PORTD (BIT(2)) #define TARGET_IO_PORTD (BIT(2))
#define USABLE_TIMER_CHANNEL_COUNT 14 // 4xPWM, 6xESC, 2xESC via UART3 RX/TX, 1xLED Strip, 1xIR. #define USABLE_TIMER_CHANNEL_COUNT 14 // 4xPWM, 6xESC, 2xESC via UART3 RX/TX, 1xLED Strip, 1xIR.
#if (SPRACINGF4NEO_REV >= 3)
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(4) | TIM_N(8) | TIM_N(9))
#else
#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8) | TIM_N(9)) #define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(8) | TIM_N(9))
#endif

View File

@ -124,4 +124,4 @@
#define TARGET_IO_PORTD 0xffff #define TARGET_IO_PORTD 0xffff
#define USABLE_TIMER_CHANNEL_COUNT 7 #define USABLE_TIMER_CHANNEL_COUNT 7
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8)) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) )

View File

@ -172,4 +172,4 @@
#define TARGET_IO_PORTE 0xffff #define TARGET_IO_PORTE 0xffff
#define USABLE_TIMER_CHANNEL_COUNT 12 #define USABLE_TIMER_CHANNEL_COUNT 12
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9) ) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(9) )

View File

@ -136,4 +136,4 @@
#define TARGET_IO_PORTD (BIT(2)) #define TARGET_IO_PORTD (BIT(2))
#define USABLE_TIMER_CHANNEL_COUNT 7 #define USABLE_TIMER_CHANNEL_COUNT 7
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8)) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) )

View File

@ -124,5 +124,5 @@
#define TARGET_IO_PORTC (BIT(13)|BIT(14)|BIT(15)) #define TARGET_IO_PORTC (BIT(13)|BIT(14)|BIT(15))
#define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(3)|BIT(4)) #define TARGET_IO_PORTF (BIT(0)|BIT(1)|BIT(3)|BIT(4))
#define USABLE_TIMER_CHANNEL_COUNT 17 #define USABLE_TIMER_CHANNEL_COUNT 15
#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(15) | TIM_N(16) | TIM_N(17) ) #define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) | TIM_N(15) | TIM_N(16) | TIM_N(17) )

View File

@ -145,4 +145,4 @@
#define TARGET_IO_PORTD (BIT(2)) #define TARGET_IO_PORTD (BIT(2))
#define USABLE_TIMER_CHANNEL_COUNT 9 #define USABLE_TIMER_CHANNEL_COUNT 9
#define USED_TIMERS (TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(12)) #define USED_TIMERS (TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8) | TIM_N(12))

View File

@ -13,15 +13,19 @@
USER_DIR = ../main USER_DIR = ../main
TEST_DIR = unit TEST_DIR = unit
ROOT = ../.. ROOT = ../..
OBJECT_DIR = ../../obj/test
TARGET_DIR = $(USER_DIR)/target
include $(ROOT)/make/system-id.mk include $(ROOT)/make/system-id.mk
include $(ROOT)/make/targets_list.mk
# specify which files that are included in the test in addition to the unittest file. # specify which files that are included in the test in addition to the unittest file.
# variables available: # variables available:
# <test_name>_SRC # <test_name>_SRC
# <test_name>_DEFINES # <test_name>_DEFINES
# <test_name>_INCLUDE_DIRS # <test_name>_INCLUDE_DIRS
# <test_name>_EXPAND (run for each target, call the above with target as $1)
# <test_name>_BLACKLIST (targets to exclude from an expanded test's run)
alignsensor_unittest_SRC := \ alignsensor_unittest_SRC := \
$(USER_DIR)/sensors/boardalignment.c \ $(USER_DIR)/sensors/boardalignment.c \
@ -39,9 +43,9 @@ atomic_unittest_SRC := \
$(USER_DIR)/build/atomic.c \ $(USER_DIR)/build/atomic.c \
$(TEST_DIR)/atomic_unittest_c.c $(TEST_DIR)/atomic_unittest_c.c
baro_bmp085_unittest_SRC := \ #baro_bmp085_unittest_SRC := \
$(USER_DIR)/drivers/barometer/barometer_bmp085.c \ # $(USER_DIR)/drivers/barometer/barometer_bmp085.c \
$(USER_DIR)/drivers/io.c # $(USER_DIR)/drivers/io.c
baro_bmp280_unittest_SRC := \ baro_bmp280_unittest_SRC := \
@ -58,9 +62,9 @@ baro_ms5611_unittest_DEFINES := \
USE_BARO_MS5611 \ USE_BARO_MS5611 \
USE_BARO_SPI_MS5611 USE_BARO_SPI_MS5611
battery_unittest_SRC := \ #battery_unittest_SRC := \
$(USER_DIR)/sensors/battery.c \ # $(USER_DIR)/sensors/battery.c \
$(USER_DIR)/common/maths.c # $(USER_DIR)/common/maths.c
blackbox_unittest_SRC := \ blackbox_unittest_SRC := \
@ -265,16 +269,25 @@ telemetry_ibus_unittest_SRC := \
$(USER_DIR)/telemetry/ibus_shared.c \ $(USER_DIR)/telemetry/ibus_shared.c \
$(USER_DIR)/telemetry/ibus.c $(USER_DIR)/telemetry/ibus.c
timer_definition_unittest_EXPAND := yes
# SITL is a simulator; NERO and STM32F7X2 don't define USED_TIMERS in target.h.
timer_definition_unittest_BLACKLIST := STM32F7X2 SITL NERO
timer_definition_unittest_SRC = \
$(TARGET_DIR)/$(call get_base_target,$1)/target.c
timer_definition_unittest_DEFINES = \
TARGET=$(call get_base_target,$1)
timer_definition_unittest_INCLUDE_DIRS = \
$(TEST_DIR)/timer_definition_unittest.include \
$(TARGET_DIR)/$(call get_base_target,$1)
transponder_ir_unittest_SRC := \ transponder_ir_unittest_SRC := \
$(USER_DIR)/drivers/transponder_ir_ilap.c \ $(USER_DIR)/drivers/transponder_ir_ilap.c \
$(USER_DIR)/drivers/transponder_ir_arcitimer.c $(USER_DIR)/drivers/transponder_ir_arcitimer.c
type_conversion_unittest_SRC := \
$(USER_DIR)/common/typeconversion.c
ws2811_unittest_SRC := \ ws2811_unittest_SRC := \
$(USER_DIR)/drivers/light_ws2811strip.c $(USER_DIR)/drivers/light_ws2811strip.c
@ -333,11 +346,6 @@ vtx_unittest_DEFINES := \
# Remember to tweak this if you move this file. # Remember to tweak this if you move this file.
GTEST_DIR = ../../lib/test/gtest GTEST_DIR = ../../lib/test/gtest
USER_INCLUDE_DIR = $(USER_DIR)
OBJECT_DIR = ../../obj/test
# Use clang/clang++ by default # Use clang/clang++ by default
CC := clang CC := clang
CXX := clang++ CXX := clang++
@ -388,8 +396,10 @@ LDFLAGS += -Wl,-T,$(TEST_DIR)/pg.ld -Wl,-Map,$(OBJECT_DIR)/$@.map
endif endif
# Gather up all of the tests. # Gather up all of the tests.
TEST_SRC = $(sort $(wildcard $(TEST_DIR)/*.cc)) TEST_SRCS = $(sort $(wildcard $(TEST_DIR)/*.cc))
TESTS = $(TEST_SRC:$(TEST_DIR)/%.cc=%) TEST_BASENAMES = $(TEST_SRCS:$(TEST_DIR)/%.cc=%)
TESTS = $(foreach test,$(TEST_BASENAMES),$(if $($(test)_EXPAND),$(foreach \
target,$(filter-out $($(test)_BLACKLIST),$(VALID_TARGETS)),$(test).$(target)),$(test)))
# All Google Test headers. Usually you shouldn't change this # All Google Test headers. Usually you shouldn't change this
# definition. # definition.
@ -470,69 +480,119 @@ $(OBJECT_DIR)/gtest_main.a : $(OBJECT_DIR)/gtest-all.o $(OBJECT_DIR)/gtest_main.
$(OBJECT_DIR)/gtest_main.d $(OBJECT_DIR)/gtest_main.d
# includes in test dir must override includes in user dir # includes in test dir must override includes in user dir, unless the user
TEST_INCLUDE_DIRS := $(TEST_DIR) \ # specifies a list of endorsed directories in ${target}_INCLUDE_DIRS.
$(USER_INCLUDE_DIR) test_include_dirs = $1 $(TEST_DIR) $(USER_DIR)
test_cflags = $(addprefix -I,$(call test_include_dirs,$1))
TEST_CFLAGS = $(addprefix -I,$(TEST_INCLUDE_DIRS))
# target name extractor
# param $1 = expanded test name in the form of test.target
target = $(1:$(basename $1).%=%)
# canned recipe for all test builds # canned recipe for all test builds
# param $1 = testname #
# variable expansion rules of thumb (number of $'s):
# * parameters: one $, e.g. $1
# * statically accessed variables set elsewhere: one $, e.g. $(C_FLAGS)
# * dynamically accessed variables set elsewhere: one $, e.g. $($1_SRC)
# * make functions accessing only the above: one $, e.g. $(basename $1)
# * dynamically set and accessed variables: two $, e.g. $$($1_OBJS)
# * make functions accessing dynamically set variables: two $,
# e.g. $$(call test_cflags,$$($1_INCLUDE_DIRS))
#
# param $1 = plain test name for global tests, test.target for per-target tests
define test-specific-stuff define test-specific-stuff
$$1_OBJS = $$(patsubst $$(TEST_DIR)%,$$(OBJECT_DIR)/$1%, $$(patsubst $$(USER_DIR)%,$$(OBJECT_DIR)/$1%,$$($1_SRC:=.o))) ifeq ($1,$(basename $1))
# standard global test
$1_OBJS = $(patsubst \
$(TEST_DIR)/%,$(OBJECT_DIR)/$1/%,$(patsubst \
$(USER_DIR)/%,$(OBJECT_DIR)/$1/%,$($1_SRC:=.o)))
else
# test executed for each target, $1 has the form of test.target
$1_SRC = $(addsuffix .o,$(call $(basename $1)_SRC,$(call target,$1)))
$1_OBJS = $$(patsubst \
$(TEST_DIR)/%,$(OBJECT_DIR)/$1/%,$$(patsubst \
$(USER_DIR)/%,$(OBJECT_DIR)/$1/%,$$(patsubst \
$(TARGET_DIR)/$(call get_base_target,$(call target,$1))/%,$(OBJECT_DIR)/$1/%,$$($1_SRC))))
$1_DEFINES = $(call $(basename $1)_DEFINES,$(call target,$1))
$1_INCLUDE_DIRS = $(call $(basename $1)_INCLUDE_DIRS,$(call target,$1))
endif
# $$(info $1 -v-v-------) # $$(info $1 -v-v-------)
# $$(info $1_SRC: $($1_SRC)) # $$(info $1_SRC: $$($1_SRC))
# $$(info $1_OBJS: $$($$1_OBJS)) # $$(info $1_OBJS: $$($1_OBJS))
# $$(info $1 -^-^-------) # $$(info $1 -^-^-------)
# include generated dependencies
#include generated dependencies -include $$($1_OBJS:.o=.d)
-include $$($$1_OBJS:.o=.d) -include $(OBJECT_DIR)/$1/$(basename $1).d
-include $(OBJECT_DIR)/$1/$1.d
$(OBJECT_DIR)/$1/%.c.o: $(USER_DIR)/%.c $(OBJECT_DIR)/$1/%.c.o: $(USER_DIR)/%.c
@echo "compiling $$<" "$(STDOUT)" @echo "compiling $$<" "$(STDOUT)"
$(V1) mkdir -p $$(dir $$@) $(V1) mkdir -p $$(dir $$@)
$(V1) $(CC) $(C_FLAGS) $(TEST_CFLAGS) \ $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
$(foreach def,$($1_INCLUDE_DIRS),-I $(def)) \ $$(foreach def,$$($1_DEFINES),-D $$(def)) \
$(foreach def,$($1_DEFINES),-D $(def)) \
-c $$< -o $$@ -c $$< -o $$@
$(OBJECT_DIR)/$1/%.c.o: $(TEST_DIR)/%.c $(OBJECT_DIR)/$1/%.c.o: $(TEST_DIR)/%.c
@echo "compiling test c file: $$<" "$(STDOUT)" @echo "compiling test c file: $$<" "$(STDOUT)"
$(V1) mkdir -p $$(dir $$@) $(V1) mkdir -p $$(dir $$@)
$(V1) $(CC) $(C_FLAGS) $(TEST_CFLAGS) \ $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
$(foreach def,$($1_INCLUDE_DIRS),-I $(def)) \ $$(foreach def,$$($1_DEFINES),-D $$(def)) \
$(foreach def,$($1_DEFINES),-D $(def)) \
-c $$< -o $$@ -c $$< -o $$@
$(OBJECT_DIR)/$1/$1.o: $(TEST_DIR)/$1.cc ifneq ($1,$(basename $1))
# per-target tests may compile files from the target directory
$(OBJECT_DIR)/$1/%.c.o: $(TARGET_DIR)/$(call get_base_target,$(call target,$1))/%.c
@echo "compiling target c file: $$<" "$(STDOUT)"
$(V1) mkdir -p $$(dir $$@)
$(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
$$(foreach def,$$($1_DEFINES),-D $$(def)) \
-c $$< -o $$@
endif
$(OBJECT_DIR)/$1/$(basename $1).o: $(TEST_DIR)/$(basename $1).cc
@echo "compiling $$<" "$(STDOUT)" @echo "compiling $$<" "$(STDOUT)"
$(V1) mkdir -p $$(dir $$@) $(V1) mkdir -p $$(dir $$@)
$(V1) $(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) \ $(V1) $(CXX) $(CXX_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
$(foreach def,$($1_INCLUDE_DIRS),-I $(def)) \ $$(foreach def,$$($1_DEFINES),-D $$(def)) \
$(foreach def,$($1_DEFINES),-D $(def)) \
-c $$< -o $$@ -c $$< -o $$@
$(OBJECT_DIR)/$1/$(basename $1): $$($1_OBJS) \
$(OBJECT_DIR)/$1/$1 : $$($$1_OBJS) \ $(OBJECT_DIR)/$1/$(basename $1).o \
$(OBJECT_DIR)/$1/$1.o \
$(OBJECT_DIR)/gtest_main.a $(OBJECT_DIR)/gtest_main.a
@echo "linking $$@" "$(STDOUT)" @echo "linking $$@" "$(STDOUT)"
$(V1) mkdir -p $(dir $$@) $(V1) mkdir -p $(dir $$@)
$(V1) $(CXX) $(CXX_FLAGS) $(LDFLAGS) $$^ -o $$@ $(V1) $(CXX) $(CXX_FLAGS) $(LDFLAGS) $$^ -o $$@
test_$1: $(OBJECT_DIR)/$1/$1 test_$1: $(OBJECT_DIR)/$1/$(basename $1)
$(V1) $$< $$(EXEC_OPTS) "$(STDOUT)" && echo "running $$@: PASS" $(V1) $$< $$(EXEC_OPTS) "$(STDOUT)" && echo "running $$@: PASS"
endef endef
#apply the canned recipe above to all tests
$(eval $(foreach test,$(TESTS),$(call test-specific-stuff,$(test)))) $(eval $(foreach test,$(TESTS),$(call test-specific-stuff,$(test))))
$(foreach test,$(TESTS),$(if $($(basename $(test))_SRC),,$(error \
Test 'unit/$(basename $(test)).cc' has no '$(basename $(test))_SRC' variable defined)))
$(foreach var,$(filter-out TARGET_SRC,$(filter %_SRC,$(.VARIABLES))),$(if $(filter $(var:_SRC=)%,$(TESTS)),,$(error \
Variable '$(var)' has no 'unit/$(var:_SRC=).cc' test)))
target_list:
@echo ========== BASE TARGETS ==========
@echo $(BASE_TARGETS)
@echo ========== ALT TARGETS ==========
@echo $(ALT_TARGETS)
@echo ========== VALID_TARGETS ==========
@echo $(VALID_TARGETS)
@echo ========== BASE/ALT PAIRS ==========
@echo $(BASE_ALT_PAIRS)
@echo ========== ALT/BASE MAPPING ==========
@echo $(foreach target,$(ALT_TARGETS),$(target)\>$(call get_base_target,$(target)))
@echo ========== ALT/BASE FULL MAPPING ==========
@echo $(foreach target,$(VALID_TARGETS),$(target)\>$(call get_base_target,$(target)))

View File

@ -0,0 +1,103 @@
/*
* This file is part of Betaflight.
*
* Betaflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Betaflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Betaflight. If not, see <http://www.gnu.org/licenses/>.
*/
extern "C" {
#include <target.h>
#include <drivers/timer.h>
extern const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT];
}
#include <bitset>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include "gtest/gtest.h"
TEST(TimerDefinitionTest, Test_counterMismatch) {
for (const timerHardware_t &t : timerHardware)
ASSERT_EQ(&t - timerHardware, t.def_tim_counter)
<< "Counter mismatch in timerHardware (in target.c) at position "
<< &t - timerHardware << "; the array may have uninitialized "
<< "trailing elements. This happens when USABLE_TIMER_CHANNEL_COUNT"
<< " is not equal to the number of array initializers. Current "
<< "value is " << USABLE_TIMER_CHANNEL_COUNT << ", last initialized"
<< " array element appears to be " << &t - timerHardware - 1 << '.';
}
TEST(TimerDefinitionTest, Test_duplicatePin) {
std::set<TestPinEnum> usedPins;
for (const timerHardware_t &t : timerHardware)
EXPECT_TRUE(usedPins.emplace(t.pin).second)
<< "Pin " << TEST_PIN_NAMES[t.pin] << " is used more than once. "
<< "This is a problem with the timerHardware array (in target.c). "
<< "Check the array for typos. Then check the size of the array "
<< "initializers; it must be USABLE_TIMER_CHANNEL_COUNT.";
EXPECT_EQ(USABLE_TIMER_CHANNEL_COUNT, usedPins.size());
}
namespace {
std::string writeUsedTimers(const std::bitset<TEST_TIMER_SIZE> &tset) {
std::stringstream used_timers;
if (tset.any()) {
unsigned int timer{0};
for (; timer < TEST_TIMER_SIZE; ++timer)
if (tset[timer]) {
used_timers << "( TIM_N(" << timer << ')';
break;
}
for (++timer; timer < TEST_TIMER_SIZE; ++timer)
if (tset[timer]) used_timers << " | TIM_N(" << timer << ')';
used_timers << " )";
} else {
used_timers << "(0)";
}
return used_timers.str();
}
}
TEST(TimerDefinitionTest, Test_usedTimers)
{
std::bitset<TEST_TIMER_SIZE> expected;
for (const timerHardware_t &t : timerHardware)
expected |= TIM_N(t.timer);
const std::bitset<TEST_TIMER_SIZE> actual{USED_TIMERS};
EXPECT_EQ(expected, actual)
<< "Used timers mismatch. target.c says " << expected << ", but "
<< "target.h says " << actual << ". This has two possible causes: "
<< "(1) The USED_TIMERS bitmap (in target.h) is outdated and out of "
<< "sync with timerHardware (in target.c). (2) There is an "
<< "inconsistency between USABLE_TIMER_CHANNEL_COUNT and the length "
<< "of timerHardware's initializer list.";
std::cerr
<< "USED_TIMERS definition based on timerHardware:" << std::endl
<< writeUsedTimers(expected) << std::endl;
}
// STUBS
extern "C" {
void spiPinConfigure(int) {}
int spiPinConfig(int) { return 0; }
void spiInit(int) {}
int i2cConfig(int) { return 0; }
void i2cHardwareConfigure(int) {}
void i2cInit(int) {}
void bstInit(int) {}
}

View File

@ -0,0 +1,21 @@
#include <mock_enums.h>
typedef struct timerHardware_s {
enum TestTimerEnum timer;
enum TestChannelEnum channel;
enum TestPinEnum pin;
enum TestTimUseEnum purpose;
unsigned int def_tim_counter;
} timerHardware_t;
// F7 and F4 have 6 arguments, F3 and F1 have 5 arguments.
#define DEF_TIM(timer_, channel_, pin_, purpose_, ...) \
{ \
.timer = timer_, \
.channel = channel_, \
.pin = pin_, \
.purpose = purpose_, \
.def_tim_counter = __COUNTER__, \
}
#define TIM_N(n) (1 << (n))

View File

@ -0,0 +1,66 @@
#pragma once
enum TestTimerEnum {
TIM0, TIM1, TIM2, TIM3, TIM4, TIM5, TIM6, TIM7, TIM8, TIM9,
TIM10, TIM11, TIM12, TIM13, TIM14, TIM15, TIM16, TIM17, TIM18, TIM19, TIM20,
TEST_TIMER_SIZE,
};
enum TestChannelEnum {
CH0, CH1, CH2, CH3, CH4, CH5, CH6, CH7, CH9, CH10, CH1N, CH2N, CH3N,
TEST_CHANNEL_SIZE,
};
// Keep this in sync with TEST_PIN_NAMES below.
enum TestPinEnum {
PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9,
PA10, PA11, PA12, PA13, PA14, PA15,
PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PB8, PB9,
PB10, PB11, PB12, PB13, PB14, PB15,
PC0, PC1, PC2, PC3, PC4, PC5, PC6, PC7, PC8, PC9,
PC10, PC11, PC12, PC13, PC14, PC15,
PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7, PD8, PD9,
PD10, PD11, PD12, PD13, PD14, PD15,
PE0, PE1, PE2, PE3, PE4, PE5, PE6, PE7, PE8, PE9,
PE10, PE11, PE12, PE13, PE14, PE15,
PF0, PF1, PF2, PF3, PF4, PF5, PF6, PF7, PF8, PF9,
PF10, PF11, PF12, PF13, PF14, PF15,
PG0, PG1, PG2, PG3, PG4, PG5, PG6, PG7, PG8, PG9,
PG10, PG11, PG12, PG13, PG14, PG15,
PH0, PH1, PH2, PH3, PH4, PH5, PH6, PH7, PH8, PH9,
PH10, PH11, PH12, PH13, PH14, PH15, TEST_PIN_SIZE,
};
// Keep this in sync with TestPinEnum above.
const char *const TEST_PIN_NAMES[TEST_PIN_SIZE] = {
"PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9",
"PA10", "PA11", "PA12", "PA13", "PA14", "PA15",
"PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9",
"PB10", "PB11", "PB12", "PB13", "PB14", "PB15",
"PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9",
"PC10", "PC11", "PC12", "PC13", "PC14", "PC15",
"PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9",
"PD10", "PD11", "PD12", "PD13", "PD14", "PD15",
"PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", "PE8", "PE9",
"PE10", "PE11", "PE12", "PE13", "PE14", "PE15",
"PF0", "PF1", "PF2", "PF3", "PF4", "PF5", "PF6", "PF7", "PF8", "PF9",
"PF10", "PF11", "PF12", "PF13", "PF14", "PF15",
"PG0", "PG1", "PG2", "PG3", "PG4", "PG5", "PG6", "PG7", "PG8", "PG9",
"PG10", "PG11", "PG12", "PG13", "PG14", "PG15",
"PH0", "PH1", "PH2", "PH3", "PH4", "PH5", "PH6", "PH7", "PH8", "PH9",
"PH10", "PH11", "PH12", "PH13", "PH14", "PH15",
};
enum TestTimUseEnum {
TIM_USE_ANY,
TIM_USE_BEEPER,
TIM_USE_CAMERA_CONTROL,
TIM_USE_LED,
TIM_USE_MOTOR,
TIM_USE_NONE,
TIM_USE_PPM,
TIM_USE_PWM,
TIM_USE_SERVO,
TIM_USE_TRANSPONDER,
TEST_TIM_USE_SIZE,
};

View File

@ -0,0 +1 @@
void bstInit(int);

View File

@ -0,0 +1,5 @@
#define I2CDEV_2 (1)
int i2cConfig(int);
void i2cHardwareConfigure(int);
void i2cInit(int);

View File

@ -0,0 +1,5 @@
#define SPIDEV_1 (0)
void spiPinConfigure(int);
int spiPinConfig(int);
void spiInit(int);

View File

@ -0,0 +1,5 @@
#include <mock_enums.h>
#include "target/common_pre.h"
#include "target.h"
#include "target/common_post.h"
#include "target/common_defaults_post.h"