ThrowTheSwitch / Ceedling

Ruby-based unit testing and build system for C projects
http://throwtheswitch.org
Other
568 stars 241 forks source link

How to replace platform specific math libraries? #576

Open tomh4 opened 3 years ago

tomh4 commented 3 years ago

We have successfully set up Ceedling to run tests for our STM32L4 project but we are struggling with the arm_math library.

How would one go about testing a method that makes use of any of the methods in such a platform specific library? I tried adding the library to the project and also added the define for library ( arm_cortexM4lf_math ) but of course this does not work as we are not running the tests on a cortex m4...

Any suggestions we could try out ?

Letme commented 3 years ago

You will need to replace arm_math library with standard math library. :includes: option provides :release: and :test: submembers for this. Alternatively you can also do it via the :tools: for the :test_compiler: and :test_linker:. If there are functions that you want to mock instead (different from standard math), then I suggest you just add the header files somewhere to mock these functions.

tomh4 commented 3 years ago

Hello, yes the problem is we have some very specific methods we are using (e.g. arm_biquad_cascade_df2T_f32) that are not so easily replaced by the standard math libs.

Mocking does not work as the outcome of the test does depend on the these functions, or am I missing something here?

Letme commented 3 years ago

You are not executing on target, so you do not depend on these functions. You depend on the results of these functions = > mocking. Your intention is not to verify that those functions do what they do, your intention is to separate the functionality of your functions and that means not going deep into such non-standard special math functions.

They are probably full of assembly, so they might not even compile correctly anyway.

tomh4 commented 3 years ago

You are probably right, we thought we could test the correct usage of the functions ( not their functioning ).

But we will then just skip all the methods that rely on these functions to produce a correct outcome!