mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-10 05:51:35 +08:00
Showcase clang-format google style
This commit is contained in:
@@ -32,29 +32,30 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "uORBTest_UnitTest.hpp"
|
||||
#include "../uORBCommon.hpp"
|
||||
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/time.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <lib/cdev/CDev.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/SubscriptionMultiArray.hpp>
|
||||
|
||||
uORBTest::UnitTest &uORBTest::UnitTest::instance()
|
||||
{
|
||||
#include "../uORBCommon.hpp"
|
||||
|
||||
uORBTest::UnitTest &uORBTest::UnitTest::instance() {
|
||||
static uORBTest::UnitTest t;
|
||||
return t;
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::pubsublatency_main()
|
||||
{
|
||||
int uORBTest::UnitTest::pubsublatency_main() {
|
||||
/* poll on test topic and output latency */
|
||||
float latency_integral = 0.0f;
|
||||
|
||||
/* wakeup source(s) */
|
||||
px4_pollfd_struct_t fds[1] {};
|
||||
px4_pollfd_struct_t fds[1]{};
|
||||
|
||||
int test_multi_sub = orb_subscribe_multi(ORB_ID(orb_test_medium), 0);
|
||||
|
||||
@@ -72,7 +73,7 @@ int uORBTest::UnitTest::pubsublatency_main()
|
||||
int num_missed = 0;
|
||||
|
||||
// timings has to be on the heap to keep frame size below 2048 bytes
|
||||
unsigned *timings = new unsigned[MAX_RUNS] {};
|
||||
unsigned *timings = new unsigned[MAX_RUNS]{};
|
||||
unsigned timing_min = 9999999;
|
||||
unsigned timing_max = 0;
|
||||
|
||||
@@ -110,8 +111,8 @@ int uORBTest::UnitTest::pubsublatency_main()
|
||||
orb_unsubscribe(test_multi_sub);
|
||||
|
||||
if (pubsubtest_print && timings) {
|
||||
char fname[32] {};
|
||||
sprintf(fname, PX4_STORAGEDIR"/uorb_timings%u.txt", timingsgroup);
|
||||
char fname[32]{};
|
||||
sprintf(fname, PX4_STORAGEDIR "/uorb_timings%u.txt", timingsgroup);
|
||||
FILE *f = fopen(fname, "w");
|
||||
|
||||
if (f == nullptr) {
|
||||
@@ -127,7 +128,6 @@ int uORBTest::UnitTest::pubsublatency_main()
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
float std_dev = 0.f;
|
||||
float mean = latency_integral / MAX_RUNS;
|
||||
|
||||
@@ -156,8 +156,7 @@ int uORBTest::UnitTest::pubsublatency_main()
|
||||
return pubsubtest_res;
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test()
|
||||
{
|
||||
int uORBTest::UnitTest::test() {
|
||||
int ret = test_single();
|
||||
|
||||
if (ret != OK) {
|
||||
@@ -209,11 +208,10 @@ int uORBTest::UnitTest::test()
|
||||
return test_queue_poll_notify();
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_unadvertise()
|
||||
{
|
||||
int uORBTest::UnitTest::test_unadvertise() {
|
||||
test_note("Testing unadvertise");
|
||||
|
||||
//we still have the advertisements from the previous test_multi calls.
|
||||
// we still have the advertisements from the previous test_multi calls.
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
int ret = orb_unadvertise(_pfd[i]);
|
||||
|
||||
@@ -222,8 +220,8 @@ int uORBTest::UnitTest::test_unadvertise()
|
||||
}
|
||||
}
|
||||
|
||||
//try to advertise and see whether we get the right instance
|
||||
int instance_test[4] {};
|
||||
// try to advertise and see whether we get the right instance
|
||||
int instance_test[4]{};
|
||||
orb_test_s t{};
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
@@ -241,14 +239,9 @@ int uORBTest::UnitTest::test_unadvertise()
|
||||
return test_note("PASS unadvertise");
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::info() { return OK; }
|
||||
|
||||
int uORBTest::UnitTest::info()
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_single()
|
||||
{
|
||||
int uORBTest::UnitTest::test_single() {
|
||||
test_note("try single-topic support");
|
||||
|
||||
orb_advert_t ptopic{};
|
||||
@@ -320,8 +313,7 @@ int uORBTest::UnitTest::test_single()
|
||||
return test_note("PASS single-topic test");
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_multi()
|
||||
{
|
||||
int uORBTest::UnitTest::test_multi() {
|
||||
/* this routine tests the multi-topic support */
|
||||
test_note("try multi-topic support");
|
||||
|
||||
@@ -385,23 +377,21 @@ int uORBTest::UnitTest::test_multi()
|
||||
return test_note("PASS multi-topic test");
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::pub_test_multi2_entry(int argc, char *argv[])
|
||||
{
|
||||
int uORBTest::UnitTest::pub_test_multi2_entry(int argc, char *argv[]) {
|
||||
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
||||
return t.pub_test_multi2_main();
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::pub_test_multi2_main()
|
||||
{
|
||||
int uORBTest::UnitTest::pub_test_multi2_main() {
|
||||
int data_next_idx = 0;
|
||||
const int num_instances = 3;
|
||||
orb_advert_t orb_pub[num_instances] {};
|
||||
orb_advert_t orb_pub[num_instances]{};
|
||||
orb_test_medium_s data_topic{};
|
||||
|
||||
for (int i = 0; i < num_instances; ++i) {
|
||||
orb_advert_t &pub = orb_pub[i];
|
||||
int idx = i;
|
||||
// PX4_WARN("advertise %i, t=%" PRIu64, i, hrt_absolute_time());
|
||||
// PX4_WARN("advertise %i, t=%" PRIu64, i, hrt_absolute_time());
|
||||
pub = orb_advertise_multi(ORB_ID(orb_test_medium_multi), &data_topic, &idx);
|
||||
|
||||
if (idx != i) {
|
||||
@@ -417,13 +407,13 @@ int uORBTest::UnitTest::pub_test_multi2_main()
|
||||
int num_messages = 50 * num_instances;
|
||||
|
||||
while (message_counter++ < num_messages) {
|
||||
px4_usleep(2); //make sure the timestamps are different
|
||||
px4_usleep(2); // make sure the timestamps are different
|
||||
|
||||
data_topic.timestamp = hrt_absolute_time();
|
||||
data_topic.val = data_next_idx;
|
||||
|
||||
orb_publish(ORB_ID(orb_test_medium_multi), orb_pub[data_next_idx], &data_topic);
|
||||
// PX4_WARN("publishing msg (idx=%i, t=%" PRIu64 ")", data_next_idx, data_topic.time);
|
||||
// PX4_WARN("publishing msg (idx=%i, t=%" PRIu64 ")", data_next_idx, data_topic.time);
|
||||
|
||||
data_next_idx = (data_next_idx + 1) % num_instances;
|
||||
|
||||
@@ -442,37 +432,31 @@ int uORBTest::UnitTest::pub_test_multi2_main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_multi2()
|
||||
{
|
||||
int uORBTest::UnitTest::test_multi2() {
|
||||
test_note("Testing multi-topic 2 test (queue simulation)");
|
||||
//test: first subscribe, then advertise
|
||||
// test: first subscribe, then advertise
|
||||
|
||||
_thread_should_exit = false;
|
||||
const int num_instances = 3;
|
||||
int orb_data_fd[num_instances] {-1, -1, -1};
|
||||
int orb_data_fd[num_instances]{-1, -1, -1};
|
||||
int orb_data_next = 0;
|
||||
|
||||
for (int i = 0; i < num_instances; ++i) {
|
||||
// PX4_WARN("subscribe %i, t=%" PRIu64, i, hrt_absolute_time());
|
||||
// PX4_WARN("subscribe %i, t=%" PRIu64, i, hrt_absolute_time());
|
||||
orb_data_fd[i] = orb_subscribe_multi(ORB_ID(orb_test_medium_multi), i);
|
||||
}
|
||||
|
||||
char *const args[1] = { nullptr };
|
||||
int pubsub_task = px4_task_spawn_cmd("uorb_test_multi",
|
||||
SCHED_DEFAULT,
|
||||
SCHED_PRIORITY_MAX - 2,
|
||||
2000,
|
||||
(px4_main_t)&uORBTest::UnitTest::pub_test_multi2_entry,
|
||||
args);
|
||||
char *const args[1] = {nullptr};
|
||||
int pubsub_task = px4_task_spawn_cmd("uorb_test_multi", SCHED_DEFAULT, SCHED_PRIORITY_MAX - 2, 2000,
|
||||
(px4_main_t)&uORBTest::UnitTest::pub_test_multi2_entry, args);
|
||||
|
||||
if (pubsub_task < 0) {
|
||||
return test_fail("failed launching task");
|
||||
}
|
||||
|
||||
hrt_abstime last_time[num_instances] {};
|
||||
hrt_abstime last_time[num_instances]{};
|
||||
|
||||
while (!_thread_should_exit) {
|
||||
|
||||
px4_usleep(1000);
|
||||
|
||||
bool updated = false;
|
||||
@@ -484,7 +468,8 @@ int uORBTest::UnitTest::test_multi2()
|
||||
orb_copy(ORB_ID(orb_test_medium_multi), orb_data_cur_fd, &msg);
|
||||
|
||||
if (last_time[orb_data_next] >= msg.timestamp && last_time[orb_data_next] != 0) {
|
||||
return test_fail("Timestamp not increasing! (%" PRIu64 " >= %" PRIu64 ")", last_time[orb_data_next], msg.timestamp);
|
||||
return test_fail("Timestamp not increasing! (%" PRIu64 " >= %" PRIu64 ")",
|
||||
last_time[orb_data_next], msg.timestamp);
|
||||
}
|
||||
|
||||
last_time[orb_data_next] = msg.timestamp;
|
||||
@@ -501,8 +486,7 @@ int uORBTest::UnitTest::test_multi2()
|
||||
return test_note("PASS multi-topic 2 test (queue simulation)");
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_multi_reversed()
|
||||
{
|
||||
int uORBTest::UnitTest::test_multi_reversed() {
|
||||
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. */
|
||||
@@ -564,8 +548,7 @@ int uORBTest::UnitTest::test_multi_reversed()
|
||||
return test_note("PASS multi-topic reversed");
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_wrap_around()
|
||||
{
|
||||
int uORBTest::UnitTest::test_wrap_around() {
|
||||
test_note("Testing orb wrap-around");
|
||||
|
||||
orb_test_medium_s t{};
|
||||
@@ -573,7 +556,8 @@ int uORBTest::UnitTest::test_wrap_around()
|
||||
orb_advert_t ptopic{nullptr};
|
||||
bool updated{false};
|
||||
|
||||
// Advertise but not publish topics, only generate device_node, which is convenient for modifying DeviceNode::_generation
|
||||
// Advertise but not publish topics, only generate device_node, which is convenient for modifying
|
||||
// DeviceNode::_generation
|
||||
const int queue_size = 16;
|
||||
ptopic = orb_advertise_queue(ORB_ID(orb_test_medium_wrap_around), nullptr, queue_size);
|
||||
|
||||
@@ -581,7 +565,8 @@ int uORBTest::UnitTest::test_wrap_around()
|
||||
return test_fail("advertise failed: %d", errno);
|
||||
}
|
||||
|
||||
auto node = uORB::Manager::get_instance()->get_device_master()->getDeviceNode(ORB_ID(orb_test_medium_wrap_around), 0);
|
||||
auto node = uORB::Manager::get_instance()->get_device_master()->getDeviceNode(
|
||||
ORB_ID(orb_test_medium_wrap_around), 0);
|
||||
|
||||
if (node == nullptr) {
|
||||
return test_fail("get device node failed.");
|
||||
@@ -589,7 +574,8 @@ int uORBTest::UnitTest::test_wrap_around()
|
||||
|
||||
// Set generation
|
||||
{
|
||||
// Set generation to the location where wrap-around is about to be: (0 - queue_size / 2) => (UINT_MAX - queue_size / 2 + 1)
|
||||
// Set generation to the location where wrap-around is about to be: (0 - queue_size / 2) => (UINT_MAX -
|
||||
// queue_size / 2 + 1)
|
||||
set_generation(*node, unsigned(-(queue_size / 2)));
|
||||
|
||||
if (node->updates_available(0) != unsigned(-(queue_size / 2))) {
|
||||
@@ -626,23 +612,23 @@ int uORBTest::UnitTest::test_wrap_around()
|
||||
return test_fail("spurious updated flag");
|
||||
}
|
||||
|
||||
#define CHECK_UPDATED(element) \
|
||||
orb_check(sfd, &updated); \
|
||||
if (!updated) { \
|
||||
#define CHECK_UPDATED(element) \
|
||||
orb_check(sfd, &updated); \
|
||||
if (!updated) { \
|
||||
return test_fail("update flag not set, element %i", element); \
|
||||
}
|
||||
#define CHECK_NOT_UPDATED(element) \
|
||||
orb_check(sfd, &updated); \
|
||||
if (updated) { \
|
||||
#define CHECK_NOT_UPDATED(element) \
|
||||
orb_check(sfd, &updated); \
|
||||
if (updated) { \
|
||||
return test_fail("update flag set, element %i", element); \
|
||||
}
|
||||
#define CHECK_COPY(i_got, i_correct) \
|
||||
orb_copy(ORB_ID(orb_test_medium_wrap_around), sfd, &u); \
|
||||
if (i_got != i_correct) { \
|
||||
#define CHECK_COPY(i_got, i_correct) \
|
||||
orb_copy(ORB_ID(orb_test_medium_wrap_around), sfd, &u); \
|
||||
if (i_got != i_correct) { \
|
||||
return test_fail("got wrong element from the queue (got %i, should be %i)", i_got, i_correct); \
|
||||
}
|
||||
|
||||
//no messages in the queue anymore
|
||||
// no messages in the queue anymore
|
||||
|
||||
test_note(" Testing to write some elements...");
|
||||
|
||||
@@ -658,15 +644,15 @@ int uORBTest::UnitTest::test_wrap_around()
|
||||
|
||||
CHECK_NOT_UPDATED(queue_size);
|
||||
|
||||
#define SET_GENERTATION() \
|
||||
set_generation(*node, unsigned(-(queue_size / 2))); \
|
||||
if (node->updates_available(0) != unsigned(-(queue_size / 2))) { \
|
||||
return test_fail("set generation failed."); \
|
||||
} \
|
||||
for (int i = 0; i < queue_size; i++) { \
|
||||
#define SET_GENERTATION() \
|
||||
set_generation(*node, unsigned(-(queue_size / 2))); \
|
||||
if (node->updates_available(0) != unsigned(-(queue_size / 2))) { \
|
||||
return test_fail("set generation failed."); \
|
||||
} \
|
||||
for (int i = 0; i < queue_size; i++) { \
|
||||
if (PX4_OK != orb_copy(ORB_ID(orb_test_medium_wrap_around), sfd, &u)) { \
|
||||
break; \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
test_note(" Testing overflow...");
|
||||
@@ -718,21 +704,12 @@ int uORBTest::UnitTest::test_wrap_around()
|
||||
return test_note("PASS orb wrap around");
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_SubscriptionMulti()
|
||||
{
|
||||
|
||||
int uORBTest::UnitTest::test_SubscriptionMulti() {
|
||||
uORB::PublicationMulti<orb_test_s> orb_test_pub_multi[ORB_MULTI_MAX_INSTANCES] {
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test, ORB_ID::orb_test, ORB_ID::orb_test, ORB_ID::orb_test,
|
||||
#if ORB_MULTI_MAX_INSTANCES > 4
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test,
|
||||
ORB_ID::orb_test, ORB_ID::orb_test, ORB_ID::orb_test, ORB_ID::orb_test, ORB_ID::orb_test,
|
||||
ORB_ID::orb_test,
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -760,7 +737,8 @@ int uORBTest::UnitTest::test_SubscriptionMulti()
|
||||
|
||||
// verify instance numbering
|
||||
if (orb_test_sub_multi_array[i].get_instance() != i) {
|
||||
return test_fail("sub %d doesn't match instance %d", i, orb_test_sub_multi_array[i].get_instance());
|
||||
return test_fail("sub %d doesn't match instance %d", i,
|
||||
orb_test_sub_multi_array[i].get_instance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,7 +755,6 @@ int uORBTest::UnitTest::test_SubscriptionMulti()
|
||||
int sub_instance = 0;
|
||||
|
||||
for (auto &sub : orb_test_sub_multi_array) {
|
||||
|
||||
if (!sub.updated()) {
|
||||
return test_fail("sub %d not updated", sub_instance);
|
||||
|
||||
@@ -791,12 +768,15 @@ int uORBTest::UnitTest::test_SubscriptionMulti()
|
||||
|
||||
} else {
|
||||
if (orb_test_copy.val != (i * sub_instance + t)) {
|
||||
return test_fail("sub %d invalid value %d", sub_instance, orb_test_copy.val);
|
||||
return test_fail("sub %d invalid value %d", sub_instance,
|
||||
orb_test_copy.val);
|
||||
}
|
||||
|
||||
if (sub.get_last_generation() != last_gen + 1) {
|
||||
//return test_fail("sub %d generation should be %d + 1, but it's %d", sub_instance, last_gen, sub.get_last_generation());
|
||||
PX4_WARN("sub %d generation should be %d + 1, but it's %d", sub_instance, last_gen, sub.get_last_generation());
|
||||
// return test_fail("sub %d generation should be %d + 1, but
|
||||
// it's %d", sub_instance, last_gen, sub.get_last_generation());
|
||||
PX4_WARN("sub %d generation should be %d + 1, but it's %d",
|
||||
sub_instance, last_gen, sub.get_last_generation());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -814,8 +794,7 @@ int uORBTest::UnitTest::test_SubscriptionMulti()
|
||||
return test_note("PASS orb SubscriptionMulti");
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_queue()
|
||||
{
|
||||
int uORBTest::UnitTest::test_queue() {
|
||||
test_note("Testing orb queuing");
|
||||
|
||||
orb_test_medium_s u{};
|
||||
@@ -856,23 +835,23 @@ int uORBTest::UnitTest::test_queue()
|
||||
return test_fail("spurious updated flag");
|
||||
}
|
||||
|
||||
#define CHECK_UPDATED(element) \
|
||||
orb_check(sfd, &updated); \
|
||||
if (!updated) { \
|
||||
#define CHECK_UPDATED(element) \
|
||||
orb_check(sfd, &updated); \
|
||||
if (!updated) { \
|
||||
return test_fail("update flag not set, element %i", element); \
|
||||
}
|
||||
#define CHECK_NOT_UPDATED(element) \
|
||||
orb_check(sfd, &updated); \
|
||||
if (updated) { \
|
||||
#define CHECK_NOT_UPDATED(element) \
|
||||
orb_check(sfd, &updated); \
|
||||
if (updated) { \
|
||||
return test_fail("update flag set, element %i", element); \
|
||||
}
|
||||
#define CHECK_COPY(i_got, i_correct) \
|
||||
orb_copy(ORB_ID(orb_test_medium_queue), sfd, &u); \
|
||||
if (i_got != i_correct) { \
|
||||
#define CHECK_COPY(i_got, i_correct) \
|
||||
orb_copy(ORB_ID(orb_test_medium_queue), sfd, &u); \
|
||||
if (i_got != i_correct) { \
|
||||
return test_fail("got wrong element from the queue (got %i, should be %i)", i_got, i_correct); \
|
||||
}
|
||||
|
||||
//no messages in the queue anymore
|
||||
// no messages in the queue anymore
|
||||
|
||||
test_note(" Testing to write some elements...");
|
||||
|
||||
@@ -924,15 +903,12 @@ int uORBTest::UnitTest::test_queue()
|
||||
return test_note("PASS orb queuing");
|
||||
}
|
||||
|
||||
|
||||
int uORBTest::UnitTest::pub_test_queue_entry(int argc, char *argv[])
|
||||
{
|
||||
int uORBTest::UnitTest::pub_test_queue_entry(int argc, char *argv[]) {
|
||||
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
||||
return t.pub_test_queue_main();
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::pub_test_queue_main()
|
||||
{
|
||||
int uORBTest::UnitTest::pub_test_queue_main() {
|
||||
orb_test_medium_s t{};
|
||||
orb_advert_t ptopic{nullptr};
|
||||
const int queue_size = 50;
|
||||
@@ -948,17 +924,16 @@ int uORBTest::UnitTest::pub_test_queue_main()
|
||||
++t.val;
|
||||
|
||||
while (message_counter < num_messages) {
|
||||
|
||||
//simulate burst
|
||||
// simulate burst
|
||||
int burst_counter = 0;
|
||||
|
||||
while (burst_counter++ < queue_size / 2 + 7) { //make interval non-boundary aligned
|
||||
while (burst_counter++ < queue_size / 2 + 7) { // make interval non-boundary aligned
|
||||
orb_publish(ORB_ID(orb_test_medium_queue_poll), ptopic, &t);
|
||||
++t.val;
|
||||
}
|
||||
|
||||
message_counter += burst_counter;
|
||||
px4_usleep(20 * 1000); //give subscriber a chance to catch up
|
||||
px4_usleep(20 * 1000); // give subscriber a chance to catch up
|
||||
}
|
||||
|
||||
_num_messages_sent = t.val;
|
||||
@@ -969,8 +944,7 @@ int uORBTest::UnitTest::pub_test_queue_main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_queue_poll_notify()
|
||||
{
|
||||
int uORBTest::UnitTest::test_queue_poll_notify() {
|
||||
test_note("Testing orb queuing (poll & notify)");
|
||||
|
||||
orb_test_medium_s t{};
|
||||
@@ -982,25 +956,20 @@ int uORBTest::UnitTest::test_queue_poll_notify()
|
||||
|
||||
_thread_should_exit = false;
|
||||
|
||||
char *const args[1] = { nullptr };
|
||||
int pubsub_task = px4_task_spawn_cmd("uorb_test_queue",
|
||||
SCHED_DEFAULT,
|
||||
SCHED_PRIORITY_DEFAULT,
|
||||
2000,
|
||||
(px4_main_t)&uORBTest::UnitTest::pub_test_queue_entry,
|
||||
args);
|
||||
char *const args[1] = {nullptr};
|
||||
int pubsub_task = px4_task_spawn_cmd("uorb_test_queue", SCHED_DEFAULT, SCHED_PRIORITY_DEFAULT, 2000,
|
||||
(px4_main_t)&uORBTest::UnitTest::pub_test_queue_entry, args);
|
||||
|
||||
if (pubsub_task < 0) {
|
||||
return test_fail("failed launching task");
|
||||
}
|
||||
|
||||
int next_expected_val = 0;
|
||||
px4_pollfd_struct_t fds[1] {};
|
||||
px4_pollfd_struct_t fds[1]{};
|
||||
fds[0].fd = sfd;
|
||||
fds[0].events = POLLIN;
|
||||
|
||||
while (!_thread_should_exit) {
|
||||
|
||||
int poll_ret = px4_poll(fds, 1, 500);
|
||||
|
||||
if (poll_ret == 0) {
|
||||
@@ -1033,8 +1002,7 @@ int uORBTest::UnitTest::test_queue_poll_notify()
|
||||
return test_note("PASS orb queuing (poll & notify), got %i messages", next_expected_val);
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::latency_test(bool print)
|
||||
{
|
||||
int uORBTest::UnitTest::latency_test(bool print) {
|
||||
test_note("---------------- LATENCY TEST ------------------");
|
||||
orb_test_medium_s t{};
|
||||
t.val = 308;
|
||||
@@ -1046,7 +1014,7 @@ int uORBTest::UnitTest::latency_test(bool print)
|
||||
return test_fail("orb_advertise failed (%i)", errno);
|
||||
}
|
||||
|
||||
char *const args[1] = { nullptr };
|
||||
char *const args[1] = {nullptr};
|
||||
|
||||
pubsubtest_print = print;
|
||||
pubsubtest_passed = false;
|
||||
@@ -1056,12 +1024,8 @@ int uORBTest::UnitTest::latency_test(bool print)
|
||||
// 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,
|
||||
2000,
|
||||
(px4_main_t)&uORBTest::UnitTest::pubsubtest_threadEntry,
|
||||
args);
|
||||
int pubsub_task = px4_task_spawn_cmd("uorb_latency", SCHED_DEFAULT, SCHED_PRIORITY_MAX, 2000,
|
||||
(px4_main_t)&uORBTest::UnitTest::pubsubtest_threadEntry, args);
|
||||
|
||||
/* give the test task some data */
|
||||
while (!pubsubtest_passed) {
|
||||
@@ -1085,8 +1049,7 @@ int uORBTest::UnitTest::latency_test(bool print)
|
||||
return pubsubtest_res;
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_fail(const char *fmt, ...)
|
||||
{
|
||||
int uORBTest::UnitTest::test_fail(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
fprintf(stderr, "uORB FAIL: ");
|
||||
@@ -1099,8 +1062,7 @@ int uORBTest::UnitTest::test_fail(const char *fmt, ...)
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::test_note(const char *fmt, ...)
|
||||
{
|
||||
int uORBTest::UnitTest::test_note(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
fprintf(stderr, "uORB note: ");
|
||||
@@ -1112,8 +1074,7 @@ int uORBTest::UnitTest::test_note(const char *fmt, ...)
|
||||
return OK;
|
||||
}
|
||||
|
||||
int uORBTest::UnitTest::pubsubtest_threadEntry(int argc, char *argv[])
|
||||
{
|
||||
int uORBTest::UnitTest::pubsubtest_threadEntry(int argc, char *argv[]) {
|
||||
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
|
||||
return t.pubsublatency_main();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user