tests: test the timepoint API
This tests sys_timepoint_calc(), sys_timepoint_timeout() and sys_timepoint_expired(). Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
52e2f83185
commit
3c9249cedc
5 changed files with 53 additions and 21 deletions
8
tests/kernel/timer/timepoints/CMakeLists.txt
Normal file
8
tests/kernel/timer/timepoints/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(timer_timepoints)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
2
tests/kernel/timer/timepoints/prj.conf
Normal file
2
tests/kernel/timer/timepoints/prj.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_NEW_API=y
|
38
tests/kernel/timer/timepoints/src/main.c
Normal file
38
tests/kernel/timer/timepoints/src/main.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2023 BayLibre SAS
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
ZTEST(timepoints, test_timepoint_api)
|
||||
{
|
||||
k_timepoint_t timepoint;
|
||||
k_timeout_t timeout, remaining;
|
||||
|
||||
timeout = K_NO_WAIT;
|
||||
timepoint = sys_timepoint_calc(timeout);
|
||||
zassert_true(sys_timepoint_expired(timepoint));
|
||||
remaining = sys_timepoint_timeout(timepoint);
|
||||
zassert_true(K_TIMEOUT_EQ(remaining, K_NO_WAIT));
|
||||
|
||||
timeout = K_FOREVER;
|
||||
timepoint = sys_timepoint_calc(timeout);
|
||||
zassert_false(sys_timepoint_expired(timepoint));
|
||||
remaining = sys_timepoint_timeout(timepoint);
|
||||
zassert_true(K_TIMEOUT_EQ(remaining, K_FOREVER));
|
||||
|
||||
timeout = K_SECONDS(1);
|
||||
timepoint = sys_timepoint_calc(timeout);
|
||||
zassert_false(sys_timepoint_expired(timepoint));
|
||||
remaining = sys_timepoint_timeout(timepoint);
|
||||
zassert_true(remaining.ticks <= timeout.ticks && remaining.ticks != 0);
|
||||
k_sleep(K_MSEC(1100));
|
||||
zassert_true(sys_timepoint_expired(timepoint));
|
||||
remaining = sys_timepoint_timeout(timepoint);
|
||||
zassert_true(K_TIMEOUT_EQ(remaining, K_NO_WAIT));
|
||||
}
|
||||
|
||||
ZTEST_SUITE(timepoints, NULL, NULL, NULL, NULL, NULL);
|
5
tests/kernel/timer/timepoints/testcase.yaml
Normal file
5
tests/kernel/timer/timepoints/testcase.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
tests:
|
||||
kernel.timer.timepoints:
|
||||
tags:
|
||||
- kernel
|
||||
- timer
|
|
@ -309,27 +309,6 @@ ZTEST_USER(timer_api_error, test_timer_add_timeout)
|
|||
ztest_test_pass();
|
||||
}
|
||||
|
||||
extern uint64_t sys_clock_timeout_end_calc(k_timeout_t timeout);
|
||||
extern void sys_clock_announce(int32_t ticks);
|
||||
|
||||
ZTEST(timer_api_error, test_timeout_end_calc)
|
||||
{
|
||||
int ret;
|
||||
k_timeout_t timeout;
|
||||
|
||||
timeout = K_MSEC(DURATION);
|
||||
ret = sys_clock_timeout_end_calc(timeout);
|
||||
zassert_true(ret, "---timeout end calc---");
|
||||
|
||||
timeout.ticks = TEST_TIMEOUT;
|
||||
ret = sys_clock_timeout_end_calc(timeout);
|
||||
zassert_true(ret, "timeout end calc error");
|
||||
|
||||
timeout = K_FOREVER;
|
||||
ret = sys_clock_timeout_end_calc(timeout);
|
||||
zassert_true(ret, "timeout end calc forever");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests for the Timer kernel object
|
||||
* @defgroup kernel_timer_tests Timer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue