Files
openthread/tests/unit
Jonathan Hui 0841be04fd [posix] detect and fail on unused radio URL parameters (#13087)
This commit enhances the radio URL parsing logic to detect and fail
when unused parameters are provided in the URL. This prevents typos
or unsupported parameters from being silently ignored.

The following changes were made:

- Updated ot::Url::Url to track parameter usage by appending a
  trailing '&' delimiter in Init() and replacing it with '\0'
  in GetValue() when a parameter is matched. This marks the
  parameter as used and removes any limit on the number of
  trackable parameters.
- Added a Validate() method to ot::Url::Url to verify that all
  parameters in the query string were accessed.
- Refactored ot::Posix::Radio to share a single RadioUrl instance
  with SpinelManager, ensuring all components track usage on the
  same URL object.
- Integrated Validate() calls in otSysInit() and platformTrelInit()
  to perform validation after all platform components have been
  initialized.
- Updated Radio::ProcessMaxPowerTable to use a local copy of the
  parameter string to avoid premature modification of the URL buffer.
- Adjusted RadioUrl and unit tests to provide sufficient buffer
  space for the additional tracking delimiter.
- Added new unit tests in tests/unit/test_url.cpp to verify the
  usage tracking and validation logic.
2026-05-09 10:04:07 -07:00
..
2026-04-14 08:44:27 -07:00

OpenThread Unit Tests

This page describes how to build and run OpenThread unit tests. It will be helpful for developers to debug failed unit test cases if they got one in CI or to add some new test cases.

Build Simulation

The unit tests cannot be built solely without building the whole project. So first build OpenThread on the simulation platform, which will also build all unit tests:

# Go to the root directory of OpenThread
$ script/cmake-build simulation

List all tests

To see what tests are available in OpenThread:

# Make sure you are at the simulation build directory (build/simulation)
$ ctest -N

Run the Unit Tests

To run all the unit tests:

# Make sure you are at the simulation build directory (build/simulation)
$ ctest

To run a specific unit test, for example, ot-test-spinel:

# Make sure you are at the simulation build directory (build/simulation)
$ ctest -R ot-test-spinel

Update a Test Case

If you are developing a unit test case and have made some changes in the test source file, you will need rebuild the test before running it:

# Make sure you are at the simulation build directory (build/simulation)
$ ninja <test_name>

This will only build the test and take a short time.

If any changes or fixes were made to the OpenThread code, then you'll need to rebuild the entire project:

# Make sure you are at the simulation build directory (build/simulation)
$ ninja

This will build the updated OpenThread code as well as the test cases.