Skip to content

Commit 9d9089e

Browse files
gbarkadiuszhenrikbrixandersen
authored andcommitted
ztest: Add Support for Multiple Test Runs.
Introduces new kconfig options to enable multiple test runs in the ztest. Signed-off-by: Arkadiusz Cholewinski <[email protected]>
1 parent 80bf9bf commit 9d9089e

File tree

9 files changed

+53
-19
lines changed

9 files changed

+53
-19
lines changed

doc/develop/test/ztest.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,15 @@ randomize the order. The output from the test will display the seed for failed
602602
tests. For native simulator builds you can provide the seed as an argument to
603603
twister with ``--seed``.
604604

605-
Static configuration of ZTEST_SHUFFLE contains:
606-
607-
- :kconfig:option:`CONFIG_ZTEST_SHUFFLE_SUITE_REPEAT_COUNT` - Number of iterations the test suite will run.
608-
- :kconfig:option:`CONFIG_ZTEST_SHUFFLE_TEST_REPEAT_COUNT` - Number of iterations the test will run.
609605

606+
Repeating Tests
607+
***********************
608+
By default the tests are executed once. The test cases and test suites
609+
may be executed multiple times. Enable :kconfig:option:`CONFIG_ZTEST_REPEAT` to
610+
execute the tests multiple times. By default the multiplication factors are 3, which
611+
means every test suite is executed 3 times and every test case is executed 3 times. This can
612+
be changed by the :kconfig:option:`CONFIG_ZTEST_SUITE_REPEAT_COUNT` and
613+
:kconfig:option:`CONFIG_ZTEST_TEST_REPEAT_COUNT` Kconfig options.
610614

611615
Test Selection
612616
**************

subsys/testsuite/ztest/Kconfig

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,41 @@ config ZTEST_SHUFFLE
150150

151151
if ZTEST_SHUFFLE
152152
config ZTEST_SHUFFLE_SUITE_REPEAT_COUNT
153-
int "Number of iterations the test suite will run"
153+
int "[DEPRECATED] Number of iterations the test suite will run"
154154
default 3
155155
help
156-
This rule will execute a test suite N number of times. The tests
157-
per suite will be shuffled on each iteration. The test order will likely
158-
be different per iteration.
156+
This is used to execute a test suite N number of times.
157+
[DEPRECATED] use ZTEST_SUITE_REPEAT_COUNT instead.
159158

160159
config ZTEST_SHUFFLE_TEST_REPEAT_COUNT
161-
int "Number of iterations the test will run"
160+
int "[DEPRECATED] Number of iterations the test will run"
162161
default 3
163162
help
164-
This rule will execute a test N number of times. The test order will
165-
likely be different per iteration.
163+
This is used to execute a test case N number of times.
164+
[DEPRECATED] use ZTEST_TEST_REPEAT_COUNT instead.
166165

167166
endif #ZTEST_SHUFFLE
168167

168+
config ZTEST_REPEAT
169+
bool "Repeat the tests and suites"
170+
help
171+
This rule will repeat the tests and the test suites.
172+
173+
if ZTEST_REPEAT
174+
config ZTEST_SUITE_REPEAT_COUNT
175+
int "Number of iterations the test suite will run"
176+
default 3
177+
help
178+
This rule will execute a test suite N number of times.
179+
180+
config ZTEST_TEST_REPEAT_COUNT
181+
int "Number of iterations the test will run"
182+
default 3
183+
help
184+
This rule will execute a test N number of times.
185+
186+
endif #ZTEST_REPEAT
187+
169188
config ZTEST_SUMMARY
170189
bool "Display test summary"
171190
default y

