Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test framework improvements #1183

Merged
merged 8 commits into from
Jan 10, 2023
Merged

Conversation

krichardsson
Copy link
Contributor

@krichardsson krichardsson commented Jan 6, 2023

This PR aims at improving testability, both in unit tests and the python tests (using python bindings). A secondary goal is also to make it possible to add the kalman estimator to the python bindings which would make it possible to use it in simulations and test.

The main changes include:

  • ASSERT() in the firmware is propagated to the test frameworks and fails the test if an assert is false
  • DEBUG_PRINT() in the firmware is now printed in the test console output
  • CMSIS matrix math functions are supported from tests, that is the matrix operations in cf_math.h works when called from a test
  • Fixes a bug related to the @IGNORE_IF_NOT annotation that prevented some tests from running

@krichardsson
Copy link
Contributor Author

Hmm, there seems to be some sort of problem when building the examples/app_hello_world/src/hello_world.c OOT app. I think the problem is that the object files in the firmware are not properly linked and the linker can not find any functions in the firmware. Not sure why (make is not my best friend...). @ntamas I think you were involved in the c++ support, do you have any idea what is going on?

It seems as this is not a new problem caused by this PR, but it is rather just showing the problem.
Another way of triggering it is to go back to master and make a call from appMain() in examples/app_hello_world/src/hello_world.c to any random function in the firmware, for instance

#include "buzzer.h"
void appMain()
{
  buzzerInit();
}

The result is /home/kristoffer/code/bitcraze/crazyflie-firmware/examples/app_hello_world-cpp/src/hello_world.cpp:58: undefined reference to buzzerInit()'`

@ntamas
Copy link
Contributor

ntamas commented Jan 7, 2023

I think this is caused by differences in C and C++ linkage. If you want a header file to behave nicely, irrespectively of whether you include it from a C or a C++ source file, you need to put this around all declarations in the header to force C linkage for the functions:

#ifdef __cplusplus
extern "C" {
#endif

[...declarations come here...]

#ifdef __cplusplus
}
#endif

This either has to be done for all your headers that you ever want to include from C++ files, or you need to wrap the #include directives in the .cpp files like this:

extern "C" {

[...include all the headers from the Crazyflie firmware here...]

}

For instance, this patch solves the compilation of app_hello_world-cpp in this PR:

diff --git a/examples/app_hello_world-cpp/src/hello_world.cpp b/examples/app_hello_world-cpp/src/hello_world.cpp
index 53de5c7c..d3607164 100644
--- a/examples/app_hello_world-cpp/src/hello_world.cpp
+++ b/examples/app_hello_world-cpp/src/hello_world.cpp
@@ -37,12 +37,12 @@
 extern "C"
 {
   #include "app.h"
-}

-#include "FreeRTOS.h"
-#include "task.h"
+  #include "FreeRTOS.h"
+  #include "task.h"

-#include "debug.h"
+  #include "debug.h"
+}

 #define DEBUG_MODULE "HELLOWORLD"

@krichardsson
Copy link
Contributor Author

Thanks @ntamas !

@krichardsson krichardsson marked this pull request as ready for review January 10, 2023 10:06
@krichardsson krichardsson merged commit b8859c2 into master Jan 10, 2023
@krichardsson krichardsson deleted the krichardsson/test-improvements branch January 10, 2023 10:18
@krichardsson krichardsson added this to the 2023.02 milestone Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants