You are here
Home > embedded > Testing >

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.

Top
%d bloggers like this: