From 3a243059164015263954df473b823dd200f96a43 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Tue, 6 Jul 2021 16:50:49 +0100 Subject: [PATCH] rtos: Remove UNITTEST macro from rtos Production code should not contain any test-specific checks. Rather than checking `UNITTEST`, unit tests can directly set `MBED_CONF_RTOS_PRESENT=1` to make RTOS available for testing. Note: The cellular ATHandler test also has `MBED_CONF_RTOS_PRESENT=1` added because `ATHandler.cpp` contains a check of this variable. --- .../UNITTESTS/framework/device/athandler/CMakeLists.txt | 1 + rtos/include/rtos/Thread.h | 2 +- rtos/include/rtos/internal/mbed_rtos1_types.h | 2 +- rtos/include/rtos/internal/mbed_rtos_storage.h | 2 +- rtos/include/rtos/mbed_rtos_types.h | 2 +- rtos/tests/UNITTESTS/doubles/CMakeLists.txt | 5 ++++- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt index 428cac1a01..76f3c8af11 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt @@ -13,6 +13,7 @@ target_compile_definitions(${TEST_NAME} DEVICE_INTERRUPTIN=1 MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 MBED_CONF_CELLULAR_AT_HANDLER_BUFFER_SIZE=32 + MBED_CONF_RTOS_PRESENT=1 ) target_sources(${TEST_NAME} diff --git a/rtos/include/rtos/Thread.h b/rtos/include/rtos/Thread.h index ec698c358d..1aa72de714 100644 --- a/rtos/include/rtos/Thread.h +++ b/rtos/include/rtos/Thread.h @@ -33,7 +33,7 @@ #include "rtos/Semaphore.h" #include "rtos/Mutex.h" -#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) || defined(UNITTEST) +#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) namespace rtos { /** \addtogroup rtos-public-api */ diff --git a/rtos/include/rtos/internal/mbed_rtos1_types.h b/rtos/include/rtos/internal/mbed_rtos1_types.h index e178b273c1..a2a18008f4 100644 --- a/rtos/include/rtos/internal/mbed_rtos1_types.h +++ b/rtos/include/rtos/internal/mbed_rtos1_types.h @@ -17,7 +17,7 @@ #ifndef MBED_RTOS_RTX1_TYPES_H #define MBED_RTOS_RTX1_TYPES_H -#if MBED_CONF_RTOS_PRESENT || defined(UNITTEST) +#if MBED_CONF_RTOS_PRESENT #include "cmsis_os.h" diff --git a/rtos/include/rtos/internal/mbed_rtos_storage.h b/rtos/include/rtos/internal/mbed_rtos_storage.h index 750725dc4e..c9b06fa2c8 100644 --- a/rtos/include/rtos/internal/mbed_rtos_storage.h +++ b/rtos/include/rtos/internal/mbed_rtos_storage.h @@ -17,7 +17,7 @@ #ifndef MBED_RTOS_STORAGE_H #define MBED_RTOS_STORAGE_H -#if MBED_CONF_RTOS_PRESENT || defined(UNITTEST) +#if MBED_CONF_RTOS_PRESENT #include "mbed_rtx_storage.h" diff --git a/rtos/include/rtos/mbed_rtos_types.h b/rtos/include/rtos/mbed_rtos_types.h index eaf5da0e3d..40bd9d9165 100644 --- a/rtos/include/rtos/mbed_rtos_types.h +++ b/rtos/include/rtos/mbed_rtos_types.h @@ -17,7 +17,7 @@ #ifndef RTOS_TYPES_H_ #define RTOS_TYPES_H_ -#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) || defined(UNITTEST) +#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) #include "cmsis_os2.h" #else diff --git a/rtos/tests/UNITTESTS/doubles/CMakeLists.txt b/rtos/tests/UNITTESTS/doubles/CMakeLists.txt index 4216a6ab6c..e827f16d45 100644 --- a/rtos/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/rtos/tests/UNITTESTS/doubles/CMakeLists.txt @@ -18,7 +18,10 @@ target_include_directories(mbed-stubs-rtos-headers add_library(mbed-stubs-rtos) -add_definitions(-DUNITTEST) +target_compile_definitions(mbed-stubs-rtos + PRIVATE + MBED_CONF_RTOS_PRESENT=1 +) target_sources(mbed-stubs-rtos PRIVATE