From 9c1622a64ae3d36b7c0785696ea46e5ebcec8dd4 Mon Sep 17 00:00:00 2001 From: Punit Vara Date: Tue, 10 Oct 2017 15:36:43 +0530 Subject: [PATCH] tests: tickless: Make use of ztest framework Add appropriate ztest APIs to make this legacy test case to use ztest framework. Signed-off-by: Punit Vara --- tests/kernel/tickless/tickless/prj.conf | 1 + .../tickless/tickless/src/test_tickless.c | 40 +++++++++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/tests/kernel/tickless/tickless/prj.conf b/tests/kernel/tickless/tickless/prj.conf index d4a38aa02ce..999abd18cda 100644 --- a/tests/kernel/tickless/tickless/prj.conf +++ b/tests/kernel/tickless/tickless/prj.conf @@ -1 +1,2 @@ CONFIG_SYS_POWER_MANAGEMENT=y +CONFIG_ZTEST=y diff --git a/tests/kernel/tickless/tickless/src/test_tickless.c b/tests/kernel/tickless/tickless/src/test_tickless.c index c948df9a167..c40960b56b3 100644 --- a/tests/kernel/tickless/tickless/src/test_tickless.c +++ b/tests/kernel/tickless/tickless/src/test_tickless.c @@ -6,12 +6,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -/* -DESCRIPTION -Unit test for tickless idle feature. - */ +/* DESCRIPTION Unit test for tickless idle feature. */ #include +#include #include #include @@ -22,6 +20,9 @@ Unit test for tickless idle feature. #define SLEEP_TICKS 10 +static struct k_thread thread_tickless; +static K_THREAD_STACK_DEFINE(thread_tickless_stack, STACKSIZE); + #ifdef CONFIG_TICKLESS_IDLE extern s32_t _sys_idle_threshold_ticks; #endif @@ -173,7 +174,10 @@ void ticklessTestThread(void) printk("Cal time stamp: 0x%x\n", cal_tsc); #endif - /* Calculate percentage difference between calibrated TSC diff and measured result */ + /* + * Calculate percentage difference between + * calibrated TSC diff and measured result + */ if (diff_tsc > cal_tsc) { diff_per = (100 * (diff_tsc - cal_tsc)) / cal_tsc; } else { @@ -182,12 +186,8 @@ void ticklessTestThread(void) printk("variance in time stamp diff: %d percent\n", (s32_t)diff_per); - if (diff_ticks != SLEEP_TICKS) { - printk("* TEST FAILED. TICK COUNT INCORRECT *\n"); - TC_END_REPORT(TC_FAIL); - } else { - TC_END_REPORT(TC_PASS); - } + zassert_equal(diff_ticks, SLEEP_TICKS, + "* TEST FAILED. TICK COUNT INCORRECT *"); /* release the timer, if necessary */ _TIMESTAMP_CLOSE(); @@ -198,5 +198,19 @@ void ticklessTestThread(void) } -K_THREAD_DEFINE(TICKLESS_THREAD, STACKSIZE, ticklessTestThread, NULL, NULL, - NULL, PRIORITY, 0, K_NO_WAIT); +void test_tickless(void) +{ + k_thread_create(&thread_tickless, thread_tickless_stack, + STACKSIZE, + (k_thread_entry_t) ticklessTestThread, + NULL, NULL, NULL, + PRIORITY, 0, K_NO_WAIT); + k_sleep(4000); +} + +void test_main(void) +{ + ztest_test_suite(test_tick_less, + ztest_unit_test(test_tickless)); + ztest_run_test_suite(test_tick_less); +}