2022-07-19 05:25:39 +08:00
|
|
|
.. _definition_and_criteria:
|
|
|
|
|
|
|
|
Sample Definition and Criteria
|
|
|
|
##############################
|
|
|
|
|
|
|
|
Definition
|
|
|
|
==========
|
|
|
|
|
|
|
|
A sample is a concise Zephyr application that provides an accessible overview of one or
|
|
|
|
more features, subsystems, or modules. This includes kernel services, drivers, protocols, etc.
|
|
|
|
Samples should be limited in scope and should focus only on demonstrating non-trivial or
|
|
|
|
essential aspects of the subsystem(s) or module(s) being highlighted.
|
|
|
|
|
2024-09-05 07:33:00 +08:00
|
|
|
Samples are recommended when submitting new features; however, they are not mandatory.
|
|
|
|
|
2022-07-19 05:25:39 +08:00
|
|
|
Sample Criteria
|
|
|
|
===============
|
|
|
|
|
2024-09-05 07:33:00 +08:00
|
|
|
1. Samples must not be used to test features or verify platforms
|
|
|
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
2022-07-19 05:25:39 +08:00
|
|
|
* The primary purpose of a sample is to provide a reference to the user.
|
|
|
|
* Samples must not use Zephyr's testing framework.
|
|
|
|
|
2023-10-10 08:24:43 +08:00
|
|
|
* Must not use :kconfig:option:`CONFIG_ZTEST`
|
2022-07-19 05:25:39 +08:00
|
|
|
* Must not use zasserts in samples.
|
|
|
|
|
|
|
|
* If a sample can provide output that can be verified, then output should be evaluated against
|
|
|
|
expected value to have some level of testing for the sample itself.
|
2023-08-07 00:19:26 +08:00
|
|
|
Refer to :ref:`twister_script` for more details.
|
2024-09-05 07:33:00 +08:00
|
|
|
|
|
|
|
* Although being able to run a sample successfully does verify the
|
|
|
|
functionality is working as expected, this should not replace dedicated and
|
|
|
|
comprehensive tests with full coverage to be submitted into the
|
|
|
|
:zephyr_file:`tests/` folder. In a sample, the only thing you test is
|
|
|
|
buildability and, in some cases, if a sample is performing as expected, i.e. you
|
|
|
|
are testing the sample, not the subsystem it builds on top.
|
2022-07-19 05:25:39 +08:00
|
|
|
|
|
|
|
2. Twister should be able to build every sample.
|
|
|
|
++++++++++++++++++++++++++++++++++++++++++++++++
|
2023-08-07 00:19:26 +08:00
|
|
|
* Every sample must have a YAML file. Reference: :ref:`twister_script`.
|
2022-07-19 05:25:39 +08:00
|
|
|
|
|
|
|
**For example:**
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
tests:
|
|
|
|
sample.kernel.cond_var:
|
|
|
|
integration_platforms:
|
2023-11-16 16:43:51 +08:00
|
|
|
- native_sim
|
2024-09-05 07:33:00 +08:00
|
|
|
tags:
|
|
|
|
- kernel
|
|
|
|
- condition_variables
|
2022-07-19 05:25:39 +08:00
|
|
|
harness: console
|
|
|
|
harness_config:
|
|
|
|
type: one_line
|
|
|
|
regex:
|
|
|
|
- ".*Waited and joined with 3 threads"
|
|
|
|
|
2024-09-05 07:33:00 +08:00
|
|
|
* Do not mark the test as build only. A sample should be able to build *and*
|
|
|
|
run on the documented platforms. Use the ``harness`` option to skip the
|
|
|
|
execution. Twister only attempts to flash and execute the build binary if
|
|
|
|
the harness is set to ``ztest`` or ``console``.
|
|
|
|
* The default configuration for the sample must be in the :file:`prj.conf`
|
|
|
|
file and should be operational on all supported platforms. Do not rely on the
|
|
|
|
``extra_args`` or ``extra_configs`` options in the YAML file to build the
|
|
|
|
sample.
|
|
|
|
* The tests should verify the default configuration of the sample and any
|
|
|
|
optional features documented in the sample's README file. Sample should
|
|
|
|
never be used to test functionality of the subsystem or module the sample
|
|
|
|
belongs to.
|
|
|
|
* Any documented configuration options related to the sample and its
|
|
|
|
operation can be verified using ``extra_args`` or
|
|
|
|
``extra_configs`` options in the YAML file. The :file:`prj.conf` file should have the
|
|
|
|
base configuration options.
|
|
|
|
* Sample output can be validated by leveraging the ``harness_config`` regex option,
|
|
|
|
wherever applicable.
|
|
|
|
* Use ``platform_allow`` to limit test to the platforms the sample was actually
|
|
|
|
verified on. Those platforms should be listed in the sample's README file.
|
2022-07-19 05:25:39 +08:00
|
|
|
* Make use of ``integration_platforms`` to limit the scope when there are timing or
|
2024-09-05 07:33:00 +08:00
|
|
|
resource constraints. Ideally, one platform should be enough to verify the
|
|
|
|
sample when changes are submitted to the Zephyr tree via a pull-request.
|
2022-07-19 05:25:39 +08:00
|
|
|
* Make the sample as generic as possible. Avoid making a sample platform specific unless it is
|
|
|
|
for particular hardware.
|
|
|
|
|
2024-09-05 07:33:00 +08:00
|
|
|
3. A sample should provide sufficient coverage of a subsystem, feature, or module.
|
2022-07-19 05:25:39 +08:00
|
|
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
**DO's:**
|
|
|
|
* Cover the most common and important use cases of the functionality.
|
|
|
|
* Keep the code simple and easy to read. Example: :zephyr_file:`samples/philosophers`.
|
|
|
|
|
|
|
|
**DONT's:**
|
|
|
|
* Samples must not test the negative or edge case behaviors.
|
|
|
|
* Must not be unit tests.
|
|
|
|
|
2024-09-05 07:33:00 +08:00
|
|
|
4. Samples must be documented.
|
2022-07-19 05:25:39 +08:00
|
|
|
++++++++++++++++++++++++++++++
|
|
|
|
* Samples must have a ``README.rst`` file in the samples folder.
|
|
|
|
Example: ``samples/subsys/foo/README.rst``. clearly explaining the purpose of the sample, its
|
2024-09-05 07:33:00 +08:00
|
|
|
hardware requirements, and the expected sample output, if applicable.
|
2022-07-19 05:25:39 +08:00
|
|
|
* Ensure that the ``README.rst`` file is accessible in the sample hierarchy starting at
|
|
|
|
``samples/index.rst``.
|
|
|
|
|
|
|
|
**README Template:**
|
|
|
|
* Overview, if applicable.
|
2024-09-05 07:33:00 +08:00
|
|
|
* Software/Hardware requirements
|
2022-07-19 05:25:39 +08:00
|
|
|
* Building & Running instructions
|
|
|
|
* Sample output, if applicable.
|
|
|
|
|
|
|
|
|
|
|
|
As a starting point, this sample is a good example to refer to
|
|
|
|
:zephyr_file:`samples/kernel/condition_variables/condvar`.
|