-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: ztest: Add test for busy simulator
Added test that validates busy simulator. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
- Loading branch information
1 parent
395cfa5
commit 3a5a77f
Showing
7 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.13.1) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(uart_basic_api) | ||
|
||
target_sources(app PRIVATE | ||
src/main.c | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_COUNTER_TIMER0=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2021 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&timer0 { | ||
status = "okay"; | ||
interrupts = <8 0>; | ||
}; | ||
|
||
/ { | ||
busy-sim { | ||
compatible = "vnd,busy-sim"; | ||
status = "okay"; | ||
counter = <&timer0>; | ||
}; | ||
}; |
19 changes: 19 additions & 0 deletions
19
tests/ztest/busy_sim/boards/nrf52840dk_nrf52840_pin.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2021 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&timer0 { | ||
status = "okay"; | ||
interrupts = <8 0>; | ||
}; | ||
|
||
/ { | ||
busy-sim { | ||
compatible = "vnd,busy-sim"; | ||
status = "okay"; | ||
counter = <&timer0>; | ||
active-gpios = <&gpio0 27 GPIO_ACTIVE_HIGH>; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CONFIG_ZTEST=y | ||
CONFIG_TEST_BUSY_SIM=y | ||
CONFIG_ZTEST_THREAD_PRIORITY=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2021 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <ztest.h> | ||
#include <busy_sim.h> | ||
|
||
static void test_busy_sim(void) | ||
{ | ||
uint32_t ms = 1000; | ||
uint32_t delta = 80; | ||
uint32_t busy_ms; | ||
uint32_t t = k_uptime_get_32(); | ||
|
||
k_busy_wait(1000 * ms); | ||
t = k_uptime_get_32() - t; | ||
|
||
zassert_true((t > (ms - delta)) && (t < (ms + delta)), NULL); | ||
|
||
/* Start busy simulator and check that k_busy_wait last longer */ | ||
t = k_uptime_get_32(); | ||
busy_sim_start(500, 200, 1000, 400); | ||
k_busy_wait(1000 * ms); | ||
t = k_uptime_get_32() - t; | ||
busy_ms = (3 * ms) / 2; | ||
|
||
busy_sim_stop(); | ||
/* due to clock imprecision, randomness and addtional cpu load overhead | ||
* expected time range is increased. | ||
*/ | ||
zassert_true((t > (busy_ms - 2 * delta)) && (t < (busy_ms + 4 * delta)), | ||
"expected in range: %d-%d, k_busy_wait lasted %d", | ||
busy_ms - 2 * delta, busy_ms + 4 * delta, t); | ||
|
||
/* Check that k_busy_wait is not interrupted after busy_sim_stop. */ | ||
t = k_uptime_get_32(); | ||
k_busy_wait(1000 * ms); | ||
t = k_uptime_get_32() - t; | ||
zassert_true((t > (ms - delta)) && (t < (ms + delta)), NULL); | ||
} | ||
|
||
void test_main(void) | ||
{ | ||
ztest_test_suite(busy_sim_tests, | ||
ztest_unit_test(test_busy_sim) | ||
); | ||
|
||
ztest_run_test_suite(busy_sim_tests); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
common: | ||
tags: test_framework | ||
depends_on: counter | ||
tests: | ||
testing.ztest.busy_sim: | ||
platform_allow: nrf52840dk_nrf52840 | ||
testing.ztest.busy_sim_nrf52840dk_pin: | ||
platform_allow: nrf52840dk_nrf52840 | ||
extra_args: DTC_OVERLAY_FILE=boards/nrf52840dk_nrf52840_pin.overlay |