posix: pthread: test the priority conversion functions
Made the conversion functions non-static and added ztests for them to make sure that they work across the full range of Zephyr priorities. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
parent
5ad7f4b314
commit
c3cc2e4e6d
2 changed files with 37 additions and 2 deletions
|
@ -227,7 +227,8 @@ static bool is_posix_policy_prio_valid(uint32_t priority, int policy)
|
|||
return false;
|
||||
}
|
||||
|
||||
static int zephyr_to_posix_priority(int z_prio, int *policy)
|
||||
/* Non-static so that they can be tested in ztest */
|
||||
int zephyr_to_posix_priority(int z_prio, int *policy)
|
||||
{
|
||||
if (z_prio < 0) {
|
||||
__ASSERT_NO_MSG(-z_prio <= CONFIG_NUM_COOP_PRIORITIES);
|
||||
|
@ -239,7 +240,8 @@ static int zephyr_to_posix_priority(int z_prio, int *policy)
|
|||
return ZEPHYR_TO_POSIX_PRIORITY(z_prio);
|
||||
}
|
||||
|
||||
static int posix_to_zephyr_priority(int priority, int policy)
|
||||
/* Non-static so that they can be tested in ztest */
|
||||
int posix_to_zephyr_priority(int priority, int policy)
|
||||
{
|
||||
if (policy == SCHED_FIFO) {
|
||||
/* COOP: highest [-CONFIG_NUM_COOP_PRIORITIES, -1] lowest */
|
||||
|
|
|
@ -215,6 +215,39 @@ static void *thread_top_term(void *p1)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Test the internal priority conversion functions */
|
||||
int zephyr_to_posix_priority(int z_prio, int *policy);
|
||||
int posix_to_zephyr_priority(int priority, int policy);
|
||||
ZTEST(pthread, test_pthread_priority_conversion)
|
||||
{
|
||||
/*
|
||||
* ZEPHYR [-CONFIG_NUM_COOP_PRIORITIES, -1]
|
||||
* TO
|
||||
* POSIX(FIFO) [0, CONFIG_NUM_COOP_PRIORITIES - 1]
|
||||
*/
|
||||
for (int z_prio = -CONFIG_NUM_COOP_PRIORITIES, prio = CONFIG_NUM_COOP_PRIORITIES - 1,
|
||||
p_prio, policy;
|
||||
z_prio <= -1; z_prio++, prio--) {
|
||||
p_prio = zephyr_to_posix_priority(z_prio, &policy);
|
||||
zassert_equal(policy, SCHED_FIFO);
|
||||
zassert_equal(p_prio, prio, "%d %d\n", p_prio, prio);
|
||||
zassert_equal(z_prio, posix_to_zephyr_priority(p_prio, SCHED_FIFO));
|
||||
}
|
||||
|
||||
/*
|
||||
* ZEPHYR [0, CONFIG_NUM_PREEMPT_PRIORITIES - 1]
|
||||
* TO
|
||||
* POSIX(RR) [0, CONFIG_NUM_PREEMPT_PRIORITIES - 1]
|
||||
*/
|
||||
for (int z_prio = 0, prio = CONFIG_NUM_PREEMPT_PRIORITIES - 1, p_prio, policy;
|
||||
z_prio < CONFIG_NUM_PREEMPT_PRIORITIES; z_prio++, prio--) {
|
||||
p_prio = zephyr_to_posix_priority(z_prio, &policy);
|
||||
zassert_equal(policy, SCHED_RR);
|
||||
zassert_equal(p_prio, prio, "%d %d\n", p_prio, prio);
|
||||
zassert_equal(z_prio, posix_to_zephyr_priority(p_prio, SCHED_RR));
|
||||
}
|
||||
}
|
||||
|
||||
ZTEST(pthread, test_pthread_execution)
|
||||
{
|
||||
int i, ret;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue