1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 00:35:39 +03:00

Merge pull request #11925 from blckmn/target_removal

Final target clean up
This commit is contained in:
J Blackman 2022-10-29 17:13:30 +11:00 committed by GitHub
commit 3d0681f942
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
67 changed files with 8 additions and 5024 deletions

View file

@ -18,7 +18,6 @@ OBJECT_DIR = ../../obj/test
TARGET_DIR = $(USER_DIR)/target
include $(ROOT)/make/system-id.mk
include $(ROOT)/make/targets_list.mk
VPATH := $(VPATH):$(USER_DIR):$(TEST_DIR)
@ -351,22 +350,6 @@ telemetry_ibus_unittest_SRC := \
$(USER_DIR)/telemetry/ibus_shared.c \
$(USER_DIR)/telemetry/ibus.c
timer_definition_unittest_EXPAND := yes
# SITL is a simulator with empty timerHardware and many hearders in target.c.
timer_definition_unittest_BLACKLIST := SITL
timer_definition_unittest_SRC = \
$(TARGET_DIR)/$(call get_base_target,$1)/target.c
timer_definition_unittest_DEFINES = \
TARGET=$1 \
BASE_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 := \
$(USER_DIR)/drivers/transponder_ir_ilap.c \
$(USER_DIR)/drivers/transponder_ir_arcitimer.c
@ -598,13 +581,9 @@ endif
TEST_SRCS = $(sort $(wildcard $(TEST_DIR)/*.cc))
TEST_BASENAMES = $(TEST_SRCS:$(TEST_DIR)/%.cc=%)
TESTS_TARGET_SPECIFIC = $(foreach test,$(TEST_BASENAMES),$(if $($(test)_EXPAND),$(test)))
TESTS_TARGET_SPECIFIC_EXPANDED = $(foreach test,$(TESTS_TARGET_SPECIFIC),$(foreach \
target,$(filter-out $($(test)_BLACKLIST),$(VALID_TARGETS)),$(test).$(target)))
TESTS = $(foreach test,$(TEST_BASENAMES),$(if $($(test)_EXPAND),,$(test)))
TESTS_ALL = $(TESTS) $(TESTS_TARGET_SPECIFIC_EXPANDED)
TESTS_REPRESENTATIVE = $(TESTS) $(foreach test,$(TESTS_TARGET_SPECIFIC), \
$(test).$(word 1,$(filter-out $($(test)_BLACKLIST),$(VALID_TARGETS))))
TESTS_ALL = $(TESTS)
# All Google Test headers. Usually you shouldn't change this
# definition.
@ -730,7 +709,7 @@ $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))))
$(TARGET_DIR)/$(TARGET)/%,$(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
@ -760,7 +739,7 @@ $(OBJECT_DIR)/$1/%.c.o: $(TEST_DIR)/%.c
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
$(OBJECT_DIR)/$1/%.c.o: $(TARGET_DIR)/$(TARGET)/%.c
@echo "compiling target c file: $$<" "$(STDOUT)"
$(V1) mkdir -p $$(dir $$@)
$(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
@ -801,20 +780,3 @@ endif
$(foreach test,$(TESTS_ALL),$(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_ALL)),,$(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

@ -1,113 +0,0 @@
/*
* 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>
}
#include <bitset>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include "gtest/gtest.h"
#if USABLE_TIMER_CHANNEL_COUNT > 0
extern "C" {
extern const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT];
}
TEST(TimerDefinitionTest, Test_counterMismatch)
{
for (const timerHardware_t &t : timerHardware)
EXPECT_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());
}
#if !defined(USE_TIMER_MGMT)
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;
}
#endif
// 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) {}
}
#endif // USABLE_TIMER_CHANNEL_COUNT > 0