Skip to content

Commit

Permalink
AP_Networking: move to using enum class for Tests bitmask
Browse files Browse the repository at this point in the history
  • Loading branch information
bugobliterator committed Sep 17, 2024
1 parent 99fb74c commit d473aae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
13 changes: 7 additions & 6 deletions libraries/AP_Networking/AP_Networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,14 @@ class AP_Networking
uint32_t announce_ms;

#if AP_NETWORKING_TESTS_ENABLED
enum {
TEST_UDP_CLIENT = (1U<<0),
TEST_TCP_CLIENT = (1U<<1),
TEST_TCP_DISCARD = (1U<<2),
TEST_TCP_REFLECT = (1U<<3),
TEST_CONNECTOR_LOOPBACK = (1U<<4),
enum class Test {
UDP_CLIENT = (1U<<0),
TCP_CLIENT = (1U<<1),
TCP_DISCARD = (1U<<2),
TCP_REFLECT = (1U<<3),
CONNECTOR_LOOPBACK = (1U<<4),
};
bool test_enabled(Test test) const;
void start_tests(void);
void test_UDP_client(void);
void test_TCP_client(void);
Expand Down
21 changes: 13 additions & 8 deletions libraries/AP_Networking/AP_Networking_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ extern const AP_HAL::HAL& hal;
*/
void AP_Networking::start_tests(void)
{
if (param.tests & TEST_UDP_CLIENT) {
if (test_enabled(Test::UDP_CLIENT)) {
hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Networking::test_UDP_client, void),
"UDP_client",
8192, AP_HAL::Scheduler::PRIORITY_IO, -1);
}
if (param.tests & TEST_TCP_CLIENT) {
if (test_enabled(Test::TCP_CLIENT)) {
hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Networking::test_TCP_client, void),
"TCP_client",
8192, AP_HAL::Scheduler::PRIORITY_IO, -1);
}
if (param.tests & TEST_TCP_DISCARD) {
if (test_enabled(Test::TCP_DISCARD)) {
hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Networking::test_TCP_discard, void),
"TCP_discard",
8192, AP_HAL::Scheduler::PRIORITY_UART, -1);
}
if (param.tests & TEST_TCP_REFLECT) {
if (test_enabled(Test::TCP_REFLECT)) {
hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Networking::test_TCP_reflect, void),
"TCP_reflect",
8192, AP_HAL::Scheduler::PRIORITY_UART, -1);
}
if (param.tests & TEST_CONNECTOR_LOOPBACK) {
if (test_enabled(Test::CONNECTOR_LOOPBACK)) {
hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Networking::test_connector_loopback, void),
"connector_loopback",
8192, AP_HAL::Scheduler::PRIORITY_UART, -1);
Expand Down Expand Up @@ -135,7 +135,7 @@ void AP_Networking::test_TCP_discard(void)
uint32_t last_report_ms = AP_HAL::millis();
uint32_t total_sent = 0;
while (true) {
if ((param.tests & TEST_TCP_DISCARD) == 0) {
if (!test_enabled(Test::TCP_DISCARD)) {
hal.scheduler->delay(1);
continue;
}
Expand Down Expand Up @@ -179,7 +179,7 @@ void AP_Networking::test_TCP_reflect(void)
uint32_t last_recv = 0;
const uint32_t max_disparity = 100*1024;
while (true) {
if ((param.tests & TEST_TCP_REFLECT) == 0) {
if (!test_enabled(Test::TCP_REFLECT)) {
hal.scheduler->delay(1);
continue;
}
Expand Down Expand Up @@ -255,7 +255,7 @@ void AP_Networking::test_connector_loopback(void)
uint32_t last_report_ms = AP_HAL::millis();
uint32_t total_rx = 0;
while (true) {
if ((param.tests & TEST_CONNECTOR_LOOPBACK) == 0) {
if (!test_enabled(Test::CONNECTOR_LOOPBACK)) {
hal.scheduler->delay(1);
continue;
}
Expand All @@ -274,4 +274,9 @@ void AP_Networking::test_connector_loopback(void)
}
}

bool AP_Networking::test_enabled(Test test) const
{
return param.tests & (uint32_t)test;
}

#endif // AP_NETWORKING_ENABLED && AP_NETWORKING_TESTS_ENABLED

0 comments on commit d473aae

Please sign in to comment.