mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
uORB: join threads in unit tests
This commit is contained in:
parent
261cc16077
commit
20669aba6f
@ -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);
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user