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:
Mark Charlebois
2015-05-06 13:19:52 -07:00
parent 872e1ebda0
commit 7ebee7ca6f
3 changed files with 26 additions and 17 deletions
+14 -5
View File
@@ -68,15 +68,22 @@ class uORBTest::UnitTest
{
public:
// Singleton pattern
static uORBTest::UnitTest &instance();
~UnitTest() {}
int test();
template<typename S> int latency_test(orb_id_t T, bool print);
int info();
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);
bool pubsubtest_passed = false;
bool pubsubtest_print = false;
bool pubsubtest_passed;
bool pubsubtest_print;
int pubsubtest_res = OK;
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);
char * const args[2] = { (char* const) this, 0 };
char * const args[1] = { NULL };
pubsubtest_print = print;
pubsubtest_passed = false;
/* 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",
SCHED_DEFAULT,
SCHED_PRIORITY_MAX - 5,