Skip to main content

Unit testing using ceedling on STM32F0 QEMU

Unit testing on limited memory  Microcontoller often require expensive ICE with RAM buffers.IDEs often did not provide inbuild unit testing and static analysis tools in case of micro controllers developmet IDEs .Alternative is to use QMU simulator for slected Micro contoller archetecture and use ceedling project on Eclipe to create and test code,run test and genrate test port
              https://qrgo.page.link/EHGBx
Below example shows a sample project file used for running a ceedling unit test
       
---

# Notes:

# Sample project C code is not presently written to produce a release artifact.

# As such, release build options are disabled.

# This sample, therefore, only demonstrates running a collection of unit tests.



:project:

:use_exceptions: FALSE

:use_mocks: TRUE

:use_test_preprocessor: TRUE

:use_auxiliary_dependencies: TRUE

:build_root: build

#  :release_build: TRUE

:test_file_prefix: test_

:which_ceedling: gem

:default_tasks:

- test:all



#:test_build:

#  :use_assembly: TRUE



#:release_build:

#  :output: MyApp.out

#  :use_assembly: FALSE



:environment:

- :path:                                 #concatenated with path separator (see special case above)

- /home/anas/Downloads/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux/gcc-arm-none-eabi-9-2019-q4-major/bin/       #prepend existing PATH with gizmo path

- "#{ENV['PATH']}"                    #pattern #{…} triggers ruby evaluation string substitution

#note: value string must be quoted because of '#'

- :path:                                 #concatenated with path separator (see special case above)

- /home/anas/opt/xPacks/@xpack-dev-tools/qemu-arm/2.8.0-8.1/.content/bin/                     #prepend existing PATH with gizmo path

- "#{ENV['PATH']}"                    #pattern #{…} triggers ruby evaluation string substitution

#note: value string must be quoted because of '#'





:extension:

:executable: .out



:paths:

:test:

