Ceedling Unit Testing With ATSAME54

This post is continuation of previous post on how to mock local variable in ceedling, please check out previous post before continuing with this article. Another issue is having to add all the microchip files.

When CMock gets a hold of the header file it looks at all the functions defined there and generates several mock functions for each.

In one program, we are dealing with 4 pins of microcontroller. The pin numbers and its functions are defined in file ‘atmel_start_pins.h’ which is included in our project. But inside this file there are definitions for all the pins and ‘hal.gpio.h’ file is included. Inside ‘hal.gpio.h’ file, another files are included. The original atmel_start_pins.h file is like below, We need only 4 pins from this file:

The function under test is :

Solution:

Instead of wasting memory we can create our own file ‘atmel_start_pins.h’ for unit testing. The file will contain The function declarations we want to mock and only the required data.

In above function INPUT_ENTER_KEY,INPUT_BACK_KEY etc are having values as follwing :

These PB_1,PB_2,PB_3,PB_4 are defined in file ‘atmel_start_pins.h’. So we can create our own ‘atmel_start_pins.h’ file which is having only requied data .The new file is like:

Now we can mock this required function and interfaces. We can just assign any numbers for PB_1,PB_2,PB_3,PB_4 . Pass these pin numbers in test cases.

we able to unit test without memory wastage.

Ceedling Unit Testing

Unit testing is code that calls some other code to check if it performing as expected.Ceedling is a build system specifically designed for running unit tests in c. Unity and CMock are open source tools for testing c.Ceedling has feature of automatic generation of mock.

  • Unity is a unit test framework.
  • CMock creates the fake versions of other modules.Using these fake versions we can verify whether our module is working correctly or not.
  • Ceedling include unit test framework(Unity) and Mocking framework(CMock).
  • It requires Ruby to run and it uses GCC to build each test.
  • Ceedling comes with a command line tool that can be used to generate the project.

Check out details on how to mock local variable in ceedling, and Ceedling Unit Testing With ATSAME54 Micro-controller.