我需要在我的C项目中进行一些单元测试,该项目将在STM32F0处理器中使用。我可以在 x64 gcc 上测试我的抽象代码,但问题是我需要一个小尾数的平台(STM32F0 默认情况下是小尾数)。我尝试在project.yml文件中做一些修改。
:project:
:use_exceptions: FALSE
:use_test_preprocessor: TRUE
:use_auxiliary_dependencies: TRUE
:build_root: build
# :release_build: TRUE
:test_file_prefix: test_
#:release_build:
# :output: MyApp.out
# :use_assembly: FALSE
:environment:
:extension:
:executable: .out
:paths:
:test:
- +:test/**
- -:test/support
:source:
- ../CDynTransport/src/
:support:
- test/support
:defines:
# in order to add common defines:
# 1) remove the trailing [] from the :common: section
# 2) add entries to the :common: section (e.g. :test: has TEST defined)
:commmon: &common_defines []
:test:
- *common_defines
- TEST
:test_preprocess:
- *common_defines
- TEST
:cmock:
:mock_prefix: mock_
:when_no_prototypes: :warn
:enforce_strict_ordering: TRUE
:plugins:
- :ignore
- :callback
:treat_as:
uint8: HEX8
uint16: HEX16
uint32: UINT32
int8: INT8
bool: UINT8
:tools:
:test_compiler:
:executable: arm-none-eabi-gcc
:arguments:
- "${1}"
- '-c'
- '-g'
- '-mcpu=cortex-m0'
- '-mthumb'
- '-Wall'
- '-Wno-address'
#- '-std=c99'
#- '-pedantic'
- -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE #expands to -I search paths
- -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR #expands to -I search paths
- -D$: COLLECTION_DEFINES_TEST_AND_VENDOR #expands to all -D defined symbols
- -I"$": COLLECTION_PATHS_SOURCE_INCLUDE_VENDOR
- '-DTEST'
- '-DUNITY_EXCLUDE_STDINT_H'
- '-DUNITY_EXCLUDE_LIMITS_H'
- '-DUNITY_EXCLUDE_SIZEOF'
- '-DUNITY_INCLUDE_DOUBLE'
- '-DUNITY_SUPPORT_TEST_CASES'
- '-DUNITY_INT_WIDTH=32'
- '-DUNITY_LONG_WIDTH=32'
- '-DUNITY_INCLUDE_CONFIG_H'
:test_linker:
:executable: arm-none-eabi-gcc
:arguments:
- '-lm'
- '-mcpu=cortex-m0'
- '-mthumb'
- '-specs=nosys.specs'
#- '-T targets/gcc_armcortexM3/qemu.ld'
:test_simulator:
:executable: qemu-system-arm
:arguments:
- -cpu cortex-m3
- -M lm3s6965evb
- -no-reboot
- -nographic
- -kernel
:plugins:
:load_paths:
- vendor/ceedling/plugins
:enabled:
- stdout_pretty_tests_report
- module_generator
但是我仍然遇到编译问题。例如:
Test 'test_command.c'
---------------------
Generating runner for test_command.c...
Compiling test_command_runner.c...
In file included from /home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/vendor/unity/src/unity.h:16:0,
from build/test/runners/test_command_runner.c:22:
/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/vendor/unity/src/unity_internals.h:11:26: fatal error: unity_config.h: No such file or directory
#include "unity_config.h"
^
compilation terminated.
ERROR: Shell command failed.
> Shell executed command:
'arm-none-eabi-gcc build/test/runners/test_command_runner.c -c -g -mcpu=cortex-m0 -mthumb -Wall -Wno-address -I"test" -I"test/support" -I"../CDynTransport/src" -I"/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/vendor/unity/src" -I"/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/vendor/cmock/src" -I"build/test/mocks" -DTEST -I"../CDynTransport/src" -DTEST -DUNITY_EXCLUDE_STDINT_H -DUNITY_EXCLUDE_LIMITS_H -DUNITY_EXCLUDE_SIZEOF -DUNITY_INCLUDE_DOUBLE -DUNITY_SUPPORT_TEST_CASES -DUNITY_INT_WIDTH=32 -DUNITY_LONG_WIDTH=32 -DUNITY_INCLUDE_CONFIG_H'
> And exited with status: [1].
rake aborted!
ShellExecutionException: ShellExecutionException
/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/lib/ceedling/tool_executor.rb:78:in `exec'
/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/lib/ceedling/generator.rb:95:in `generate_object_file'
/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/lib/ceedling/rules_tests.rake:17:in `block in <top (required)>'
/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/lib/ceedling/task_invoker.rb:74:in `invoke_test_results'
/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/lib/ceedling/test_invoker.rb:68:in `block in setup_and_invoke'
/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/lib/ceedling/test_invoker.rb:32:in `setup_and_invoke'
/home/slawek/CentralInterface/CDynTransportTest/vendor/ceedling/lib/ceedling/tasks_tests.rake:11:in `block (2 levels) in <top (required)>'
Tasks: TOP => build/test/results/test_command.pass => build/test/out/test_command.out => build/test/out/test_command_runner.o
(See full trace by running task with --trace)
有人有针对 STM32 微控制器的 Ceedling 的现成配置吗?
这适用于我的 STM32G0 设置
# Ceedling configuration to run unit testing with code coverage using GCC compiler and the
# STM32CubeG0 library, user only has to type make test target from the makefile to run
# all the unit test cases written on files in folder test
:project:
:build_root: Build/ceedling/ # Directory where ceedling will place its output
:use_test_preprocessor: TRUE
:use_auxiliary_dependencies: TRUE
:test_file_prefix: test_
# Project paths for test and source and header files
:paths:
:test:
- test/** # directory where the unit testing are
:source:
- app/** # directory where the functions to test are
- halg0/Src # HAL library source files
- cmsisg0/startups # HAL library system source file
:include:
- halg0/Inc # HAL library include files
- cmsisg0/core # HAL library CPU definitions in header files
- cmsisg0/registers # HAL library register definition files
# Global defines applicable only when you run the code using ceedling
:defines:
:test:
- UTEST # define the macro UTEST to remove the static qualifier
- STM32G0B1xx # HAL library microcontroller in use
- USE_HAL_DRIVER # HAL library to active HAL driver func tions
# Plugins to add extra fcuntionality to ceedling, like code coverage and pretty reports
:plugins:
:load_paths:
- "#{Ceedling.load_path}"
:enabled:
- stdout_pretty_tests_report # Display test cases result in a better way
- gcov # Code coverage
# enable and configure code coverage
:gcov:
:abort_on_uncovered: true # Stop if a file under test has not been tested
:utilities:
- gcovr # gcovr for report generation
:reports:
- HtmlDetailed # genarate a detail report of each file in HTML
:uncovered_ignore_list:
- halg0/** # Ignore files in HAL library
- cmsisg0/** # Ignore files in HAL library
- app/main.c # Ignore main file (renmove from here ig needed)
- app/ints.c # Do not test interrupt vectors
- app/msps.c # Do not test extra initlization functions
# Configure the mock generator
:cmock:
:mock_prefix: mock_ # Generate mock version using mock prefix
:treat_externs: :include
:when_no_prototypes: :warn
:enforce_strict_ordering: TRUE
:includes:
- stm32g0xx.h # Include by default this header on each mock file
:strippables: # Add here all fucntions you do not want to be mocked
- '(?:HAL_GPIO_EXTI_Rising_Callback\s*\(+.*?\)+)' # For instance the callback functions
- '(?:HAL_GPIO_EXTI_Falling_Callback\s*\(+.*?\)+)' # For instance the callback functions
:plugins:
- :ignore # Generate <function>_Ignore and <function>_IgnoreAndReturn
- :ignore_arg # Generate <function>_IgnoreArg_<param_name>
- :expect_any_args # Generate <function>_func_ExpectAnyArgs and <function>_func_ExpectAnyArgsAndReturn
- :array # Generate <function>_ExpectWithArray and <function>_ExpectWithArrayAndReturn
- :callback # Generate <function>_
- :return_thru_ptr # Generate <function>_ReturnArrayThruPtr_<param_name> and <function>_ReturnMemThruPtr_<param_name>
# extra flags to add to default compiler GCC whe run commands ceedling test:all and ceedling gcov:all
# these flags are the same written in the makefile used to build the project plus three extra flags
# for some reason are needed by GCC to avoid cast warnings in HAL library
:flags:
:test: # flags when GCC runs with ceedling test:all
:compile:
:*:
- -O0
- -ffunction-sections
- -fdata-sections
- -fno-builtin
- -std=c11
- -pedantic
- -Wall
- -Werror
- -Wstrict-prototypes
- -fsigned-char
- -fomit-frame-pointer
- -fverbose-asm
# Extra flags to avoid cast warnings in the HAL library
- -Wno-int-to-pointer-cast
- -Wno-pointer-to-int-cast
- -Wno-error=address
:gcov: # flags when GCC runs with ceedling gcov:all
:compile:
:*:
- -O0
- -ffunction-sections
- -fdata-sections
- -fno-builtin
- -std=c11
- -pedantic
- -Wall
- -Werror
- -Wstrict-prototypes
- -fsigned-char
- -fomit-frame-pointer
- -fverbose-asm
# Extra flags to avoid cast warnings in the HAL library
- -Wno-int-to-pointer-cast
- -Wno-pointer-to-int-cast
- -Wno-error=address