- +:test/**

- -:test/support

:source:

- 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)

:common: &common_defines

- DEBUG 

- USE_FULL_ASSERT 

- OS_USE_SEMIHOSTING 

- TRACE 

- OS_USE_TRACE_SEMIHOSTING_DEBUG 

- STM32F072 

- USE_STDPERIPH_DRIVER 

- HSE_VALUE=8000000  

#  - UNITY_EXCLUDE_SETJMP_H

:test:

- *common_defines

- TEST

:test_preprocess:

- *common_defines

- TEST

:gcov:

- *common_defines

- TEST

:gcov_preprocess:

- *common_defines

- TEST



:flags:

:test:

:compile:

:bootloader:

- --coverage 

:link:

:'test_.+':  # add '--bar --baz' to linking of test_main.exe

- --coverage

:gcov:

:compile:

:bootloader:

- --coverage    

:link:

:'test_.+':  # add '--bar --baz' to linking of test_main.exe

- --coverage

:cmock:

:mock_prefix: mock_

:when_no_prototypes: :warn

:enforce_strict_ordering: TRUE

:plugins:

- :ignore

- :ignore_arg

- :callback

:treat_as:

uint8:    HEX8

uint16:   HEX16

uint32:   UINT32

int8:     INT8

bool:     UINT8



# Add -gcov to the plugins list to make sure of the gcov plugin

# You will need to have gcov and gcovr both installed to make it work.

# For more information on these options, see docs in plugins/gcov

:gcov:

:html_report: TRUE

:html_report_type: detailed

:html_medium_threshold: 75

:html_high_threshold: 90

:xml_report: FALSE



#:tools:

# Ceedling defaults to using gcc for compiling, linking, etc.

# As [:tools] is blank, gcc will be used (so long as it's in your system path)

# See documentation to configure a given toolchain for use

:tools:

:test_compiler:

:executable: arm-none-eabi-gcc              #exists in system search path

:name: 'test compiler'

:arguments:

- -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

- -mcpu=cortex-m0 

- -mthumb 

- -Og 

- -fmessage-length=0 

- -fsigned-char 

- -ffunction-sections 

- -fdata-sections 

- -fno-move-loop-invariants 

- -Wall 

- -Wextra  

- -g3  

- -std=gnu11 

- -MMD -MP -MF ${4} 

- -MT ${2} 

#- --network-license             #simple command line argument

# - -optimize-level 4             #simple command line argument

#- "#{`args.exe -m acme.prj`}"   #in-line ruby sub to shell out & build string of arguments

- -c ${1}                       #source code input file (Ruby method call param list sub)

- -o ${2}                       #object file output (Ruby method call param list sub)

:test_linker:

:executable: arm-none-eabi-g++    #absolute file path

:name: 'test linker'

:arguments:

- ${1}               #list of object files to link (Ruby method call param list sub)

#- -l$-lib:           #inline yaml array substitution to link in foo-lib and bar-lib

# - foo

# - bar

- -mcpu=cortex-m0

- -mthumb

- -Og

- -fmessage-length=0

- -fsigned-char

- -ffunction-sections

- -fdata-sections

- -fno-move-loop-invariants

- -Wall

- -Wextra

- -g3

- -T mem.ld

- -T libs.ld 

- -T sections.ld 

- -nostartfiles 

- -Xlinker --gc-sections

- -L"src/ldscripts"

- --specs=nano.specs    

- -o ${2}            #executable file output (Ruby method call param list sub)

:test_fixture:

:executable: qemu-system-gnuarmeclipse  #relative file path to command line simulator

:name: 'test fixture'

:stderr_redirect: :win                     #inform Ceedling what model of $stderr capture to use

:arguments:

- -m size=128

- --board STM32F0-Discovery

- --mcu STM32F072RB

#   - --gdb tcp::1234

- -d unimp,guest_errors

- --nographic 

- --image "${1}" 

- --semihosting-config enable=on,target=native

# - -mem large   #simple command line argument

#- -f "${1}"    #binary executable input file to simulator (Ruby method call param list sub)



:gcov_compiler:

:executable: arm-none-eabi-gcc              #exists in system search path

:name: 'test compiler'

:arguments:

- -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

- -mcpu=cortex-m0 

- -mthumb 

- -Og 

- -fmessage-length=0 

- -fsigned-char 

- -ffunction-sections 

- -fdata-sections 

- -fno-move-loop-invariants 

- -Wall 

- -Wextra  

- -g3  

- -std=gnu11 

#- --network-license             #simple command line argument

# - -optimize-level 4             #simple command line argument

#- "#{`args.exe -m acme.prj`}"   #in-line ruby sub to shell out & build string of arguments

- -c ${1}                       #source code input file (Ruby method call param list sub)

- -o ${2}                       #object file output (Ruby method call param list sub)

:gcov_linker:

:executable: arm-none-eabi-g++    #absolute file path

:name: 'test linker'

:arguments:

- ${1}               #list of object files to link (Ruby method call param list sub)

#- -l$-lib:           #inline yaml array substitution to link in foo-lib and bar-lib

# - foo

# - bar

- -mcpu=cortex-m0

- -mthumb

- -Og

- -fmessage-length=0

- -fsigned-char

- -ffunction-sections

- -fdata-sections

- -fno-move-loop-invariants

- -Wall

- -Wextra

- -g3

- -T mem.ld

- -T libs.ld 

- -T sections.ld 

- -nostartfiles 

- -Xlinker --gc-sections

- -L"src/Test/ldscripts"

- --specs=nano.specs    

- -o ${2}            #executable file output (Ruby method call param list sub)

:gcov_fixture:

:executable: qemu-system-gnuarmeclipse  #relative file path to command line simulator

:name: 'test fixture'

:stderr_redirect: :win                     #inform Ceedling what model of $stderr capture to use

:arguments:

- -m size=128

- --board STM32F0-Discovery

- --mcu STM32F072RB

#   - --gdb tcp::1234

- -d unimp,guest_errors

- --nographic 

- --image "${1}" 



- --semihosting-config enable=on,target=native

# - -mem large   #simple command line argument

# LIBRARIES

# These libraries are automatically injected into the build process. Those specified as

# common will be used in all types of builds. Otherwise, libraries can be injected in just

# tests or releases. These options are MERGED with the options in supplemental yaml files.

:libraries:

:placement: :end

:flag: "${1}"  # or "-L ${1}" for example

:common: &common_libraries []



:plugins:

:enabled:

- xml_tests_report # <--- -="" ...="" added="" been="" code="" gcov="" has="" line="" module_generator="" stdout_gtestlike_tests_report="" this="">
 

Comments