Migrating the sysutil tests to new ztest API Signed-off-by: Spoorthy Priya Yerabolu <spoorthy.priya.yerabolu@intel.com>
53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
/*
|
|
* Copyright (c) 2022 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <zephyr/ztest.h>
|
|
#include <zephyr/sys/util.h>
|
|
#include <zephyr/kernel.h>
|
|
|
|
/**
|
|
* @addtogroup sys_util_tests
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief Test wait_for works as expected with typical use cases
|
|
*
|
|
* @see WAIT_FOR()
|
|
*/
|
|
|
|
ZTEST(sys_util, test_wait_for)
|
|
{
|
|
uint32_t start, end, expected;
|
|
|
|
zassert_true(WAIT_FOR(true, 0, NULL), "true, no wait, NULL");
|
|
zassert_true(WAIT_FOR(true, 0, k_yield()), "true, no wait, yield");
|
|
zassert_false(WAIT_FOR(false, 0, k_yield()), "false, no wait, yield");
|
|
zassert_true(WAIT_FOR(true, 1, k_yield()), "true, 1usec, yield");
|
|
zassert_false(WAIT_FOR(false, 1, k_yield()), "false, 1usec, yield");
|
|
zassert_true(WAIT_FOR(true, 1000, k_yield()), "true, 1msec, yield");
|
|
|
|
|
|
expected = 1000*(sys_clock_hw_cycles_per_sec()/USEC_PER_SEC);
|
|
start = k_cycle_get_32();
|
|
zassert_false(WAIT_FOR(false, 1000, k_yield()), "true, 1msec, yield");
|
|
end = k_cycle_get_32();
|
|
zassert_true(end-start >= expected, "wait for 1ms");
|
|
}
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
/**
|
|
* @defgroup sys_util_tests Sys Util Tests
|
|
* @ingroup all_tests
|
|
* @{
|
|
* @}
|
|
*/
|
|
|
|
ZTEST_SUITE(sys_util, NULL, NULL, NULL, NULL, NULL);
|