Skip to content

Commit ef49f03

Browse files
nashifcarlescufi
authored andcommitted
doc: overhaul sample criteria and expectations
overhaul sample criteria and what we expect in a sample, especially overhaul the twister part and what should be provided for good test coverage. Signed-off-by: Anas Nashif <[email protected]>
1 parent 4f5f4c0 commit ef49f03

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

samples/sample_definition_and_criteria.rst

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ more features, subsystems, or modules. This includes kernel services, drivers, p
1111
Samples should be limited in scope and should focus only on demonstrating non-trivial or
1212
essential aspects of the subsystem(s) or module(s) being highlighted.
1313

14+
Samples are recommended when submitting new features; however, they are not mandatory.
15+
1416
Sample Criteria
1517
===============
1618

17-
1. Samples must not be used as a testcase.
18-
++++++++++++++++++++++++++++++++++++++++++
19+
1. Samples must not be used to test features or verify platforms
20+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1921
* The primary purpose of a sample is to provide a reference to the user.
2022
* Samples must not use Zephyr's testing framework.
2123

@@ -25,7 +27,13 @@ Sample Criteria
2527
* If a sample can provide output that can be verified, then output should be evaluated against
2628
expected value to have some level of testing for the sample itself.
2729
Refer to :ref:`twister_script` for more details.
28-
* Samples are optional.
30+
31+
* Although being able to run a sample successfully does verify the
32+
functionality is working as expected, this should not replace dedicated and
33+
comprehensive tests with full coverage to be submitted into the
34+
:zephyr_file:`tests/` folder. In a sample, the only thing you test is
35+
buildability and, in some cases, if a sample is performing as expected, i.e. you
36+
are testing the sample, not the subsystem it builds on top.
2937

3038
2. Twister should be able to build every sample.
3139
++++++++++++++++++++++++++++++++++++++++++++++++
@@ -39,36 +47,42 @@ Sample Criteria
3947
sample.kernel.cond_var:
4048
integration_platforms:
4149
- native_sim
42-
tags: kernel condition_variables
50+
tags:
51+
- kernel
52+
- condition_variables
4353
harness: console
4454
harness_config:
4555
type: one_line
4656
regex:
4757
- ".*Waited and joined with 3 threads"
4858
49-
**Guidelines for Samples:**
50-
* Minimize the use of ``platform_allow`` and architecture filters.
51-
* Do not mark the test as build only unless necessary.
52-
* Any test case-specific configuration options are added using ``extra_args`` or
53-
``extra_configs`` options in the YAML file. The `prj.conf` file should have the in-common
54-
configuration options.
55-
* The sample itself can be evaluated using multiple configurations in the sample's YAML file.
56-
For example, the sample is used to run with different logging modes using multiple scenarios
57-
in ``samples/subsys/logging/syst``.
58-
* Sample output can be validated leveraging the ``harness_config`` regex option,
59-
wherever applicable.
60-
61-
3. Samples should target multiple platforms and architectures.
62-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
63-
* Minimize the use of ``platform_allow`` and architecture filters as it limits the scope
64-
of testing to the mentioned platforms and architectures.
65-
Reference: :ref:`twister_script`
59+
* Do not mark the test as build only. A sample should be able to build *and*
60+
run on the documented platforms. Use the ``harness`` option to skip the
61+
execution. Twister only attempts to flash and execute the build binary if
62+
the harness is set to ``ztest`` or ``console``.
63+
* The default configuration for the sample must be in the :file:`prj.conf`
64+
file and should be operational on all supported platforms. Do not rely on the
65+
``extra_args`` or ``extra_configs`` options in the YAML file to build the
66+
sample.
67+
* The tests should verify the default configuration of the sample and any
68+
optional features documented in the sample's README file. Sample should
69+
never be used to test functionality of the subsystem or module the sample
70+
belongs to.
71+
* Any documented configuration options related to the sample and its
72+
operation can be verified using ``extra_args`` or
73+
``extra_configs`` options in the YAML file. The :file:`prj.conf` file should have the
74+
base configuration options.
75+
* Sample output can be validated by leveraging the ``harness_config`` regex option,
76+
wherever applicable.
77+
* Use ``platform_allow`` to limit test to the platforms the sample was actually
78+
verified on. Those platforms should be listed in the sample's README file.
6679
* Make use of ``integration_platforms`` to limit the scope when there are timing or
67-
resource constraints.
80+
resource constraints. Ideally, one platform should be enough to verify the
81+
sample when changes are submitted to the Zephyr tree via a pull-request.
6882
* Make the sample as generic as possible. Avoid making a sample platform specific unless it is
6983
for particular hardware.
7084

71-
4. A sample should provide sufficient coverage of a subsystem, feature, or module.
85+
3. A sample should provide sufficient coverage of a subsystem, feature, or module.
7286
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7387
**DO's:**
7488
* Cover the most common and important use cases of the functionality.
@@ -78,17 +92,17 @@ Sample Criteria
7892
* Samples must not test the negative or edge case behaviors.
7993
* Must not be unit tests.
8094

81-
5. Samples must be documented.
95+
4. Samples must be documented.
8296
++++++++++++++++++++++++++++++
8397
* Samples must have a ``README.rst`` file in the samples folder.
8498
Example: ``samples/subsys/foo/README.rst``. clearly explaining the purpose of the sample, its
85-
HW requirements, and the expected sample output, if applicable.
99+
hardware requirements, and the expected sample output, if applicable.
86100
* Ensure that the ``README.rst`` file is accessible in the sample hierarchy starting at
87101
``samples/index.rst``.
88102

89103
**README Template:**
90104
* Overview, if applicable.
91-
* SW/HW requirements
105+
* Software/Hardware requirements
92106
* Building & Running instructions
93107
* Sample output, if applicable.
94108

0 commit comments

Comments
 (0)