Skip to content

Commit bf55de2

Browse files
KangJianXnashif
authored andcommitted
kernel: timer: Add some testcases to testing timer and clock
Add some error condition or testing cases to verify whether the robustness of API. Such as give a NULL to some API and check the response if get result that we were expacted. Signed-off-by: Jian Kang <[email protected]>
1 parent 1491fb9 commit bf55de2

File tree

6 files changed

+429
-0
lines changed

6 files changed

+429
-0
lines changed

tests/kernel/timer/timer_api/src/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ void test_timer_duration_period(void)
173173
TIMER_ASSERT(tdata.expire_cnt == EXPIRE_TIMES, &duration_timer);
174174
TIMER_ASSERT(tdata.stop_cnt == 1, &duration_timer);
175175

176+
k_timer_start(&duration_timer, K_FOREVER, K_MSEC(PERIOD));
177+
TIMER_ASSERT(tdata.stop_cnt == 1, &duration_timer);
176178
/* cleanup environemtn */
177179
k_timer_stop(&duration_timer);
178180
}
@@ -452,8 +454,13 @@ void test_timer_status_sync(void)
452454
TIMER_ASSERT(tdata.expire_cnt == (i + 1), &status_sync_timer);
453455
}
454456

457+
k_timer_start(&status_sync_timer, K_MSEC(DURATION), K_MSEC(PERIOD));
458+
busy_wait_ms(PERIOD*2);
459+
zassert_true(k_timer_status_sync(&status_sync_timer), NULL);
460+
455461
/* cleanup environment */
456462
k_timer_stop(&status_sync_timer);
463+
zassert_false(k_timer_status_sync(&status_sync_timer), NULL);
457464
}
458465

459466
/**

tests/kernel/timer/timer_api/src/timer_convert.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,29 @@ static struct test_rec tests[] = {
4646
TESTREC(ms, ticks, near, 64),
4747
TESTREC(ms, ticks, ceil, 32),
4848
TESTREC(ms, ticks, ceil, 64),
49+
TESTREC(us, cyc, floor, 32),
4950
TESTREC(us, cyc, floor, 64),
51+
TESTREC(us, cyc, near, 32),
5052
TESTREC(us, cyc, near, 64),
53+
TESTREC(us, cyc, ceil, 32),
5154
TESTREC(us, cyc, ceil, 64),
55+
TESTREC(us, ticks, floor, 32),
5256
TESTREC(us, ticks, floor, 64),
57+
TESTREC(us, ticks, near, 32),
5358
TESTREC(us, ticks, near, 64),
59+
TESTREC(us, ticks, ceil, 32),
5460
TESTREC(us, ticks, ceil, 64),
5561
TESTREC(cyc, ms, floor, 32),
5662
TESTREC(cyc, ms, floor, 64),
5763
TESTREC(cyc, ms, near, 32),
5864
TESTREC(cyc, ms, near, 64),
5965
TESTREC(cyc, ms, ceil, 32),
6066
TESTREC(cyc, ms, ceil, 64),
67+
TESTREC(cyc, us, floor, 32),
6168
TESTREC(cyc, us, floor, 64),
69+
TESTREC(cyc, us, near, 32),
6270
TESTREC(cyc, us, near, 64),
71+
TESTREC(cyc, us, ceil, 32),
6372
TESTREC(cyc, us, ceil, 64),
6473
TESTREC(cyc, ticks, floor, 32),
6574
TESTREC(cyc, ticks, floor, 64),
@@ -73,26 +82,41 @@ static struct test_rec tests[] = {
7382
TESTREC(ticks, ms, near, 64),
7483
TESTREC(ticks, ms, ceil, 32),
7584
TESTREC(ticks, ms, ceil, 64),
85+
TESTREC(ticks, us, floor, 32),
7686
TESTREC(ticks, us, floor, 64),
87+
TESTREC(ticks, us, near, 32),
7788
TESTREC(ticks, us, near, 64),
89+
TESTREC(ticks, us, ceil, 32),
7890
TESTREC(ticks, us, ceil, 64),
7991
TESTREC(ticks, cyc, floor, 32),
8092
TESTREC(ticks, cyc, floor, 64),
8193
TESTREC(ticks, cyc, near, 32),
8294
TESTREC(ticks, cyc, near, 64),
8395
TESTREC(ticks, cyc, ceil, 32),
8496
TESTREC(ticks, cyc, ceil, 64),
97+
TESTREC(ns, cyc, floor, 32),
8598
TESTREC(ns, cyc, floor, 64),
99+
TESTREC(ns, cyc, near, 32),
86100
TESTREC(ns, cyc, near, 64),
101+
TESTREC(ns, cyc, ceil, 32),
87102
TESTREC(ns, cyc, ceil, 64),
103+
TESTREC(ns, ticks, floor, 32),
88104
TESTREC(ns, ticks, floor, 64),
105+
TESTREC(ns, ticks, near, 32),
89106
TESTREC(ns, ticks, near, 64),
107+
TESTREC(ns, ticks, ceil, 32),
90108
TESTREC(ns, ticks, ceil, 64),
109+
TESTREC(cyc, ns, floor, 32),
91110
TESTREC(cyc, ns, floor, 64),
111+
TESTREC(cyc, ns, near, 32),
92112
TESTREC(cyc, ns, near, 64),
113+
TESTREC(cyc, ns, ceil, 32),
93114
TESTREC(cyc, ns, ceil, 64),
115+
TESTREC(ticks, ns, floor, 32),
94116
TESTREC(ticks, ns, floor, 64),
117+
TESTREC(ticks, ns, near, 32),
95118
TESTREC(ticks, ns, near, 64),
119+
TESTREC(ticks, ns, ceil, 32),
96120
TESTREC(ticks, ns, ceil, 64),
97121
};
98122

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(timer_api)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_TEST_USERSPACE=y
3+
CONFIG_IRQ_OFFLOAD=y
4+
CONFIG_MP_NUM_CPUS=1
5+
CONFIG_TEST_RANDOM_GENERATOR=y
6+
CONFIG_ZTEST_FATAL_HOOK=y

0 commit comments

Comments
 (0)