Skip to content

Remove the UNITTEST macro from production code #14884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions UNITTESTS/target_h/platform/cxxsupport/mstd_type_traits
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,14 @@
/* <mstd_type_traits>
*
* - includes toolchain's <type_traits>
* - For ARM C 5, standard C++11/14 features:
* - std::integral_constant, std::true_type, std::false_type
* - primary type categories (std::is_void, std::is_integral etc)
* - composite type categories (std::is_reference etc)
* - type properties (std::is_const, std::is_constructible etc), except std::is_final
* - type property queries (std::alignment_of, std::rank, std::extent)
* - type relations (std::is_same, std::is_base_of, std::is_convertible)
* - const-volatile modifications (std::remove_cv, std::add_const etc)
* - reference modifications (std::remove_reference, std::add_lvalue_reference etc)
* - sign modifications (std::make_signed, std::make_unsigned)
* - array modifications (std::remove_extent, std::remove_all_extents)
* - pointer modifications (std::remove_pointer, std::add_pointer)
* - other modifications:
* - std::aligned_storage
* - std::decay
* - std::enable_if
* - std::conditional
* - std::common_type
* - std::underlying_type
* - std::result_of
* - For all toolchains, C++17/20 backports:
* - mstd::type_identity
* - mstd::bool_constant
* - mstd::void_t
* - mstd::is_invocable, mbed::is_invocable_r, etc
* - mstd::invoke_result
* - logical operator traits (mstd::conjunction, mstd::disjunction, mstd::negation)
* - mstd::is_constant_evaluated
*/

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


namespace mstd {

/* C++20 type identity */
Expand Down Expand Up @@ -92,6 +72,10 @@ template <typename F, typename... Args>
struct invoke_result;
#endif

} // namespace mstd

namespace mstd {

using std::is_same;
using std::conditional;
using std::conditional_t;
Expand Down Expand Up @@ -462,8 +446,30 @@ struct is_nothrow_invocable_r : impl::is_invocable_r<R, invoke_result<F, Args...

#endif // __cpp_lib_is_invocable

/* C++20 is_constant_evaluated */
constexpr bool is_constant_evaluated() noexcept
{
#ifdef __clang__
#if __has_builtin(__builtin_is_constant_evaluated)
#define MSTD_HAS_IS_CONSTANT_EVALUATED 1
return __builtin_is_constant_evaluated();
#else
return false;
#endif
#elif __GNUC__ >= 9
#define MSTD_HAS_IS_CONSTANT_EVALUATED 1
return __builtin_is_constant_evaluated();
#else
return false;
#endif
}

} // namespace mstd
#if MSTD_HAS_IS_CONSTANT_EVALUATED
#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED constexpr
#else
#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED
#endif

} // namespace mstd

#endif /* MSTD_TYPE_TRAITS_ */
2 changes: 0 additions & 2 deletions UNITTESTS/target_h/platform/mbed_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ extern "C" {
*/
// mbed_assert_internal UT stub only prints an assert trace and returns, so therefore
// MBED_NORETURN must not be defined for UTs.
#ifndef UNITTEST
MBED_NORETURN
#endif
void mbed_assert_internal(const char *expr, const char *file, int line);

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
5 changes: 0 additions & 5 deletions drivers/include/drivers/MbedCRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@
#include "platform/SingletonPtr.h"
#include "platform/PlatformMutex.h"

#ifdef UNITTEST
#include <type_traits>
#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED
#else
#include <mstd_type_traits>
#endif

namespace mbed {
/** \addtogroup drivers-public-api */
Expand Down
2 changes: 1 addition & 1 deletion rtos/include/rtos/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion rtos/include/rtos/internal/mbed_rtos1_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion rtos/include/rtos/internal/mbed_rtos_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion rtos/include/rtos/mbed_rtos_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion rtos/tests/UNITTESTS/doubles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ add_executable(${TEST_NAME})

target_compile_definitions(${TEST_NAME}
PRIVATE
UNITTEST
MBED_LFS_READ_SIZE=64
MBED_LFS_PROG_SIZE=64
MBED_LFS_BLOCK_SIZE=512
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ set(TEST_NAME tdbstore-unittest)

add_executable(${TEST_NAME})

target_compile_definitions(${TEST_NAME}
PRIVATE
UNITTEST
)

target_sources(${TEST_NAME}
PRIVATE
${mbed-os_SOURCE_DIR}/storage/blockdevice/source/HeapBlockDevice.cpp
Expand Down