From 76733ce54b0180448f0aa0d6c715272279d33208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 27 Sep 2016 13:04:51 +0200 Subject: [PATCH] uorb tests: move orb metadata struct definition into cpp file If they're in the header and the header is used in multiple .cpp, there are multiple definitions. Oddly it did not lead to an error, but there were multiple structs of the same topic but with different adresses. This lead to a metadata mismatch, when running eg: uorb_tests uorb_tests latency_test --- .../uORB/uORB_tests/uORBTest_UnitTest.cpp | 15 ++++++++++++ .../uORB/uORB_tests/uORBTest_UnitTest.hpp | 23 +++++++++---------- .../uORB/uORB_tests/uORB_tests_main.cpp | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp b/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp index 820cf7cdb2..618b6e96cb 100644 --- a/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp +++ b/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp @@ -39,6 +39,21 @@ #include #include +ORB_DEFINE(orb_test, struct orb_test, sizeof(orb_test), "ORB_TEST:int val;hrt_abstime time;"); +ORB_DEFINE(orb_multitest, struct orb_test, sizeof(orb_test), "ORB_MULTITEST:int val;hrt_abstime time;"); + +ORB_DEFINE(orb_test_medium, struct orb_test_medium, sizeof(orb_test_medium), + "ORB_TEST_MEDIUM:int val;hrt_abstime time;char[64] junk;"); +ORB_DEFINE(orb_test_medium_multi, struct orb_test_medium, sizeof(orb_test_medium), + "ORB_TEST_MEDIUM_MULTI:int val;hrt_abstime time;char[64] junk;"); +ORB_DEFINE(orb_test_medium_queue, struct orb_test_medium, sizeof(orb_test_medium), + "ORB_TEST_MEDIUM_MULTI:int val;hrt_abstime time;char[64] junk;"); +ORB_DEFINE(orb_test_medium_queue_poll, struct orb_test_medium, sizeof(orb_test_medium), + "ORB_TEST_MEDIUM_MULTI:int val;hrt_abstime time;char[64] junk;"); + +ORB_DEFINE(orb_test_large, struct orb_test_large, sizeof(orb_test_large), + "ORB_TEST_LARGE:int val;hrt_abstime time;char[512] junk;"); + uORBTest::UnitTest &uORBTest::UnitTest::instance() { static uORBTest::UnitTest t; diff --git a/src/modules/uORB/uORB_tests/uORBTest_UnitTest.hpp b/src/modules/uORB/uORB_tests/uORBTest_UnitTest.hpp index 8016b9c8a2..2e41d0bfdb 100644 --- a/src/modules/uORB/uORB_tests/uORBTest_UnitTest.hpp +++ b/src/modules/uORB/uORB_tests/uORBTest_UnitTest.hpp @@ -41,8 +41,8 @@ struct orb_test { int val; hrt_abstime time; }; -ORB_DEFINE(orb_test, struct orb_test, sizeof(orb_test), "ORB_TEST:int val;hrt_abstime time;"); -ORB_DEFINE(orb_multitest, struct orb_test, sizeof(orb_test), "ORB_MULTITEST:int val;hrt_abstime time;"); +ORB_DECLARE(orb_test); +ORB_DECLARE(orb_multitest); struct orb_test_medium { @@ -50,22 +50,17 @@ struct orb_test_medium { hrt_abstime time; char junk[64]; }; -ORB_DEFINE(orb_test_medium, struct orb_test_medium, sizeof(orb_test_medium), - "ORB_TEST_MEDIUM:int val;hrt_abstime time;char[64] junk;"); -ORB_DEFINE(orb_test_medium_multi, struct orb_test_medium, sizeof(orb_test_medium), - "ORB_TEST_MEDIUM_MULTI:int val;hrt_abstime time;char[64] junk;"); -ORB_DEFINE(orb_test_medium_queue, struct orb_test_medium, sizeof(orb_test_medium), - "ORB_TEST_MEDIUM_MULTI:int val;hrt_abstime time;char[64] junk;"); -ORB_DEFINE(orb_test_medium_queue_poll, struct orb_test_medium, sizeof(orb_test_medium), - "ORB_TEST_MEDIUM_MULTI:int val;hrt_abstime time;char[64] junk;"); +ORB_DECLARE(orb_test_medium); +ORB_DECLARE(orb_test_medium_multi); +ORB_DECLARE(orb_test_medium_queue); +ORB_DECLARE(orb_test_medium_queue_poll); struct orb_test_large { int val; hrt_abstime time; char junk[512]; }; -ORB_DEFINE(orb_test_large, struct orb_test_large, sizeof(orb_test_large), - "ORB_TEST_LARGE:int val;hrt_abstime time;char[512] junk;"); +ORB_DECLARE(orb_test_large); namespace uORBTest @@ -133,6 +128,10 @@ int uORBTest::UnitTest::latency_test(orb_id_t T, bool print) orb_advert_t pfd0 = orb_advertise(T, &t); + if (pfd0 == nullptr) { + return test_fail("orb_advertise failed (%i)", errno); + } + char *const args[1] = { NULL }; pubsubtest_print = print; diff --git a/src/modules/uORB/uORB_tests/uORB_tests_main.cpp b/src/modules/uORB/uORB_tests/uORB_tests_main.cpp index 1f0162f15d..45e20504c3 100644 --- a/src/modules/uORB/uORB_tests/uORB_tests_main.cpp +++ b/src/modules/uORB/uORB_tests/uORB_tests_main.cpp @@ -44,7 +44,7 @@ extern "C" { __EXPORT int uorb_tests_main(int argc, char *argv[]); } static void usage() { - PX4_INFO("Usage: uorb_test 'latency_test'"); + PX4_INFO("Usage: uorb_tests [latency_test]"); } int