Added a self test feature to the VOXL 2 muorb module (#20307)

* Removed exit after dsp signature generation.
* First full test suite
* Cleaned up the muorb tests
* Improved VOXL 2 self test trigger in startup file
* Removed unneeded include file
This commit is contained in:
Eric Katzfey
2022-09-26 16:25:24 -04:00
committed by GitHub
parent 7bc79b491f
commit a5bfc3fbc2
11 changed files with 309 additions and 22 deletions
+2 -1
View File
@@ -33,5 +33,6 @@
px4_add_library(modules__muorb__slpi
uORBProtobufChannel.cpp
../test/MUORBTest.cpp
)
#target_include_directories(modules__muorb__slpi PRIVATE ${PX4_SOURCE_DIR}/src/modules/uORB)
target_include_directories(modules__muorb__slpi PRIVATE ../test)
+96 -2
View File
@@ -31,34 +31,128 @@
*
****************************************************************************/
#include "uORBProtobufChannel.hpp"
#include "MUORBTest.hpp"
#include <string>
// TODO: Move this out of here once we have it placed properly
#include <qurt.h>
#include <qurt_thread.h>
// TODO: Move this out of here once we have px4-log functionality
extern "C" void HAP_debug(const char *msg, int level, const char *filename, int line);
// Definition of test to run when in muorb test mode
static MUORBTestType test_to_run;
fc_func_ptrs muorb_func_ptrs;
static void test_runner(void *test)
{
HAP_debug("test_runner called", 1, muorb_test_topic_name, 0);
switch (*((MUORBTestType *) test)) {
case ADVERTISE_TEST_TYPE:
(void) muorb_func_ptrs.advertise_func_ptr(muorb_test_topic_name);
break;
case SUBSCRIBE_TEST_TYPE:
(void) muorb_func_ptrs.subscribe_func_ptr(muorb_test_topic_name);
break;
case UNSUBSCRIBE_TEST_TYPE:
(void) muorb_func_ptrs.unsubscribe_func_ptr(muorb_test_topic_name);
break;
case TOPIC_TEST_TYPE: {
uint8_t data[MUORB_TEST_DATA_LEN];
for (uint8_t i = 0; i < MUORB_TEST_DATA_LEN; i++) { data[i] = i; }
(void) muorb_func_ptrs.topic_data_func_ptr(muorb_test_topic_name, data, MUORB_TEST_DATA_LEN);
}
default:
break;
}
qurt_thread_exit(0);
}
int px4muorb_orb_initialize(fc_func_ptrs *func_ptrs, int32_t clock_offset_us)
{
HAP_debug("Hello, world!", 1, "test", 0);
// These function pointers will only be non-null on the first call
// so they must be saved off here
if (func_ptrs != nullptr) { muorb_func_ptrs = *func_ptrs; }
HAP_debug("px4muorb_orb_initialize called", 1, "init", 0);
return 0;
}
#define TEST_STACK_SIZE 8192
char stack[TEST_STACK_SIZE];
void run_test(MUORBTestType test)
{
qurt_thread_t tid;
qurt_thread_attr_t attr;
qurt_thread_attr_init(&attr);
qurt_thread_attr_set_stack_addr(&attr, stack);
qurt_thread_attr_set_stack_size(&attr, TEST_STACK_SIZE);
test_to_run = test;
(void) qurt_thread_create(&tid, &attr, &test_runner, (void *) &test_to_run);
}
int px4muorb_topic_advertised(const char *topic_name)
{
if (IS_MUORB_TEST(topic_name)) { run_test(ADVERTISE_TEST_TYPE); }
HAP_debug("px4muorb_topic_advertised called", 1, topic_name, 0);
return 0;
}
int px4muorb_add_subscriber(const char *topic_name)
{
if (IS_MUORB_TEST(topic_name)) { run_test(SUBSCRIBE_TEST_TYPE); }
HAP_debug("px4muorb_add_subscriber called", 1, topic_name, 0);
return 0;
}
int px4muorb_remove_subscriber(const char *topic_name)
{
if (IS_MUORB_TEST(topic_name)) { run_test(UNSUBSCRIBE_TEST_TYPE); }
HAP_debug("px4muorb_remove_subscriber called", 1, topic_name, 0);
return 0;
}
int px4muorb_send_topic_data(const char *topic_name, const uint8_t *data,
int data_len_in_bytes)
{
if (IS_MUORB_TEST(topic_name)) {
// Validate the test data received
bool test_passed = true;
if (data_len_in_bytes != MUORB_TEST_DATA_LEN) {
test_passed = false;
} else {
for (int i = 0; i < data_len_in_bytes; i++) {
if ((uint8_t) i != data[i]) {
test_passed = false;
break;
}
}
}
if (test_passed) { run_test(TOPIC_TEST_TYPE); }
}
HAP_debug("px4muorb_send_topic_data called", 1, topic_name, 0);
return 0;
}
@@ -36,8 +36,6 @@
#include <stdint.h>
#include <stdio.h>
//#include <unistd.h>
// TODO: This has to be defined in the slpi_proc build and in the PX4 build.
// Make it accessible from one file to both builds.
typedef struct {