Skip to content

Conversation

@majunkier
Copy link
Contributor

@majunkier majunkier commented Nov 13, 2024

The ztest harness could be enhanced to support repeatability options, allowing users to specify these options directly within the harness configuration. By defining scenarios that include harness_config, we will unify the testing environment, making it easier to debug or keep same test scope.

Currently, Zephyr supports test repetition via command-line arguments:

west twister -x=CONFIG_ZTEST_REPEAT=y -x=CONFIG_ZTEST_TEST_REPEAT_COUNT=<NUMBER> -x=CONFIG_ZTEST_SUITE_REPEAT_COUNT=<NUMBER>

However, this approach has the following drawbacks:

  • Lack of Standardization: Different users may specify different command-line options, leading to inconsistencies.

  • Manual Configuration Overhead: Users must remember and manually pass these options for every test execution.

  • Limited Automation Support: Running tests in CI/CD pipelines requires additional scripting to ensure consistent repetition settings.

By extending prj.conf, we allow users to define test repetition at the configuration level, ensuring that all builds include consistent test execution settings. This solution enables us to easily expand our testing scope, run stress tests, identify flaky tests, evaluate performance, and check for regressions.

Example of prj.conf :

CONFIG_ZTEST=y
CONFIG_ZTEST_SUITE_REPEAT_COUNT=3
CONFIG_ZTEST_TEST_REPEAT_COUNT=2

Users can also define test repetition in testcase.yaml:

tests:
  my.test.scenario:
    platform_allow: qemu_x86
    harness: console
    harness_config:
      ztest_suite_repeat: 2
      ztest_test_repeat: 1

@nashif
Copy link
Member

nashif commented Nov 19, 2024

You need to add an example/test of this being used and document this new behaviour.

@nashif
Copy link
Member

nashif commented Nov 26, 2024

still missing a test

@majunkier majunkier force-pushed the twister_repeat_harness branch 2 times, most recently from 07ff041 to 928ae6a Compare November 28, 2024 08:19
@nashif
Copy link
Member

nashif commented Nov 28, 2024

still missing a test

please add a test into tests/ztest that uses those keywords and shows how repitition is achieved and handled, a twister unit test is not enough.

@majunkier majunkier force-pushed the twister_repeat_harness branch 5 times, most recently from ba245c4 to 9905e7d Compare December 16, 2024 08:28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ztest_suite_repeat and ztest_test_repeat are configuration options of ztest harness, not console.
How is this going to work when used in other tests? does each ztest need to start parsing console and output?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the console harness to verify that this change works as expected. I have added test for ztest harness where number of repetitions per suite or test are configured in prj.conf.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From TestInstance implementation change it appears to me that suite_repeat, test_repeat, and test_shuffle are generic parameters, and ztest is going to be just one of possible implementations, but later the ztest_* properties (with different names to what is in the doc) were introduced for Harness (for any harness, actually), and I'm confused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@golowanow golowanow Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about suite_shuffle ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@majunkier majunkier force-pushed the twister_repeat_harness branch 2 times, most recently from 38462e9 to 2649451 Compare January 12, 2025 18:58
@majunkier majunkier force-pushed the twister_repeat_harness branch from 2649451 to 8cb5934 Compare February 3, 2025 11:50
@majunkier majunkier requested review from golowanow and nashif February 4, 2025 10:08
Copy link
Contributor

@yperess yperess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this different from adding this to the test yaml?

extra_configs:
  - CONFIG_ZTEST_REPEAT=y
  - CONFIG_ZTEST_REPEAT_COUNT=<NUMBER>
  - CONFIG_ZTEST_SUITE_REPEAT_COUNT=<NUMBER>

@majunkier
Copy link
Contributor Author

@nashif Could you share your perspective?

@majunkier majunkier force-pushed the twister_repeat_harness branch from 8cb5934 to 2138a50 Compare April 1, 2025 11:08
Extend Twister to allow defining repeat counts
for specific scenarios by harness_config.

Signed-off-by: Mateusz Junkier <mateusz.junkier@intel.com>
@majunkier majunkier force-pushed the twister_repeat_harness branch from 2138a50 to d1f3bd3 Compare April 2, 2025 07:19
@nashif
Copy link
Member

nashif commented Apr 23, 2025

How is this different from adding this to the test yaml?

extra_configs:
  - CONFIG_ZTEST_REPEAT=y
  - CONFIG_ZTEST_REPEAT_COUNT=<NUMBER>
  - CONFIG_ZTEST_SUITE_REPEAT_COUNT=<NUMBER>

it does have the same outcome with the main difference of seperating how you are testing from what is being tested, i.e. the extra_configs are used to add new scenarios using different config options of the test subject, the ZTEST config options are not what is being tested, it is how we execute the test, so they should be part of the harness configuration.

@majunkier majunkier requested a review from yperess April 28, 2025 07:39
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2024 Intel Corporation
* Copyright (c) 2025 Intel Corporation

Copy link
Contributor

@gbarkadiusz gbarkadiusz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kartben kartben merged commit 04b49fa into zephyrproject-rtos:main May 13, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants