forked from openthread/openthread
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] introduce Nexus test framework and platform (openthread#10533)
This commit introduces a new test framework named Nexus. The framework includes the Nexus platform implementation that emulates platform behavior, allowing multiple nodes running the OpenThread core stack to be simulated and interact with each other within the same process. Unlike the simulation platform, where nodes run in separate processes and interact via POSIX sockets, Nexus nodes are simulated within a single process. Nexus tests can interact directly with the C++ or C OT core APIs, providing more control than the simulation platform's CLI-based interactions. The flow of time in Nexus tests is directly controlled by the test itself, allowing for quick time interval advancement. This model allows for faster and more scalable simulations, enabling quick simulation of larger networks for longer durations. This commit introduces the basic platform implementation, including: - `nexus_alarm`, `nexus_radio`, and `nexus_settings` modules. - Logging support, allowing logs to be distinguished per emulated node.
- Loading branch information
Showing
23 changed files
with
2,152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# | ||
# Copyright (c) 2024, The OpenThread Authors. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# 3. Neither the name of the copyright holder nor the | ||
# names of its contributors may be used to endorse or promote products | ||
# derived from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
|
||
set(COMMON_INCLUDES | ||
${PROJECT_SOURCE_DIR}/include | ||
${PROJECT_SOURCE_DIR}/src | ||
${PROJECT_SOURCE_DIR}/src/core | ||
${PROJECT_SOURCE_DIR}/tests/nexus/platform | ||
) | ||
|
||
set(COMMON_COMPILE_OPTIONS | ||
-DOPENTHREAD_FTD=1 | ||
-DOPENTHREAD_MTD=0 | ||
-DOPENTHREAD_RADIO=0 | ||
) | ||
|
||
add_library(ot-nexus-platform | ||
platform/nexus_alarm.cpp | ||
platform/nexus_core.cpp | ||
platform/nexus_misc.cpp | ||
platform/nexus_node.cpp | ||
platform/nexus_radio.cpp | ||
platform/nexus_settings.cpp | ||
) | ||
|
||
target_include_directories(ot-nexus-platform | ||
PRIVATE | ||
${COMMON_INCLUDES} | ||
) | ||
|
||
target_compile_options(ot-nexus-platform | ||
PRIVATE | ||
${COMMON_COMPILE_OPTIONS} | ||
) | ||
|
||
target_link_libraries(ot-nexus-platform | ||
PRIVATE | ||
ot-config | ||
${OT_MBEDTLS} | ||
) | ||
|
||
set(COMMON_LIBS | ||
ot-nexus-platform | ||
openthread-ftd | ||
ot-nexus-platform | ||
${OT_MBEDTLS} | ||
ot-config | ||
openthread-ftd | ||
) | ||
|
||
#---------------------------------------------------------------------------------------------------------------------- | ||
|
||
macro(ot_nexus_test name) | ||
|
||
# Macro to add an OpenThread nexus test. | ||
# | ||
# Nexus test name will be `nexus_{name}`. Test source file of | ||
# `test_{name}.cpp` is used. Optional extra arguments can be | ||
# passed to provide additional source files. | ||
|
||
add_executable(nexus_${name} | ||
test_${name}.cpp ${ARGN} | ||
) | ||
|
||
target_include_directories(nexus_${name} | ||
PRIVATE | ||
${COMMON_INCLUDES} | ||
) | ||
|
||
target_link_libraries(nexus_${name} | ||
PRIVATE | ||
${COMMON_LIBS} | ||
) | ||
|
||
target_compile_options(nexus_${name} | ||
PRIVATE | ||
${COMMON_COMPILE_OPTIONS} | ||
) | ||
|
||
add_test(NAME nexus_${name} COMMAND nexus_${name}) | ||
endmacro() | ||
|
||
|
||
#---------------------------------------------------------------------------------------------------------------------- | ||
|
||
ot_nexus_test(form_join) | ||
ot_nexus_test(large_network) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Nexus test framework | ||
|
||
Nexus is a test framework for OpenThread testing. | ||
|
||
### Design Goals | ||
|
||
- **Faster and more scalable network simulation**: Enable faster and more efficient simulations of OpenThread networks involving a large number of nodes over extended durations. | ||
- **Enhanced control**: Achieve greater control and scalability over simulated tests. | ||
|
||
### Features | ||
|
||
- Includes the Nexus platform implementation that emulates platform behavior, allowing multiple nodes running the OpenThread core stack to be simulated and interact with each other within the same process. | ||
- Unlike the simulation platform (under `examples/platforms/simulation`), where nodes run in separate processes and interact via POSIX sockets, Nexus nodes are simulated within a single process. | ||
- Nexus tests can interact directly with the C++ or C OT core APIs, providing more control than the simulation platform's CLI-based interactions. | ||
- The flow of time in Nexus tests is directly controlled by the test itself, allowing for quick time interval advancement. | ||
|
||
### How to build and run tests | ||
|
||
To build Nexus test cases, the `build.sh` script can be used: | ||
|
||
```bash | ||
./tests/nexus/build.sh | ||
``` | ||
|
||
Afterwards, each test can be run directly: | ||
|
||
```bash | ||
./tests/nexus/nexus_form_join | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2024, The OpenThread Authors. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# 3. Neither the name of the copyright holder nor the | ||
# names of its contributors may be used to endorse or promote products | ||
# derived from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
|
||
display_usage() | ||
{ | ||
echo "" | ||
echo "Nexus build script " | ||
echo "" | ||
echo "" | ||
} | ||
|
||
die() | ||
{ | ||
echo " *** ERROR: " "$*" | ||
exit 1 | ||
} | ||
|
||
cd "$(dirname "$0")" || die "cd failed" | ||
cd ../.. || die "cd failed" | ||
|
||
if [ -n "${top_builddir}" ]; then | ||
top_srcdir=$(pwd) | ||
mkdir -p "${top_builddir}" | ||
else | ||
top_srcdir=. | ||
top_builddir=. | ||
fi | ||
|
||
echo "====================================================================================================" | ||
echo "Building OpenThread Nexus test platform" | ||
echo "====================================================================================================" | ||
cd "${top_builddir}" || die "cd failed" | ||
cmake -GNinja -DOT_PLATFORM=nexus -DOT_COMPILE_WARNING_AS_ERROR=ON \ | ||
-DOT_MULTIPLE_INSTANCE=ON \ | ||
-DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=OFF -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \ | ||
-DOT_PROJECT_CONFIG=../tests/nexus/openthread-core-nexus-config.h \ | ||
"${top_srcdir}" || die | ||
ninja || die | ||
|
||
exit 0 |
Oops, something went wrong.