I can't understand how to compile Unit Tests with MCUXpresso IDE - Vscode

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

I can't understand how to compile Unit Tests with MCUXpresso IDE - Vscode

899 次查看
RafaelFernandes
Contributor I

Hi everyone,

I'm developing firmware for the Cortex-M7 core of the i.MX8MP using the MCUXpresso IDE extension for VSCode. I usually build the project using the extension's shortcuts, which works fine for regular development.

However, I'm now trying to run unit tests using uCUnit, and I'm stuck because I have no idea how to compile the test code. I initially tried editing the CMake files, but I'm still a beginner when it comes to build systems, and nothing I tried worked.

Eventually, I realized that the MCUXpresso extension might not even be using the CMakeLists.txt file the way I expected. Now I'm not sure how the build process is actually managed or how I can hook into it to run my tests.

Does anyone know a simple way to automate unit testing within this IDE extension setup? Any guidance would be appreciated!

Thanks in advance!

0 项奖励
回复
2 回复数

865 次查看
ErichStyger
Specialist I

I'm using unit testing for example with the LPC55Sxx, see for example https://mcuoneclipse.com/2024/10/20/on-target-testing-with-linkserver-runner-and-vs-code/. 

The article has a link to the GitHub repository with the CMake files and setup, and is using LinkServer and/or J-Link as test runner.

I hope this helps,

Erich

0 项奖励
回复

872 次查看
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hello,

The MCUXpresso VSCode extension is not a pure CMake project. It is driven by CMake + NXP SDK + specific templates, but a lot of the build details are encapsulated in the CMake module provided by NXP. As a result, the project's CMakeLists.txt file is not the core file that tells everything, and may not take effect after you edit it.

If you need to add uCUnit, you can refer below steps:

1. Create a new test_runner.c including unit test

2.Using #ifdef to switch test code or normal code

// main.c
#ifdef RUN_TESTS
extern void run_tests(void);
int main(void) {
    run_tests();
    while (1); // 
}
#else
int main(void) {
    // 
}
#endif

3. Add -DRUN_TESTS in cmake flag

The build configurations(debug/release) in MCUXpresso IDE - Vscode is from CMakePresets.json-->flags.cmake

If you need to add a new build configuration, create a new Presets in  CMakePresets.json, using CMAKE_BUILD_TYPE="utest" to replace CMAKE_BUILD_TYPE="debug".

Then add your build preset in flags.cmake.

SET(CMAKE_C_FLAGS_UTEST " \
    ${CMAKE_C_FLAGS_DEBUG} \
    -DDEBUG \
    -DRUN_TESTS \
    -DCPU_MIMX8ML8DVNLZ \
    -DCPU_MIMX8ML8DVNLZ_cm7 \
    -DPRINTF_FLOAT_ENABLE=0 \
    -DSCANF_FLOAT_ENABLE=0 \
    -DPRINTF_ADVANCED_ENABLE=0 \
    -DSCANF_ADVANCED_ENABLE=0 \
    -DMCUXPRESSO_SDK \
    -DSERIAL_PORT_TYPE_UART=1 \
    -g \
    -O0 \
    -mcpu=cortex-m7 \
    -Wall \
    -Wno-address-of-packed-member \
    -mthumb \
    -MMD \
    -MP \
    -fno-common \
    -ffunction-sections \
    -fdata-sections \
    -fno-builtin \
    -mapcs \
    -std=gnu99 \
    ${FPU} \
    ${DEBUG_CONSOLE_CONFIG} \
")

4. Switch Build Configurations in MCUXpresso IDE - Vscode.

Best Regards,
Zhiming

0 项奖励
回复