tests: kernel/sched: 32-bit tick wraparound during k_sleep() execution
This test reproduce the issue: https://github.com/zephyrproject-rtos/zephyr/issues/79863 In this test, instead of waiting the 32-bit tick wraparound for several days, patching the kernel internal tick with the test API. Signed-off-by: Akaiwa Wataru <akaiwa@sonas.co.jp>
This commit is contained in:
parent
feefb7dd35
commit
1bb5c34f98
4 changed files with 53 additions and 0 deletions
8
tests/kernel/sched/wraparound/CMakeLists.txt
Normal file
8
tests/kernel/sched/wraparound/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(sleep)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
1
tests/kernel/sched/wraparound/prj.conf
Normal file
1
tests/kernel/sched/wraparound/prj.conf
Normal file
|
@ -0,0 +1 @@
|
|||
CONFIG_ZTEST=y
|
41
tests/kernel/sched/wraparound/src/main.c
Normal file
41
tests/kernel/sched/wraparound/src/main.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Akaiwa Wataru <akaiwa@sonas.co.jp>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
static k_tid_t thread_id;
|
||||
|
||||
static void alarm_callback(struct k_timer *timer)
|
||||
{
|
||||
k_wakeup(thread_id);
|
||||
}
|
||||
|
||||
K_TIMER_DEFINE(alarm, alarm_callback, NULL);
|
||||
|
||||
/**
|
||||
* @brief Test 32-bit tick wraparound during k_sleep() execution
|
||||
*/
|
||||
ZTEST(wraparound, test_tick_wraparound_in_sleep)
|
||||
{
|
||||
static const uint32_t start_ticks = 0xffffff00; /* It wraps around after 256 ticks! */
|
||||
static const uint32_t timeout_ticks = 300; /* 3 seconds @ 100Hz tick */
|
||||
static const uint32_t wakeup_ticks = 10; /* 100 ms @ 100Hz tick */
|
||||
|
||||
sys_clock_tick_set(start_ticks);
|
||||
|
||||
/* Wake up myself by alarm */
|
||||
thread_id = k_current_get();
|
||||
k_timer_start(&alarm, K_TICKS(wakeup_ticks), K_FOREVER);
|
||||
|
||||
/* Waiting alarm's k_wakeup() call */
|
||||
int32_t left_ms = k_sleep(K_TICKS(timeout_ticks));
|
||||
|
||||
zassert(left_ms > 0, "k_sleep() timed out");
|
||||
|
||||
k_timer_stop(&alarm);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(wraparound, NULL, NULL, NULL, NULL, NULL);
|
3
tests/kernel/sched/wraparound/testcase.yaml
Normal file
3
tests/kernel/sched/wraparound/testcase.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
tests:
|
||||
kernel.scheduler.wraparound:
|
||||
tags: kernel
|
Loading…
Add table
Add a link
Reference in a new issue