tests: kernel: add tickless test
Added test cases to verify tickless idle concepts defined in https://www.zephyrproject.org/doc/subsystems/power_management.html#tickless-idle Test points: verify system clock recovery after exiting tickless idle; verify slicing scheduler behaves as expected Jira: ZEP-339 Change-Id: Ic0a86d725e9692aa217375cedc7396372a026a88 Signed-off-by: Sharron LIU <sharron.liu@intel.com>
This commit is contained in:
parent
7fb0e36060
commit
eea12f6f14
4
tests/kernel/tickless/tickless_concept/Makefile
Normal file
4
tests/kernel/tickless/tickless_concept/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
|||
BOARD ?= qemu_x86
|
||||
CONF_FILE = prj.conf
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.test
|
4
tests/kernel/tickless/tickless_concept/prj.conf
Normal file
4
tests/kernel/tickless/tickless_concept/prj.conf
Normal file
|
@ -0,0 +1,4 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_SYS_POWER_MANAGEMENT=y
|
||||
CONFIG_TICKLESS_IDLE=y
|
||||
CONFIG_TICKLESS_IDLE_THRESH=20
|
3
tests/kernel/tickless/tickless_concept/src/Makefile
Normal file
3
tests/kernel/tickless/tickless_concept/src/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
include $(ZEPHYR_BASE)/tests/Makefile.test
|
||||
|
||||
obj-y = main.o test_tickless_sysclock.o
|
18
tests/kernel/tickless/tickless_concept/src/main.c
Normal file
18
tests/kernel/tickless/tickless_concept/src/main.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
extern void test_tickless_sysclock(void);
|
||||
extern void test_tickless_slice(void);
|
||||
|
||||
/*test case main entry*/
|
||||
void test_main(void *p1, void *p2, void *p3)
|
||||
{
|
||||
ztest_test_suite(test_tickless_concept,
|
||||
ztest_unit_test(test_tickless_sysclock),
|
||||
ztest_unit_test(test_tickless_slice));
|
||||
ztest_run_test_suite(test_tickless_concept);
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup t_tickless
|
||||
* @{
|
||||
* @defgroup t_tickless_concept test_tickless_concept
|
||||
* @brief TestPurpose: verify tickless idle concepts
|
||||
* @details
|
||||
https://www.zephyrproject.org/doc/subsystems/power_management.html#tickless-idle
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <power.h>
|
||||
|
||||
#define STACK_SIZE 512
|
||||
#define NUM_THREAD 4
|
||||
static char __noinit __stack tstack[NUM_THREAD][STACK_SIZE];
|
||||
/*for those not supporting tickless idle*/
|
||||
#ifndef CONFIG_TICKLESS_IDLE
|
||||
#define CONFIG_TICKLESS_IDLE_THRESH 20
|
||||
#endif
|
||||
/*sleep duration tickless*/
|
||||
#define SLEEP_TICKLESS (CONFIG_TICKLESS_IDLE_THRESH)
|
||||
/*sleep duration with tick*/
|
||||
#define SLEEP_TICKFUL (CONFIG_TICKLESS_IDLE_THRESH-1)
|
||||
/*slice size is set as half of the sleep duration*/
|
||||
#define SLICE_SIZE (CONFIG_TICKLESS_IDLE_THRESH >> 1)
|
||||
/*millisecond per tick*/
|
||||
#define MSEC_PER_TICK (sys_clock_us_per_tick / USEC_PER_MSEC)
|
||||
/*align to millisecond boundary*/
|
||||
#define ALIGN_MS_BOUNDARY() \
|
||||
do {\
|
||||
uint32_t t = k_uptime_get_32();\
|
||||
while (t == k_uptime_get_32())\
|
||||
;\
|
||||
} while (0)
|
||||
K_SEM_DEFINE(sema, 0, NUM_THREAD);
|
||||
static int64_t elapsed_slice;
|
||||
|
||||
static void thread_tslice(void *p1, void *p2, void *p3)
|
||||
{
|
||||
int64_t t = k_uptime_delta(&elapsed_slice);
|
||||
|
||||
TC_PRINT("elapsed slice %lld\n", t);
|
||||
/**TESTPOINT: verify slicing scheduler behaves as expected*/
|
||||
zassert_true(t >= SLICE_SIZE, NULL);
|
||||
/*less than one tick delay*/
|
||||
zassert_true(t <= (SLICE_SIZE + MSEC_PER_TICK), NULL);
|
||||
|
||||
uint32_t t32 = k_uptime_get_32();
|
||||
|
||||
/*keep the current thread busy for more than one slice*/
|
||||
while (k_uptime_get_32() - t32 < SLEEP_TICKLESS)
|
||||
;
|
||||
k_sem_give(&sema);
|
||||
}
|
||||
|
||||
/*test cases*/
|
||||
void test_tickless_sysclock(void)
|
||||
{
|
||||
volatile uint32_t t0, t1;
|
||||
|
||||
ALIGN_MS_BOUNDARY();
|
||||
t0 = k_uptime_get_32();
|
||||
k_sleep(SLEEP_TICKLESS);
|
||||
t1 = k_uptime_get_32();
|
||||
TC_PRINT("time %d, %d\n", t0, t1);
|
||||
/**TESTPOINT: verify system clock recovery after exiting tickless idle*/
|
||||
zassert_true((t1 - t0) >= SLEEP_TICKLESS, NULL);
|
||||
|
||||
ALIGN_MS_BOUNDARY();
|
||||
t0 = k_uptime_get_32();
|
||||
k_sem_take(&sema, SLEEP_TICKFUL);
|
||||
t1 = k_uptime_get_32();
|
||||
TC_PRINT("time %d, %d\n", t0, t1);
|
||||
/**TESTPOINT: verify system clock recovery after exiting tickful idle*/
|
||||
zassert_true((t1 - t0) >= SLEEP_TICKFUL, NULL);
|
||||
}
|
||||
|
||||
void test_tickless_slice(void)
|
||||
{
|
||||
k_tid_t tid[NUM_THREAD];
|
||||
|
||||
k_sem_reset(&sema);
|
||||
/*enable time slice*/
|
||||
k_sched_time_slice_set(SLICE_SIZE, K_PRIO_PREEMPT(0));
|
||||
|
||||
/*create delayed threads with equal preemptive priority*/
|
||||
for (int i = 0; i < NUM_THREAD; i++) {
|
||||
tid[i] = k_thread_spawn(tstack[i], STACK_SIZE,
|
||||
thread_tslice, NULL, NULL, NULL,
|
||||
K_PRIO_PREEMPT(0), 0, SLICE_SIZE);
|
||||
}
|
||||
k_uptime_delta(&elapsed_slice);
|
||||
/*relinquish CPU and wait for each thread to complete*/
|
||||
for (int i = 0; i < NUM_THREAD; i++) {
|
||||
k_sem_take(&sema, K_FOREVER);
|
||||
}
|
||||
|
||||
/*test case teardown*/
|
||||
for (int i = 0; i < NUM_THREAD; i++) {
|
||||
k_thread_abort(tid[i]);
|
||||
}
|
||||
/*disable time slice*/
|
||||
k_sched_time_slice_set(0, K_PRIO_PREEMPT(0));
|
||||
}
|
3
tests/kernel/tickless/tickless_concept/testcase.ini
Normal file
3
tests/kernel/tickless/tickless_concept/testcase.ini
Normal file
|
@ -0,0 +1,3 @@
|
|||
[test]
|
||||
tags = kernel
|
||||
arch_exclude = riscv32 nios2
|
Loading…
Reference in a new issue