forked from Archive/PX4-Autopilot
uORB: Unit test fix
The latency_test used to pass an object pointer as argv which won't work in the posix port because it expects argv to be a null terminated array of character pointers (which it makes a copy of). The test was refactored to use a singleton pattern and avoid having to pass the object pointer to the thread. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
parent
872e1ebda0
commit
7ebee7ca6f
|
@ -90,7 +90,7 @@ uorb_main(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "test"))
|
if (!strcmp(argv[1], "test"))
|
||||||
{
|
{
|
||||||
uORBTest::UnitTest t;
|
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
||||||
return t.test();
|
return t.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ uorb_main(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
if (!strcmp(argv[1], "latency_test")) {
|
if (!strcmp(argv[1], "latency_test")) {
|
||||||
|
|
||||||
uORBTest::UnitTest t;
|
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
||||||
if (argc > 2 && !strcmp(argv[2], "medium")) {
|
if (argc > 2 && !strcmp(argv[2], "medium")) {
|
||||||
return t.latency_test<struct orb_test_medium>(ORB_ID(orb_test_medium), true);
|
return t.latency_test<struct orb_test_medium>(ORB_ID(orb_test_medium), true);
|
||||||
} else if (argc > 2 && !strcmp(argv[2], "large")) {
|
} else if (argc > 2 && !strcmp(argv[2], "large")) {
|
||||||
|
@ -118,7 +118,5 @@ uorb_main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
usage();
|
usage();
|
||||||
errx(-EINVAL, "unrecognized command, try 'start', 'test', 'latency_test' or 'status'");
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,12 @@
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
#include <px4_time.h>
|
#include <px4_time.h>
|
||||||
|
|
||||||
|
uORBTest::UnitTest &uORBTest::UnitTest::instance()
|
||||||
|
{
|
||||||
|
static uORBTest::UnitTest t;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
int uORBTest::UnitTest::pubsublatency_main(void)
|
int uORBTest::UnitTest::pubsublatency_main(void)
|
||||||
{
|
{
|
||||||
/* poll on test topic and output latency */
|
/* poll on test topic and output latency */
|
||||||
|
@ -276,12 +282,8 @@ int uORBTest::UnitTest::test_note(const char *fmt, ...)
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uORBTest::UnitTest::pubsubtest_threadEntry( char* const* data )
|
int uORBTest::UnitTest::pubsubtest_threadEntry(char* const argv[])
|
||||||
{
|
{
|
||||||
uORBTest::UnitTest* t = (uORBTest::UnitTest*) data;
|
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
||||||
if( data != nullptr )
|
return t.pubsublatency_main();
|
||||||
{
|
|
||||||
return t->pubsublatency_main();
|
|
||||||
}
|
|
||||||
return uORB::ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,15 +68,22 @@ class uORBTest::UnitTest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
// Singleton pattern
|
||||||
|
static uORBTest::UnitTest &instance();
|
||||||
|
~UnitTest() {}
|
||||||
int test();
|
int test();
|
||||||
template<typename S> int latency_test(orb_id_t T, bool print);
|
template<typename S> int latency_test(orb_id_t T, bool print);
|
||||||
int info();
|
int info();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int pubsubtest_threadEntry( char* const* argv );
|
UnitTest() : pubsubtest_passed(false), pubsubtest_print(false) {}
|
||||||
|
|
||||||
|
// Disallow copy
|
||||||
|
UnitTest(const uORBTest::UnitTest &) {};
|
||||||
|
static int pubsubtest_threadEntry(char* const argv[]);
|
||||||
int pubsublatency_main(void);
|
int pubsublatency_main(void);
|
||||||
bool pubsubtest_passed = false;
|
bool pubsubtest_passed;
|
||||||
bool pubsubtest_print = false;
|
bool pubsubtest_print;
|
||||||
int pubsubtest_res = OK;
|
int pubsubtest_res = OK;
|
||||||
|
|
||||||
int test_fail(const char *fmt, ...);
|
int test_fail(const char *fmt, ...);
|
||||||
|
@ -93,14 +100,16 @@ int uORBTest::UnitTest::latency_test(orb_id_t T, bool print)
|
||||||
|
|
||||||
int pfd0 = orb_advertise(T, &t);
|
int pfd0 = orb_advertise(T, &t);
|
||||||
|
|
||||||
char * const args[2] = { (char* const) this, 0 };
|
char * const args[1] = { NULL };
|
||||||
|
|
||||||
pubsubtest_print = print;
|
pubsubtest_print = print;
|
||||||
|
|
||||||
pubsubtest_passed = false;
|
pubsubtest_passed = false;
|
||||||
|
|
||||||
/* test pub / sub latency */
|
/* test pub / sub latency */
|
||||||
|
|
||||||
|
// Can't pass a pointer in args, must be a null terminated
|
||||||
|
// array of strings because the strings are copied to
|
||||||
|
// prevent access if the caller data goes out of scope
|
||||||
int pubsub_task = px4_task_spawn_cmd("uorb_latency",
|
int pubsub_task = px4_task_spawn_cmd("uorb_latency",
|
||||||
SCHED_DEFAULT,
|
SCHED_DEFAULT,
|
||||||
SCHED_PRIORITY_MAX - 5,
|
SCHED_PRIORITY_MAX - 5,
|
||||||
|
|
Loading…
Reference in New Issue