Configure Ceedling for unit testing

I'm starting to look at using Ceedling (+Unity + CMock) for some test driven development but am having trouble getting tests that use/mock the SDK. I'm currently trying to set up unit tests for a custom ble service (an SDK equivalent would be any of the files in the components\ble\ble_services folder) that will run on my PC, not on the target. I am using Cygwin and gcc

Does anyone have any experience/guidance/project files for how to set this up?

My current yml file looks like this

---

# 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_exceptionsFALSE
  :use_test_preprocessorTRUE
  :use_auxiliary_dependenciesTRUE
  :build_rootbuild
#  :release_build: TRUE
  :test_file_prefixtest_
  :which_ceedlinggem
  :default_tasks:
    - test:all
  :options_paths:
    - options/

#:test_build:
#  :use_assembly: TRUE

#:release_build:
#  :output: MyApp.out
#  :use_assembly: FALSE

:environment:

:extension:
  :executable.out

:paths:
  :test:
    - +:test/**
    - -:test/support
  :source:
    - lib/**
  :include:
    - include/**
  :support:
    - test/support

:module_generator:
  :source_rootlib/
  :inc_rootinclude/mylib/

:use_test_preprocessortrue

: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 []
  :test:
    - *common_defines
    - TEST
    - __STATIC_INLINE='static inline'
  :test_preprocess:
    - *common_defines
    - TEST

:cmock:
  :mock_prefixmock_
  :when_no_prototypes:warn
  :enforce_strict_orderingTRUE
  :plugins:
    - :ignore
    - :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_reportTRUE
    :html_report_typedetailed
    :html_medium_threshold75
    :html_high_threshold90
    :xml_reportFALSE

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

# 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
  :test: []
  :release: []

:plugins:
  :load_paths:
    - "#{Ceedling.load_path}"
  :enabled:
    - stdout_pretty_tests_report
    - module_generator
...

I am using python to extract include paths and defines from my Keil project file and generate another yml file that I include when running ceedling e.g.

ceedling options:NRF52_S332_SDK153 test:all

this is so i can run tests for each of the targets for my project.

I'm currently stuck with errors like

../libnordic/v15.3/components/softdevice/s332/headers/ble.h: In function 'sd_ble_user_mem_reply':
../libnordic/v15.3/components/softdevice/s332/headers/nrf_svc.h:68:5: error: unknown register name 'r0' in 'asm'
     __asm(                                              \
     ^
.

I have included mock_ble.h in my test file.

#include "unity.h"

#include "ble_my_service.h"
#include "mock_ble.h"
#include "mock_ble_gap.h"


void setUp(void)
{
}

void tearDown(void)
{
}

void test_ble_my_service_NeedToImplement(void)
{
    TEST_IGNORE_MESSAGE("Need to Implement ble_my_service");
}


How can I get this going? Should this work? Am I trying to mock things at too low of a level? Am I using the right compiler tools?

  • Hello,

    to my understanding there is no support for Ceedling. You can read more about it in this post.

  • Sorry for resurrecting an old thread.

    I have Ceedling working well for my project which uses the Nordic SDK + GCC.

    Please be sure to include all relevant defines in your project.yml. Mine looks like this:

    :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
        - NRF52
        - NRF52832
        - UNIT_TEST
        - FREERTOS
      :test:
        - *common_defines
        - TEST
      :test_preprocess:
        - *common_defines
        - TEST

Related