Files
openthread/tests/unit
Abtin Keshavarzian 5c8c318627 [sub-mac] introduce unified ReceiveAt logic for timed RX (#13491)
This commit introduces a unified `ReceiveAt` abstraction in `SubMac` to
handle timed reception windows (CSL receiver, WED / Thread-Direct wakeup
listener)

Motivation & Benefits:

Previously, CSL sample window calculation and scheduling differed between
platform-offloaded timing (`OT_RADIO_CAPS_RECEIVE_TIMING`) and stack-driven
timing (`SubMac` software timers):
- `GetCslWindowEdges()` added `kCslReceiveTimeAhead` lead time to the window
  margin, only for offloaded callers to manually subtract it back out before
  calling `Radio::ReceiveAt()`.
- Stack-driven mode relied on separate timers for sample/sleep transitions
  (`HandleCslReceiveOrSleep`, `HandleWedReceiveOrSleep`), leading to code
  duplication and inconsistent timing margins across platform vs stack-driven
  executions.

This commit harmonizes timed reception handling:
- `GetCslWindowEdges()` cleanly computes target window bounds without caller-side
  adjustments.
- `SubMac::ReceiveAt()` provides a single, consistent API for both offloaded
  and stack-driven timing.
- Provides a clean foundation for Thread-Direct wakeup listening (WED) and
  future timed reception features.

Key changes:

- State Machine Refactoring: Simplifies the state management adding
  `kStateTimedReceive`. The radio state is `kStateTimedReceive` when
  actively receiving in a target rx window, and `kStateSleep` otherwise.
- `TimedRx` Helper Class: Encapsulates window parameters (`mStartTime`,
  `mDuration`, `mChannel`) and state checks (`HasStarted`, `HasEnded`).
- Pending & Active Window Preemption: `UpdateTimedRxState()` manages
  the timed RX schedules and sets the timer accordingly. It ensures
  pending windows starting before an active window ends are promoted
  seamlessly.
- Unit Test: Adds a detailed `test_sub_mac_recv_at.cpp` covering various
  behaviors (including edge-cases) of `ReceiveAt()` logic.
2026-08-31 14:27:24 -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.