subsys/testsuite/ztest/src/ztest.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ static bool failed_expectation;
3030
#include <stdlib.h>
3131
#include <time.h>
3232
#include <zephyr/random/random.h>
33-
33+
#ifndef CONFIG_ZTEST_REPEAT
3434
#define NUM_ITER_PER_SUITE CONFIG_ZTEST_SHUFFLE_SUITE_REPEAT_COUNT
3535
#define NUM_ITER_PER_TEST CONFIG_ZTEST_SHUFFLE_TEST_REPEAT_COUNT
36+
#endif
37+
#endif /* CONFIG_ZTEST_SHUFFLE */
38+
39+
#ifdef CONFIG_ZTEST_REPEAT
40+
#define NUM_ITER_PER_SUITE CONFIG_ZTEST_SUITE_REPEAT_COUNT
41+
#define NUM_ITER_PER_TEST CONFIG_ZTEST_TEST_REPEAT_COUNT
3642
#else
3743
#define NUM_ITER_PER_SUITE 1
3844
#define NUM_ITER_PER_TEST 1

tests/net/lib/lwm2m/block_transfer/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CONFIG_TEST_RANDOM_GENERATOR=y
88
CONFIG_LWM2M_LOG_ENCODE_BUFFER_ALLOCATIONS=y
99

1010
CONFIG_ZTEST_SHUFFLE=y
11+
CONFIG_ZTEST_REPEAT=y
1112

1213
CONFIG_LWM2M=y
1314
CONFIG_LWM2M_COAP_BLOCK_TRANSFER=y

tests/subsys/ipc/pbuf/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_ZTEST=y
22
CONFIG_ZTRESS=y
33
CONFIG_ZTEST_SHUFFLE=y
4+
CONFIG_ZTEST_REPEAT=y
45

56
CONFIG_IPC_SERVICE=y
67
CONFIG_IPC_SERVICE_ICMSG=y

tests/subsys/modem/backends/uart/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ CONFIG_SERIAL=y
77
CONFIG_ZTEST=y
88
CONFIG_LOG=y
99
CONFIG_ZTEST_SHUFFLE=y
10-
CONFIG_ZTEST_SHUFFLE_TEST_REPEAT_COUNT=3
10+
CONFIG_ZTEST_REPEAT=y
11+
CONFIG_ZTEST_TEST_REPEAT_COUNT=3

tests/ztest/base/prj_verbose_0.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ CONFIG_TEST_RANDOM_GENERATOR=y
66
CONFIG_TIMER_RANDOM_GENERATOR=y
77

88
CONFIG_ZTEST_SHUFFLE=y
9-
CONFIG_ZTEST_SHUFFLE_SUITE_REPEAT_COUNT=2
10-
CONFIG_ZTEST_SHUFFLE_TEST_REPEAT_COUNT=2
9+
CONFIG_ZTEST_REPEAT=y
10+
CONFIG_ZTEST_SUITE_REPEAT_COUNT=2
11+
CONFIG_ZTEST_TEST_REPEAT_COUNT=2

tests/ztest/base/prj_verbose_1.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ CONFIG_ZTEST=y
22
CONFIG_ZTEST_ASSERT_VERBOSE=1
33

44
CONFIG_ZTEST_SHUFFLE=y
5-
CONFIG_ZTEST_SHUFFLE_SUITE_REPEAT_COUNT=2
6-
CONFIG_ZTEST_SHUFFLE_TEST_REPEAT_COUNT=2
5+
CONFIG_ZTEST_REPEAT=y
6+
CONFIG_ZTEST_SUITE_REPEAT_COUNT=2
7+
CONFIG_ZTEST_TEST_REPEAT_COUNT=2
78
CONFIG_ENTROPY_GENERATOR=y

tests/ztest/base/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ static void rule_test_teardown(void *data)
153153
* after_each function was called.
154154
*/
155155
zassert_equal(fixture->state, RULE_STATE_AFTER_EACH, "Unexpected state");
156-
#ifdef CONFIG_ZTEST_SHUFFLE
157-
zassert_equal(fixture->run_count, CONFIG_ZTEST_SHUFFLE_TEST_REPEAT_COUNT);
156+
#ifdef CONFIG_ZTEST_REPEAT
157+
zassert_equal(fixture->run_count, CONFIG_ZTEST_TEST_REPEAT_COUNT);
158158
#endif
159159
}
160160

0 commit comments

Comments
 (0)