Skip to content

Commit fa1d9c0

Browse files
Cmake: Add backward compatibilty support for MBED_TEST_MODE
Fixes #14494 MBED_TEST_MODE is required for backward compatibilty with CLI1. This adds a test to ensure that the macro is created when using CLI2 for testing. This also adds a test in `.travis.yml` that checks whether CMake defines the macro when BUILD_TESTING is on. CLI1 Reference: https://os.mbed.com/docs/mbed-os/v6.9/debug-test/greentea-for-testing-applications.html Also, explicitly create and set the macro BUILD_TESTING to allow for MBED_TEST_MODE to be defined by CMake. MBED_TEST_MODE is required for backward compatibilty with CLI1. BUILD_TESTING is used to determine whether to define MBED_TEST_MODE. Normally, this would be automatically done by CTest (which we intend to add for test automation) but this hasn't yet been added to our Greentea tests.
1 parent 331473a commit fa1d9c0

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

.travis.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ before_install:
3535

3636
addons:
3737
apt:
38+
sources:
39+
- sourceline: 'deb https://apt.kitware.com/ubuntu/ xenial main'
40+
key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
3841
packages:
3942
- ninja-build
4043
- libncursesw5
44+
- cmake
45+
- ninja-build
4146

4247
matrix:
4348
include:
@@ -279,3 +284,41 @@ matrix:
279284
| while read file; do python ./hal/tests/pinvalidate/pinvalidate.py -vfp "${file}"; done
280285
- git diff --exit-code --diff-filter=d --color
281286

287+
### CMake Check ###
288+
- &cmake-vm
289+
stage: "CMake Check"
290+
name: "Backward compatiblity check - MBED_TEST_MODE"
291+
env: NAME=mbed-test-mode-check ROOT=tools/cmake/tests/mbed_test_mode/ TOOLCHAIN=GCC_ARM TARGET_NAME=K64F PROFILE=develop
292+
language: python
293+
python: 3.8
294+
install:
295+
# Hide Travis-preinstalled CMake
296+
# The Travis-preinstalled CMake is unfortunately not installed via apt, so we
297+
# can't replace it with an apt-supplied version very easily. Additionally, we
298+
# can't permit the Travis-preinstalled copy to survive, as the Travis default
299+
# path lists the Travis CMake install location ahead of any place where apt
300+
# would install CMake to. Instead of apt removing or upgrading to a new CMake
301+
# version, we must instead delete the Travis copy of CMake.
302+
- sudo rm -rf /usr/local/cmake*
303+
# Setup ccache
304+
- ccache -o compiler_check=content
305+
- ccache -M 1G
306+
- pushd /usr/lib/ccache
307+
- sudo ln -s ../../bin/ccache arm-none-eabi-gcc
308+
- sudo ln -s ../../bin/ccache arm-none-eabi-g++
309+
- export PATH="/usr/lib/ccache:$PATH"
310+
- popd
311+
# Install arm-none-eabi-gcc
312+
- pushd /home/travis/build && mkdir arm-gcc && cd arm-gcc
313+
- curl -L0 "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2?revision=05382cca-1721-44e1-ae19-1e7c3dc96118&la=en&hash=D7C9D18FCA2DD9F894FD9F3C3DC9228498FA281A" --output gcc-arm-none-eabi-9-2020-q2-update.tar.bz2
314+
- tar xf gcc-arm-none-eabi-9-2020-q2-update.tar.bz2
315+
- export PATH="$PATH:${PWD}/gcc-arm-none-eabi-9-2020-q2-update/bin"
316+
- popd
317+
- arm-none-eabi-gcc --version
318+
# Install python modules
319+
- pip install --upgrade mbed-tools
320+
- pip install -r tools/cmake/requirements.txt
321+
script:
322+
- mbedtools configure -p ${ROOT} -t ${TOOLCHAIN} -m ${TARGET_NAME} --mbed-os-path .
323+
- cmake -S ${ROOT} -B ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/ -GNinja -DCMAKE_BUILD_TYPE=${PROFILE}
324+
- cmake --build ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ target_compile_definitions(mbed-core
7979
${MBED_CONFIG_DEFINITIONS}
8080
)
8181

82+
# Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
83+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
84+
target_compile_definitions(${PROJECT_NAME}
85+
PUBLIC
86+
MBED_TEST_MODE
87+
)
88+
endif()
89+
8290
# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
8391
# script, because of path length limitations on Windows. We set the response file and bind the path
8492
# to a global property here. The MBED_TARGET being built queries this global property when it sets

tools/cmake/mbed_greentea.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ macro(mbed_greentea_add_test)
4141

4242
add_executable(${TEST_NAME})
4343

44+
# Explicitly enable BUILD_TESTING until CTest is added to the Greentea client
45+
set(BUILD_TESTING ON)
46+
4447
mbed_configure_app_target(${TEST_NAME})
4548

4649
target_include_directories(${TEST_NAME}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2020 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5+
6+
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../.. CACHE INTERNAL "")
7+
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STATIC "")
8+
9+
include(${MBED_PATH}/tools/cmake/app.cmake)
10+
11+
add_executable(mbed-test-mode-check)
12+
project(mbed-test-mode-check)
13+
14+
set(PROJECT_NAME ${CMAKE_PROJECT_NAME} CACHE INTERNAL "")
15+
include(CTest)
16+
17+
target_sources(mbed-test-mode-check
18+
PRIVATE
19+
main.cpp
20+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2021 Arm Limited and Contributors. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#if BUILD_TESTING && !defined(MBED_TEST_MODE)
8+
#error "MBED_TEST_MODE not defined with BUILD_TESTING on"
9+
#else
10+
int main(){
11+
return 1;
12+
}
13+
#endif

0 commit comments

Comments
 (0)