0

I am working on an Embedded C project for which I am currently writing unit tests. I am using the fff mocking framework, which essentially creates fake function calls which should overload hardware specific calls.

When I create a 'fake function' I get an error stating that

Address of overloaded function does not match required type 'void()'

This is happening every time I attempt to create a Fake. I am primarily an embedded C programmer, and only using elements of C++ for the purposes of unit testing. I don't really understand what this message is telling me or why it is a problem. If anyone could offer any insight, I would be very grateful.

The code in question is shown below. The error is highlighted on the function names: xTaskCreate, HAL_TIM_Base_Init and HAL_TIM_ConfigClockSource.

#include <TinyEmbeddedTest.h>
#include <stdio.h>
#include "stm32f1xx_hal.h"
#include "FreeRTOS.h"
#include "task.h"
#include "fff.h"

#include "heater.c"  //source file being tested

DEFINE_FFF_GLOBALS;

FAKE_VALUE_FUNC(BaseType_t, xTaskCreate, TaskFunction_t, char *, configSTACK_DEPTH_TYPE, void *, UBaseType_t, TaskHandle_t *);
FAKE_VALUE_FUNC(HAL_StatusTypeDef, HAL_TIM_Base_Init, TIM_HandleTypeDef);
FAKE_VALUE_FUNC(HAL_StatusTypeDef, HAL_TIM_ConfigClockSource, TIM_HandleTypeDef, TIM_ClockConfigTypeDef*);
Yksisarvinen
  • 18,008
  • 2
  • 24
  • 52
Smoggie Tom
  • 306
  • 4
  • 12

1 Answers1

1

Since your error is related to overloading it means you are trying to use multiple definitions for the same function. I would suggest you make sure that the original definitions of the problematic functions are not redefined by these mock declarations (which are also definitions). So for example, if you were mocking a function int func(void) then you can't just add a mock declaration FAKE_VALUE_FUNC(int,func). You would need to either add the weak attribute before the original function implementation or substitute the original function implementation with a function pointer. You can read more about it more extensively in two previous answers I gave on similar issues:

  1. https://stackoverflow.com/a/65814588/4441211
  2. https://stackoverflow.com/a/65814339/4441211
Eyal Gerber
  • 1,026
  • 10
  • 27