From adaaeff48a4d7b3b36e407f832a837627171d67d Mon Sep 17 00:00:00 2001 From: Ban Siesta Date: Sat, 13 Jun 2015 10:25:25 +0100 Subject: [PATCH] uORBTest_UnitTest: Split test function in 3 separate functions and add a test which fails because it does the subscription before the advertisement. --- src/modules/uORB/uORBTest_UnitTest.cpp | 99 +++++++++++++++++++++++++- src/modules/uORB/uORBTest_UnitTest.hpp | 5 ++ 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/src/modules/uORB/uORBTest_UnitTest.cpp b/src/modules/uORB/uORBTest_UnitTest.cpp index f8e60a2154..7a0c15b476 100644 --- a/src/modules/uORB/uORBTest_UnitTest.cpp +++ b/src/modules/uORB/uORBTest_UnitTest.cpp @@ -140,6 +140,31 @@ int uORBTest::UnitTest::pubsublatency_main(void) int uORBTest::UnitTest::test() { + int ret = test_single(); + if (ret != OK) { + return ret; + } + ret = test_multi(); + if (ret != OK) { + return ret; + } + ret = test_multi_reversed(); + if (ret != OK) { + return ret; + } + return OK; +} + + +int uORBTest::UnitTest::info() +{ + return OK; +} + +int uORBTest::UnitTest::test_single() +{ + test_note("try single-topic support"); + struct orb_test t, u; int sfd; orb_advert_t ptopic; @@ -203,9 +228,16 @@ int uORBTest::UnitTest::test() orb_unsubscribe(sfd); + return test_note("PASS single-topic test"); +} + +int uORBTest::UnitTest::test_multi() +{ /* this routine tests the multi-topic support */ test_note("try multi-topic support"); + struct orb_test t, u; + t.val = 0; int instance0; orb_advert_t pfd0 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance0, ORB_PRIO_MAX); @@ -280,12 +312,73 @@ int uORBTest::UnitTest::test() return test_fail("latency test failed"); } - return test_note("PASS"); + return test_note("PASS multi-topic test"); } -int uORBTest::UnitTest::info() +int uORBTest::UnitTest::test_multi_reversed() { - return OK; + test_note("try multi-topic support subscribing before publishing"); + + /* For these tests 0 and 1 instances are taken from before, therefore continue with 2 and 3. */ + + /* Subscribe first and advertise afterwards. */ + int sfd2 = orb_subscribe_multi(ORB_ID(orb_multitest), 2); + if (sfd2 < 0) { + return test_fail("sub. id2: ret: %d", sfd2); + } + + struct orb_test t, u; + t.val = 0; + int instance2; + orb_advert_t pfd2 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance2, ORB_PRIO_MAX); + + int instance3; + orb_advert_t pfd3 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance3, ORB_PRIO_MIN); + + test_note("advertised"); + + if (instance2 != 2) { + return test_fail("mult. id2: %d", instance2); + } + + if (instance3 != 3) { + return test_fail("mult. id3: %d", instance3); + } + + t.val = 204; + + if (PX4_OK != orb_publish(ORB_ID(orb_multitest), pfd2, &t)) { + return test_fail("mult. pub0 fail"); + } + + + t.val = 304; + + if (PX4_OK != orb_publish(ORB_ID(orb_multitest), pfd3, &t)) { + return test_fail("mult. pub1 fail"); + } + + test_note("published"); + + if (PX4_OK != orb_copy(ORB_ID(orb_multitest), sfd2, &u)) { + return test_fail("sub #2 copy failed: %d", errno); + } + + if (u.val != 204) { + return test_fail("sub #3 val. mismatch: %d", u.val); + } + + int sfd3 = orb_subscribe_multi(ORB_ID(orb_multitest), 3); + + if (PX4_OK != orb_copy(ORB_ID(orb_multitest), sfd3, &u)) { + return test_fail("sub #3 copy failed: %d", errno); + } + + if (u.val != 304) { + return test_fail("sub #3 val. mismatch: %d", u.val); + } + + return test_note("PASS multi-topic reversed"); } int uORBTest::UnitTest::test_fail(const char *fmt, ...) diff --git a/src/modules/uORB/uORBTest_UnitTest.hpp b/src/modules/uORB/uORBTest_UnitTest.hpp index 4957427c06..5f8d087ac1 100644 --- a/src/modules/uORB/uORBTest_UnitTest.hpp +++ b/src/modules/uORB/uORBTest_UnitTest.hpp @@ -82,10 +82,15 @@ private: UnitTest(const uORBTest::UnitTest &) {}; static int pubsubtest_threadEntry(char *const argv[]); int pubsublatency_main(void); + // bool pubsubtest_passed; bool pubsubtest_print; int pubsubtest_res = OK; + int test_single(); + int test_multi(); + int test_multi_reversed(); + int test_fail(const char *fmt, ...); int test_note(const char *fmt, ...); };