Skip to content

Commit dc6dd17

Browse files
authored
Merge pull request #14884 from LDong-Arm/rm_UNITTEST_macro
Remove the `UNITTEST` macro from production code
2 parents fea4e92 + 9b8acca commit dc6dd17

File tree

11 files changed

+37
-40
lines changed

11 files changed

+37
-40
lines changed

UNITTESTS/target_h/platform/cxxsupport/mstd_type_traits

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,14 @@
2020
/* <mstd_type_traits>
2121
*
2222
* - includes toolchain's <type_traits>
23-
* - For ARM C 5, standard C++11/14 features:
24-
* - std::integral_constant, std::true_type, std::false_type
25-
* - primary type categories (std::is_void, std::is_integral etc)
26-
* - composite type categories (std::is_reference etc)
27-
* - type properties (std::is_const, std::is_constructible etc), except std::is_final
28-
* - type property queries (std::alignment_of, std::rank, std::extent)
29-
* - type relations (std::is_same, std::is_base_of, std::is_convertible)
30-
* - const-volatile modifications (std::remove_cv, std::add_const etc)
31-
* - reference modifications (std::remove_reference, std::add_lvalue_reference etc)
32-
* - sign modifications (std::make_signed, std::make_unsigned)
33-
* - array modifications (std::remove_extent, std::remove_all_extents)
34-
* - pointer modifications (std::remove_pointer, std::add_pointer)
35-
* - other modifications:
36-
* - std::aligned_storage
37-
* - std::decay
38-
* - std::enable_if
39-
* - std::conditional
40-
* - std::common_type
41-
* - std::underlying_type
42-
* - std::result_of
4323
* - For all toolchains, C++17/20 backports:
4424
* - mstd::type_identity
4525
* - mstd::bool_constant
4626
* - mstd::void_t
4727
* - mstd::is_invocable, mbed::is_invocable_r, etc
4828
* - mstd::invoke_result
4929
* - logical operator traits (mstd::conjunction, mstd::disjunction, mstd::negation)
30+
* - mstd::is_constant_evaluated
5031
*/
5132

5233
#include <mstd_cstddef>
@@ -55,7 +36,6 @@
5536
// The template stuff in here is too confusing for astyle
5637
// *INDENT-OFF*
5738

58-
5939
namespace mstd {
6040

6141
/* C++20 type identity */
@@ -92,6 +72,10 @@ template <typename F, typename... Args>
9272
struct invoke_result;
9373
#endif
9474

75+
} // namespace mstd
76+
77+
namespace mstd {
78+
9579
using std::is_same;
9680
using std::conditional;
9781
using std::conditional_t;
@@ -462,8 +446,30 @@ struct is_nothrow_invocable_r : impl::is_invocable_r<R, invoke_result<F, Args...
462446

463447
#endif // __cpp_lib_is_invocable
464448

449+
/* C++20 is_constant_evaluated */
450+
constexpr bool is_constant_evaluated() noexcept
451+
{
452+
#ifdef __clang__
453+
#if __has_builtin(__builtin_is_constant_evaluated)
454+
#define MSTD_HAS_IS_CONSTANT_EVALUATED 1
455+
return __builtin_is_constant_evaluated();
456+
#else
457+
return false;
458+
#endif
459+
#elif __GNUC__ >= 9
460+
#define MSTD_HAS_IS_CONSTANT_EVALUATED 1
461+
return __builtin_is_constant_evaluated();
462+
#else
463+
return false;
464+
#endif
465+
}
465466

466-
} // namespace mstd
467+
#if MSTD_HAS_IS_CONSTANT_EVALUATED
468+
#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED constexpr
469+
#else
470+
#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED
471+
#endif
467472

473+
} // namespace mstd
468474

469475
#endif /* MSTD_TYPE_TRAITS_ */

UNITTESTS/target_h/platform/mbed_assert.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ extern "C" {
4141
*/
4242
// mbed_assert_internal UT stub only prints an assert trace and returns, so therefore
4343
// MBED_NORETURN must not be defined for UTs.
44-
#ifndef UNITTEST
4544
MBED_NORETURN
46-
#endif
4745
void mbed_assert_internal(const char *expr, const char *file, int line);
4846

4947
#ifdef __cplusplus

connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ target_compile_definitions(${TEST_NAME}
1313
DEVICE_INTERRUPTIN=1
1414
MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200
1515
MBED_CONF_CELLULAR_AT_HANDLER_BUFFER_SIZE=32
16+
MBED_CONF_RTOS_PRESENT=1
1617
)
1718

1819
target_sources(${TEST_NAME}

drivers/include/drivers/MbedCRC.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@
2929
#include "platform/SingletonPtr.h"
3030
#include "platform/PlatformMutex.h"
3131

32-
#ifdef UNITTEST
33-
#include <type_traits>
34-
#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED
35-
#else
3632
#include <mstd_type_traits>
37-
#endif
3833

3934
namespace mbed {
4035
/** \addtogroup drivers-public-api */

rtos/include/rtos/Thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "rtos/Semaphore.h"
3434
#include "rtos/Mutex.h"
3535

36-
#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) || defined(UNITTEST)
36+
#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY)
3737

3838
namespace rtos {
3939
/** \addtogroup rtos-public-api */

rtos/include/rtos/internal/mbed_rtos1_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef MBED_RTOS_RTX1_TYPES_H
1818
#define MBED_RTOS_RTX1_TYPES_H
1919

20-
#if MBED_CONF_RTOS_PRESENT || defined(UNITTEST)
20+
#if MBED_CONF_RTOS_PRESENT
2121

2222
#include "cmsis_os.h"
2323

rtos/include/rtos/internal/mbed_rtos_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef MBED_RTOS_STORAGE_H
1818
#define MBED_RTOS_STORAGE_H
1919

20-
#if MBED_CONF_RTOS_PRESENT || defined(UNITTEST)
20+
#if MBED_CONF_RTOS_PRESENT
2121

2222
#include "mbed_rtx_storage.h"
2323

rtos/include/rtos/mbed_rtos_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef RTOS_TYPES_H_
1818
#define RTOS_TYPES_H_
1919

20-
#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) || defined(UNITTEST)
20+
#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY)
2121
#include "cmsis_os2.h"
2222
#else
2323

rtos/tests/UNITTESTS/doubles/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ target_include_directories(mbed-stubs-rtos-headers
1818

1919
add_library(mbed-stubs-rtos)
2020

21-
add_definitions(-DUNITTEST)
21+
target_compile_definitions(mbed-stubs-rtos
22+
PRIVATE
23+
MBED_CONF_RTOS_PRESENT=1
24+
)
2225

2326
target_sources(mbed-stubs-rtos
2427
PRIVATE

storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_executable(${TEST_NAME})
77

88
target_compile_definitions(${TEST_NAME}
99
PRIVATE
10-
UNITTEST
1110
MBED_LFS_READ_SIZE=64
1211
MBED_LFS_PROG_SIZE=64
1312
MBED_LFS_BLOCK_SIZE=512

storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ set(TEST_NAME tdbstore-unittest)
55

66
add_executable(${TEST_NAME})
77

8-
target_compile_definitions(${TEST_NAME}
9-
PRIVATE
10-
UNITTEST
11-
)
12-
138
target_sources(${TEST_NAME}
149
PRIVATE
1510
${mbed-os_SOURCE_DIR}/storage/blockdevice/source/HeapBlockDevice.cpp

0 commit comments

Comments
 (0)