Browse Source

uORBTest_UnitTest: astyle

sbg
Ban Siesta 10 years ago committed by Lorenz Meier
parent
commit
8be1b4f19c
  1. 80
      src/modules/uORB/uORBTest_UnitTest.cpp
  2. 4
      src/modules/uORB/uORBTest_UnitTest.hpp

80
src/modules/uORB/uORBTest_UnitTest.cpp

@ -77,12 +77,15 @@ int uORBTest::UnitTest::pubsublatency_main(void)
for (unsigned i = 0; i < maxruns; i++) { for (unsigned i = 0; i < maxruns; i++) {
/* wait for up to 500ms for data */ /* wait for up to 500ms for data */
int pret = px4_poll(&fds[0], (sizeof(fds) / sizeof(fds[0])), 500); int pret = px4_poll(&fds[0], (sizeof(fds) / sizeof(fds[0])), 500);
if (fds[0].revents & POLLIN) { if (fds[0].revents & POLLIN) {
orb_copy(ORB_ID(orb_test), test_multi_sub, &t); orb_copy(ORB_ID(orb_test), test_multi_sub, &t);
timingsgroup = 0; timingsgroup = 0;
} else if (fds[1].revents & POLLIN) { } else if (fds[1].revents & POLLIN) {
orb_copy(ORB_ID(orb_test_medium), test_multi_sub_medium, &t); orb_copy(ORB_ID(orb_test_medium), test_multi_sub_medium, &t);
timingsgroup = 1; timingsgroup = 1;
} else if (fds[2].revents & POLLIN) { } else if (fds[2].revents & POLLIN) {
orb_copy(ORB_ID(orb_test_large), test_multi_sub_large, &t); orb_copy(ORB_ID(orb_test_large), test_multi_sub_large, &t);
timingsgroup = 2; timingsgroup = 2;
@ -106,6 +109,7 @@ int uORBTest::UnitTest::pubsublatency_main(void)
char fname[32]; char fname[32];
sprintf(fname, PX4_ROOTFSDIR"/fs/microsd/timings%u.txt", timingsgroup); sprintf(fname, PX4_ROOTFSDIR"/fs/microsd/timings%u.txt", timingsgroup);
FILE *f = fopen(fname, "w"); FILE *f = fopen(fname, "w");
if (f == NULL) { if (f == NULL) {
warnx("Error opening file!\n"); warnx("Error opening file!\n");
return uORB::ERROR; return uORB::ERROR;
@ -126,6 +130,7 @@ int uORBTest::UnitTest::pubsublatency_main(void)
if (static_cast<float>(latency_integral / maxruns) > 30.0f) { if (static_cast<float>(latency_integral / maxruns) > 30.0f) {
pubsubtest_res = uORB::ERROR; pubsubtest_res = uORB::ERROR;
} else { } else {
pubsubtest_res = PX4_OK; pubsubtest_res = PX4_OK;
} }
@ -143,47 +148,58 @@ int uORBTest::UnitTest::test()
t.val = 0; t.val = 0;
ptopic = orb_advertise(ORB_ID(orb_test), &t); ptopic = orb_advertise(ORB_ID(orb_test), &t);
if (ptopic == nullptr) if (ptopic == nullptr) {
return test_fail("advertise failed: %d", errno); return test_fail("advertise failed: %d", errno);
}
test_note("publish handle 0x%08x", ptopic); test_note("publish handle 0x%08x", ptopic);
sfd = orb_subscribe(ORB_ID(orb_test)); sfd = orb_subscribe(ORB_ID(orb_test));
if (sfd < 0) if (sfd < 0) {
return test_fail("subscribe failed: %d", errno); return test_fail("subscribe failed: %d", errno);
}
test_note("subscribe fd %d", sfd); test_note("subscribe fd %d", sfd);
u.val = 1; u.val = 1;
if (PX4_OK != orb_copy(ORB_ID(orb_test), sfd, &u)) if (PX4_OK != orb_copy(ORB_ID(orb_test), sfd, &u)) {
return test_fail("copy(1) failed: %d", errno); return test_fail("copy(1) failed: %d", errno);
}
if (u.val != t.val) if (u.val != t.val) {
return test_fail("copy(1) mismatch: %d expected %d", u.val, t.val); return test_fail("copy(1) mismatch: %d expected %d", u.val, t.val);
}
if (PX4_OK != orb_check(sfd, &updated)) if (PX4_OK != orb_check(sfd, &updated)) {
return test_fail("check(1) failed"); return test_fail("check(1) failed");
}
if (updated) if (updated) {
return test_fail("spurious updated flag"); return test_fail("spurious updated flag");
}
t.val = 2; t.val = 2;
test_note("try publish"); test_note("try publish");
if (PX4_OK != orb_publish(ORB_ID(orb_test), ptopic, &t)) if (PX4_OK != orb_publish(ORB_ID(orb_test), ptopic, &t)) {
return test_fail("publish failed"); return test_fail("publish failed");
}
if (PX4_OK != orb_check(sfd, &updated)) if (PX4_OK != orb_check(sfd, &updated)) {
return test_fail("check(2) failed"); return test_fail("check(2) failed");
}
if (!updated) if (!updated) {
return test_fail("missing updated flag"); return test_fail("missing updated flag");
}
if (PX4_OK != orb_copy(ORB_ID(orb_test), sfd, &u)) if (PX4_OK != orb_copy(ORB_ID(orb_test), sfd, &u)) {
return test_fail("copy(2) failed: %d", errno); return test_fail("copy(2) failed: %d", errno);
}
if (u.val != t.val) if (u.val != t.val) {
return test_fail("copy(2) mismatch: %d expected %d", u.val, t.val); return test_fail("copy(2) mismatch: %d expected %d", u.val, t.val);
}
orb_unsubscribe(sfd); orb_unsubscribe(sfd);
@ -198,55 +214,71 @@ int uORBTest::UnitTest::test()
int instance1; int instance1;
orb_advert_t pfd1 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance1, ORB_PRIO_MIN); orb_advert_t pfd1 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance1, ORB_PRIO_MIN);
if (instance0 != 0) if (instance0 != 0) {
return test_fail("mult. id0: %d", instance0); return test_fail("mult. id0: %d", instance0);
}
if (instance1 != 1) if (instance1 != 1) {
return test_fail("mult. id1: %d", instance1); return test_fail("mult. id1: %d", instance1);
}
t.val = 103; t.val = 103;
if (PX4_OK != orb_publish(ORB_ID(orb_multitest), pfd0, &t))
if (PX4_OK != orb_publish(ORB_ID(orb_multitest), pfd0, &t)) {
return test_fail("mult. pub0 fail"); return test_fail("mult. pub0 fail");
}
test_note("published"); test_note("published");
t.val = 203; t.val = 203;
if (PX4_OK != orb_publish(ORB_ID(orb_multitest), pfd1, &t))
if (PX4_OK != orb_publish(ORB_ID(orb_multitest), pfd1, &t)) {
return test_fail("mult. pub1 fail"); return test_fail("mult. pub1 fail");
}
/* subscribe to both topics and ensure valid data is received */ /* subscribe to both topics and ensure valid data is received */
int sfd0 = orb_subscribe_multi(ORB_ID(orb_multitest), 0); int sfd0 = orb_subscribe_multi(ORB_ID(orb_multitest), 0);
if (PX4_OK != orb_copy(ORB_ID(orb_multitest), sfd0, &u)) if (PX4_OK != orb_copy(ORB_ID(orb_multitest), sfd0, &u)) {
return test_fail("sub #0 copy failed: %d", errno); return test_fail("sub #0 copy failed: %d", errno);
}
if (u.val != 103) if (u.val != 103) {
return test_fail("sub #0 val. mismatch: %d", u.val); return test_fail("sub #0 val. mismatch: %d", u.val);
}
int sfd1 = orb_subscribe_multi(ORB_ID(orb_multitest), 1); int sfd1 = orb_subscribe_multi(ORB_ID(orb_multitest), 1);
if (PX4_OK != orb_copy(ORB_ID(orb_multitest), sfd1, &u)) if (PX4_OK != orb_copy(ORB_ID(orb_multitest), sfd1, &u)) {
return test_fail("sub #1 copy failed: %d", errno); return test_fail("sub #1 copy failed: %d", errno);
}
if (u.val != 203) if (u.val != 203) {
return test_fail("sub #1 val. mismatch: %d", u.val); return test_fail("sub #1 val. mismatch: %d", u.val);
}
/* test priorities */ /* test priorities */
int prio; int prio;
if (PX4_OK != orb_priority(sfd0, &prio))
if (PX4_OK != orb_priority(sfd0, &prio)) {
return test_fail("prio #0"); return test_fail("prio #0");
}
if (prio != ORB_PRIO_MAX) if (prio != ORB_PRIO_MAX) {
return test_fail("prio: %d", prio); return test_fail("prio: %d", prio);
}
if (PX4_OK != orb_priority(sfd1, &prio)) if (PX4_OK != orb_priority(sfd1, &prio)) {
return test_fail("prio #1"); return test_fail("prio #1");
}
if (prio != ORB_PRIO_MIN) if (prio != ORB_PRIO_MIN) {
return test_fail("prio: %d", prio); return test_fail("prio: %d", prio);
}
if (PX4_OK != latency_test<struct orb_test>(ORB_ID(orb_test), false)) if (PX4_OK != latency_test<struct orb_test>(ORB_ID(orb_test), false)) {
return test_fail("latency test failed"); return test_fail("latency test failed");
}
return test_note("PASS"); return test_note("PASS");
} }

4
src/modules/uORB/uORBTest_UnitTest.hpp

@ -121,8 +121,10 @@ int uORBTest::UnitTest::latency_test(orb_id_t T, bool print)
while (!pubsubtest_passed) { while (!pubsubtest_passed) {
t.val = 308; t.val = 308;
t.time = hrt_absolute_time(); t.time = hrt_absolute_time();
if (PX4_OK != orb_publish(T, pfd0, &t))
if (PX4_OK != orb_publish(T, pfd0, &t)) {
return test_fail("mult. pub0 timing fail"); return test_fail("mult. pub0 timing fail");
}
/* simulate >800 Hz system operation */ /* simulate >800 Hz system operation */
usleep(1000); usleep(1000);

Loading…
Cancel
Save