uORB: join threads in unit tests

This commit is contained in:
Julian Oes 2026-02-18 13:11:33 +13:00
parent 261cc16077
commit 20669aba6f
No known key found for this signature in database
GPG Key ID: F0ED380FEA56DE41
3 changed files with 23 additions and 0 deletions

View File

@ -167,6 +167,9 @@ __EXPORT px4_task_t px4_task_spawn_cmd(const char *name,
/** Deletes a task - does not do resource cleanup **/
__EXPORT int px4_task_delete(px4_task_t pid);
/** Wait for a task to exit. Returns 0 on success. Only supported on POSIX. **/
__EXPORT int px4_task_join(px4_task_t pid);
/** Send a signal to a task **/
__EXPORT int px4_task_kill(px4_task_t pid, int sig);

View File

@ -501,6 +501,8 @@ int uORBTest::UnitTest::test_multi2()
}
}
px4_task_join(pubsub_task);
for (int i = 0; i < num_instances; ++i) {
orb_unsubscribe(orb_data_fd[i]);
}
@ -1032,6 +1034,8 @@ int uORBTest::UnitTest::test_queue_poll_notify()
}
}
px4_task_join(pubsub_task);
if (_num_messages_sent.load() != next_expected_val) {
return test_fail("number of sent and received messages mismatch (sent: %i, received: %i)",
_num_messages_sent.load(), next_expected_val);
@ -1087,6 +1091,7 @@ int uORBTest::UnitTest::latency_test(bool print)
return test_fail("failed launching task");
}
px4_task_join(pubsub_task);
orb_unadvertise(pfd0);
return pubsubtest_res.load();

View File

@ -274,6 +274,21 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
return taskid;
}
int px4_task_join(px4_task_t id)
{
if (id < PX4_MAX_TASKS) {
pthread_mutex_lock(&task_mutex);
pthread_t pid = taskmap[id].pid;
pthread_mutex_unlock(&task_mutex);
if (pid != 0) {
return pthread_join(pid, nullptr);
}
}
return -EINVAL;
}
int px4_task_delete(px4_task_t id)
{
int rv = 0;