-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces the test for testing the new functionality of ztest shell. Passing -r (repeat iter) parameter. This allows to run a particula testcase or testsuite several times. Passing -p (any value) parameter. This allows to provide a parameter to a test at runtime. Signed-off-by: Arkadiusz Cholewinski <[email protected]>
- Loading branch information
1 parent
74b3e10
commit 0356880
Showing
5 changed files
with
76 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,8 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(ztest_params) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
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_ZTEST_SHELL=y | ||
CONFIG_ZTEST_SHUFFLE=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,28 @@ | ||
# Copyright (c) 2024 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from twister_harness import Shell | ||
|
||
def test_run_all_shuffled(shell: Shell): | ||
shell.exec_command('ztest shuffle -c 1 -s 1') | ||
|
||
def test_run_testcase_once(shell: Shell): | ||
shell.exec_command('ztest run-testcase ztest_params::test_dummy') | ||
|
||
def test_run_testcase_twice(shell: Shell): | ||
shell.exec_command('ztest run-testcase ztest_params::test_dummy -r 2') | ||
|
||
def test_run_testsuite_twice(shell: Shell): | ||
shell.exec_command('ztest run-testsuite ztest_params -r 2') | ||
|
||
def test_run_testsuite_once(shell: Shell): | ||
shell.exec_command('ztest run-testsuite ztest_params') | ||
|
||
def test_run_testcase_with_int_parameter(shell: Shell): | ||
lines = shell.exec_command('ztest run-testcase ztest_params::test_int_param -p 44') | ||
assert 'Passed int value:44' in lines, 'expected response not found' | ||
|
||
def test_run_testcase_with_string_parameter(shell: Shell): | ||
lines = shell.exec_command('ztest run-testcase ztest_params::test_string_param -p Zephyr') | ||
assert 'Passed string:Zephyr' in lines, 'expected response not found' |
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,33 @@ | ||
/* | ||
* Copyright (c) 2024 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/ztest.h> | ||
#include <stdlib.h> | ||
|
||
ZTEST_SUITE(ztest_params, NULL, NULL, NULL, NULL, NULL); | ||
|
||
ZTEST(ztest_params, test_dummy) | ||
{ | ||
printf("Dummy test\n"); | ||
} | ||
|
||
ZTEST_P(ztest_params, test_int_param) | ||
{ | ||
if (data != NULL) { | ||
printf("Passed int value:%d\n", atoi(data)); | ||
} else { | ||
printf("Run without parameter"); | ||
} | ||
} | ||
|
||
ZTEST_P(ztest_params, test_string_param) | ||
{ | ||
if (data != NULL) { | ||
printf("Passed string:%s\n", (char *)data); | ||
} else { | ||
printf("Run without parameter"); | ||
} | ||
} |
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,4 @@ | ||
tests: | ||
testing.ztest.ztest_params.ztest_params: | ||
tags: test_framework | ||
harness: pytest |