From bb8650179c006608e510b2e41971b2dd3c20e090 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 11 Nov 2020 17:34:39 -0800 Subject: [PATCH] consolidate EFI_UNIT_TEST and friends (#1940) * restructure * guard c++ * idle too * status_loop.h * consolidate definitions * use 1/0 instead, check for existence * missed a few * dead define * defs for bootloader --- firmware/Makefile | 5 ++++- firmware/bootloader/src/Makefile | 2 ++ firmware/config/boards/hellen/cypress/efifeatures.h | 11 ----------- firmware/config/boards/kinetis/efifeatures.h | 11 ----------- firmware/config/boards/skeleton/efifeatures.h | 10 ---------- firmware/config/stm32f4ems/efifeatures.h | 10 ---------- firmware/controllers/core/engine_ptr.h | 12 +++++++++++- firmware/hw_layer/hardware.cpp | 4 ---- simulator/Makefile | 3 ++- simulator/simulator/efifeatures.h | 4 ---- simulator/simulator/global.h | 2 -- unit_tests/Makefile | 3 +++ unit_tests/efifeatures.h | 2 -- 13 files changed, 22 insertions(+), 57 deletions(-) diff --git a/firmware/Makefile b/firmware/Makefile index a5edde2abf..1d605c9d99 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -43,7 +43,10 @@ ifeq ($(USE_OPT),) USE_OPT = $(EXTRA_PARAMS) $(DEBUG_LEVEL_OPT) $(RFLAGS) -fomit-frame-pointer -falign-functions=16 -fsingle-precision-constant endif -USE_OPT += $(RUSEFI_OPT) +# EFI_UNIT_TEST determines if we are running in a unit test (hide things from hw/sim) +# EFI_PROD_CODE determines if we are running on real hardware (hide things from tests/sim) +# EFI_SIMULATOR determines if we are running in the simulator (hide things from hw/tests) +USE_OPT += $(RUSEFI_OPT) -DEFI_UNIT_TEST=0 -DEFI_PROD_CODE=1 -DEFI_SIMULATOR=0 # C specific options here (added to USE_OPT). ifeq ($(USE_COPT),) diff --git a/firmware/bootloader/src/Makefile b/firmware/bootloader/src/Makefile index 2838e3aab6..06ae5a67fe 100644 --- a/firmware/bootloader/src/Makefile +++ b/firmware/bootloader/src/Makefile @@ -28,6 +28,8 @@ DDEFS += -DEFI_USB_SERIAL=FALSE -DHAL_USE_SERIAL_USB=FALSE -DHAL_USE_USB=FALSE - # disable CAN DDEFS += -DEFI_CAN_SUPPORT=FALSE +DDEFS += -DEFI_UNIT_TEST=0 -DEFI_PROD_CODE=1 -DEFI_SIMULATOR=0 + # Compiler options here. ifeq ($(USE_OPT),) USE_OPT = $(EXTRA_PARAMS) $(DEBUG_LEVEL_OPT) $(RFLAGS) -Wno-error=implicit-fallthrough -Wno-error=bool-operation -fomit-frame-pointer -falign-functions=16 -Werror -Wno-error=pointer-sign -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=sign-compare -Wno-error=unused-parameter -Wno-error=missing-field-initializers -Werror=type-limits -Wno-error=strict-aliasing -Wno-error=attributes diff --git a/firmware/config/boards/hellen/cypress/efifeatures.h b/firmware/config/boards/hellen/cypress/efifeatures.h index a668b56fa2..7c6e692463 100644 --- a/firmware/config/boards/hellen/cypress/efifeatures.h +++ b/firmware/config/boards/hellen/cypress/efifeatures.h @@ -200,12 +200,6 @@ #define EFI_EMULATE_POSITION_SENSORS TRUE -/** - * This macros is used to hide pieces of the code from unit tests, so it only makes sense in folders exposed to the tests project. - * This macros is NOT about taking out logging in general. - */ -#define EFI_PROD_CODE TRUE - /** * Do we need file logging (like SD card) logic? */ @@ -352,8 +346,6 @@ #define EFI_WARNING_LED FALSE -#define EFI_UNIT_TEST FALSE - #undef CONSOLE_MODE_SWITCH_PORT #undef CONFIG_RESET_SWITCH_PORT @@ -391,7 +383,6 @@ [7] = {.port = NULL, .pad = 0}, #define EFI_BOSCH_YAW FALSE -#define ADC_SNIFFER FALSE #define GPTDEVICE GPTD1 @@ -404,8 +395,6 @@ #define EXTREME_TERM_LOGGING FALSE #define EFI_PRINTF_FUEL_DETAILS FALSE -#define EFI_SIMULATOR FALSE - #define RAM_UNUSED_SIZE 1 #define CCM_UNUSED_SIZE 1 diff --git a/firmware/config/boards/kinetis/efifeatures.h b/firmware/config/boards/kinetis/efifeatures.h index fee008641f..da5a1e1ef5 100644 --- a/firmware/config/boards/kinetis/efifeatures.h +++ b/firmware/config/boards/kinetis/efifeatures.h @@ -188,12 +188,6 @@ #define EFI_EMULATE_POSITION_SENSORS FALSE #endif -/** - * This macros is used to hide pieces of the code from unit tests, so it only makes sense in folders exposed to the tests project. - * This macros is NOT about taking out logging in general. - */ -#define EFI_PROD_CODE TRUE - /** * Do we need file logging (like SD card) logic? */ @@ -321,8 +315,6 @@ #define EFI_WARNING_LED FALSE -#define EFI_UNIT_TEST FALSE - #undef CONSOLE_MODE_SWITCH_PORT #undef CONFIG_RESET_SWITCH_PORT @@ -360,7 +352,6 @@ [7] = {.port = NULL, .pad = 0}, #define EFI_BOSCH_YAW FALSE -#define ADC_SNIFFER FALSE #define GPTDEVICE GPTD1 @@ -373,8 +364,6 @@ #define EXTREME_TERM_LOGGING FALSE #define EFI_PRINTF_FUEL_DETAILS FALSE -#define EFI_SIMULATOR FALSE - #define RAM_UNUSED_SIZE 1 #define CCM_UNUSED_SIZE 1 diff --git a/firmware/config/boards/skeleton/efifeatures.h b/firmware/config/boards/skeleton/efifeatures.h index 13adb931c7..c137f3620e 100644 --- a/firmware/config/boards/skeleton/efifeatures.h +++ b/firmware/config/boards/skeleton/efifeatures.h @@ -202,16 +202,6 @@ #define EFI_EMULATE_POSITION_SENSORS TRUE #endif -/** - * This macros is used to hide hardware-specific pieces of the code from unit tests and simulator, so it only makes - * sense in folders exposed to the tests projects (simulator and unit tests). - * This macros is NOT about taking out logging in general. - * See also EFI_UNIT_TEST - * See also EFI_SIMULATOR - * todo: do we want to rename any of these three options? - */ -#define EFI_PROD_CODE TRUE - /** * Do we need file logging (like SD card) logic? */ diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index 29487b322b..905a86aa00 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -243,16 +243,6 @@ #define EFI_EMULATE_POSITION_SENSORS TRUE #endif -/** - * This macros is used to hide hardware-specific pieces of the code from unit tests and simulator, so it only makes - * sense in folders exposed to the tests projects (simulator and unit tests). - * This macros is NOT about taking out logging in general. - * See also EFI_UNIT_TEST - * See also EFI_SIMULATOR - * todo: do we want to rename any of these three options? - */ -#define EFI_PROD_CODE TRUE - /** * Do we need file logging (like SD card) logic? */ diff --git a/firmware/controllers/core/engine_ptr.h b/firmware/controllers/core/engine_ptr.h index 18d584e903..ecfb13202c 100644 --- a/firmware/controllers/core/engine_ptr.h +++ b/firmware/controllers/core/engine_ptr.h @@ -1,6 +1,16 @@ #pragma once -#include "efifeatures.h" +#ifndef EFI_UNIT_TEST +#error EFI_UNIT_TEST must be defined! +#endif + +#ifndef EFI_SIMULATOR +#error EFI_SIMULATOR must be defined! +#endif + +#ifndef EFI_PROD_CODE +#error EFI_PROD_CODE must be defined! +#endif #ifdef __cplusplus class Engine; diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 9597ee1c10..5dfe073fea 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -590,10 +590,6 @@ void initHardware(Logging *l) { initServo(); #endif -#if ADC_SNIFFER - initAdcDriver(); -#endif - #if EFI_AUX_SERIAL initAuxSerial(); #endif /* EFI_AUX_SERIAL */ diff --git a/simulator/Makefile b/simulator/Makefile index f872e13327..cd740317f0 100644 --- a/simulator/Makefile +++ b/simulator/Makefile @@ -40,7 +40,8 @@ ifeq ($(USE_OPT),) endif endif -USE_OPT += $(RUSEFI_OPT) +# See explanation in main firmware Makefile for these three defines +USE_OPT += $(RUSEFI_OPT) -DEFI_UNIT_TEST=0 -DEFI_PROD_CODE=0 -DEFI_SIMULATOR=1 ifeq ($(CCACHE_DIR),) $(info No CCACHE_DIR) diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index c3dd6f9f6a..2e9311f0d3 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -67,8 +67,6 @@ #define CONSOLE_MAX_ACTIONS 256 -#define EFI_SIMULATOR TRUE -#define EFI_PROD_CODE FALSE #define TS_UART_DMA_MODE FALSE #define EFI_MAP_AVERAGING TRUE @@ -157,7 +155,5 @@ */ #define INTERMEDIATE_LOGGING_BUFFER_SIZE 2000 -#define EFI_UNIT_TEST FALSE - #define EFI_BOARD_TEST FALSE #define EFI_JOYSTICK FALSE diff --git a/simulator/simulator/global.h b/simulator/simulator/global.h index 3a0601f721..7e4e8a16eb 100644 --- a/simulator/simulator/global.h +++ b/simulator/simulator/global.h @@ -26,8 +26,6 @@ #define efiSetPadMode(msg, brainPin, mode) {} -#define EFI_UNIT_TEST FALSE - #define hasOsPanicError() (FALSE) #define US_TO_NT_MULTIPLIER 100 diff --git a/unit_tests/Makefile b/unit_tests/Makefile index 8b895e3fd0..a01f6cd03b 100644 --- a/unit_tests/Makefile +++ b/unit_tests/Makefile @@ -35,6 +35,9 @@ endif #USE_OPT += $(RUSEFI_OPT) #USE_OPT += -Wno-error=format= -Wno-error=register -Wno-error=write-strings +# See explanation in main firmware Makefile for these three defines +USE_OPT += -DEFI_UNIT_TEST=1 -DEFI_PROD_CODE=0 -DEFI_SIMULATOR=0 + ifeq ($(CCACHE_DIR),) $(info No CCACHE_DIR) else diff --git a/unit_tests/efifeatures.h b/unit_tests/efifeatures.h index bb96796992..2ee9aa39bb 100644 --- a/unit_tests/efifeatures.h +++ b/unit_tests/efifeatures.h @@ -42,8 +42,6 @@ #define DEBUG_INTERPOLATION TRUE -#define EFI_UNIT_TEST TRUE - #define EFI_FSIO TRUE #define EFI_TEXT_LOGGING TRUE