Skip to content

Commit c9f0148

Browse files
Andrew Boienashif
authored andcommitted
tests: schedule_api: cover priority checks
Some cases, such as for the idle thread, were uncovered. Signed-off-by: Andrew Boie <[email protected]>
1 parent f0f74e4 commit c9f0148

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

tests/kernel/sched/schedule_api/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void test_main(void)
5454
#endif /* CONFIG_USERSPACE */
5555

5656
ztest_test_suite(threads_scheduling,
57+
ztest_unit_test(test_bad_priorities),
5758
ztest_unit_test(test_priority_cooperative),
5859
ztest_unit_test(test_priority_preemptible),
5960
ztest_unit_test(test_yield_cooperative),

tests/kernel/sched/schedule_api/src/test_sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void spin_for_ms(int ticks);
2828

2929
void test_priority_cooperative(void);
3030
void test_priority_preemptible(void);
31+
void test_bad_priorities(void);
3132
void test_yield_cooperative(void);
3233
void test_sleep_cooperative(void);
3334
void test_sleep_wakeup_preemptible(void);

tests/kernel/sched/schedule_api/src/test_sched_priority.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "test_sched.h"
8+
#include <ksched.h>
89

910
static struct k_thread tdata;
1011
static int last_prio;
@@ -93,3 +94,41 @@ void test_priority_preemptible(void)
9394
/* restore environment */
9495
k_thread_priority_set(k_current_get(), old_prio);
9596
}
97+
98+
extern void idle(void *p1, void *p2, void *p3);
99+
100+
/**
101+
* Validate checking priority values
102+
*
103+
* Our test cases don't cover every outcome of whether a priority is valid,
104+
* do so here.
105+
*
106+
* @ingroup kernel_sched_tests
107+
*/
108+
void test_bad_priorities(void)
109+
{
110+
struct prio_test {
111+
int prio;
112+
void *entry;
113+
bool result;
114+
} testcases[] = {
115+
{ K_IDLE_PRIO, idle, true },
116+
{ K_IDLE_PRIO, NULL, false },
117+
{ K_HIGHEST_APPLICATION_THREAD_PRIO - 1, NULL, false },
118+
{ K_LOWEST_APPLICATION_THREAD_PRIO + 1, NULL, false },
119+
{ K_HIGHEST_APPLICATION_THREAD_PRIO, NULL, true },
120+
{ K_LOWEST_APPLICATION_THREAD_PRIO, NULL, true },
121+
{ CONFIG_MAIN_THREAD_PRIORITY, NULL, true }
122+
};
123+
124+
for (int i = 0; i < ARRAY_SIZE(testcases); i++) {
125+
zassert_equal(_is_valid_prio(testcases[i].prio,
126+
testcases[i].entry),
127+
testcases[i].result, "failed check %d", i);
128+
/* XXX why are these even separate APIs? */
129+
zassert_equal(Z_VALID_PRIO(testcases[i].prio,
130+
testcases[i].entry),
131+
testcases[i].result, "failed check %d", i);
132+
}
133+
}
134+

0 commit comments

Comments
 (0)