Skip to content

Commit bff98e0

Browse files
[ncp] use ot-ctl CLI for NCP join/leave test (#2821)
This commit introduces a new expect test script, `ncp_cli_join_leave.exp`, designed to verify the functionality of joining and leaving using the `ot-ctl` CLI under NCP mode.
1 parent 2bdf12e commit bff98e0

3 files changed

Lines changed: 88 additions & 1 deletion

File tree

tests/scripts/expect/_common.exp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ proc spawn_node {id type sim_app} {
8888
spawn $sim_app
8989
expect ">"
9090
}
91+
ctl {
92+
spawn $sim_app
93+
send "factoryreset\n"
94+
wait_for "state" "disabled"
95+
expect "Done"
96+
97+
expect_after {
98+
timeout { fail "Timed out" }
99+
}
100+
}
91101
otbr-docker {
92102
spawn docker exec -it $sim_app bash
93103
expect "app#"
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/expect -f
2+
#
3+
# Copyright (c) 2025, The OpenThread Authors.
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
# 1. Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# 2. Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# 3. Neither the name of the copyright holder nor the
14+
# names of its contributors may be used to endorse or promote products
15+
# derived from this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
30+
source "tests/scripts/expect/_common.exp"
31+
32+
set dataset "0e080000000000010000000300001435060004001fffe002087d61eb42cdc48d6a0708fd0d07fca1b9f0500510ba088fc2bd6c3b3897f7a10f58263ff3030f4f70656e5468726561642d353234660102524f04109dc023ccd447b12b50997ef68020f19e0c0402a0f7f8"
33+
34+
# Step 1. Start a Thread node and create a Thread network
35+
spawn_node 1 cli $::env(EXP_OT_CLI_PATH)
36+
37+
send "dataset set active ${dataset}\n"
38+
expect_line "Done"
39+
send "ifconfig up\n"
40+
expect_line "Done"
41+
send "thread start\n"
42+
expect_line "Done"
43+
wait_for "state" "leader"
44+
expect_line "Done"
45+
46+
47+
# Step 2. Start otbr-agent with a NCP
48+
spawn_node 2 otbr $::env(EXP_OT_NCP_PATH)
49+
sleep 1
50+
51+
# Step 3. Start ot-ctl and join the network
52+
spawn_node 3 ctl $::env(EXP_OT_CTL_PATH)
53+
54+
send "dataset set active ${dataset}\n"
55+
expect "Done"
56+
send "ifconfig up\n"
57+
expect "Done"
58+
send "thread start\n"
59+
expect "Done"
60+
wait_for "state" "router|child"
61+
expect "Done"
62+
63+
# Step 4. Leave the network
64+
send "thread stop\n"
65+
expect "Done"
66+
send "ifconfig down\n"
67+
expect "Done"
68+
69+
# Step 5. Verify the state of otbr-agent is 'disabled'
70+
wait_for "state" "disabled"
71+
expect "Done"

tests/scripts/ncp_mode

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ readonly ABS_TOP_OT_SRCDIR
6161
ABS_TOP_OT_BUILDDIR="${ABS_TOP_BUILDDIR}/../simulation"
6262
readonly ABS_TOP_BUILDDIR
6363

64+
OT_CTL="${ABS_TOP_BUILDDIR}/third_party/openthread/repo/src/posix/ot-ctl"
65+
readonly OT_CTL
66+
6467
OTBR_COLOR_PASS='\033[0;32m'
6568
readonly OTBR_COLOR_PASS
6669

@@ -141,7 +144,7 @@ do_build_ot_simulation()
141144
-DOT_MTD=OFF -DOT_RCP=OFF -DOT_APP_CLI=OFF -DOT_APP_RCP=OFF \
142145
-DOT_BORDER_ROUTING=ON -DOT_NCP_INFRA_IF=ON -DOT_SIMULATION_INFRA_IF=OFF \
143146
-DOT_SRP_SERVER=ON -DOT_SRP_ADV_PROXY=ON -DOT_PLATFORM_DNSSD=ON -DOT_SIMULATION_DNSSD=OFF -DOT_NCP_DNSSD=ON \
144-
-DOT_BORDER_AGENT=ON \
147+
-DOT_BORDER_AGENT=ON -DOT_NCP_CLI_STREAM=ON \
145148
-DBUILD_TESTING=OFF
146149
OT_CMAKE_BUILD_DIR=${ABS_TOP_OT_BUILDDIR}/cli "${ABS_TOP_OT_SRCDIR}"/script/cmake-build simulation \
147150
-DOT_MTD=OFF -DOT_RCP=OFF -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \
@@ -203,6 +206,7 @@ setup_infraif()
203206
test_setup()
204207
{
205208
executable_or_die "${OTBR_AGENT_PATH}"
209+
executable_or_die "${OT_CTL}"
206210

207211
# Remove flashes
208212
sudo rm -vrf "${TEST_BASE}/tmp"
@@ -215,6 +219,7 @@ test_setup()
215219
executable_or_die "${ot_ncp}"
216220

217221
export EXP_OTBR_AGENT_PATH="${OTBR_AGENT_PATH}"
222+
export EXP_OT_CTL_PATH="${OT_CTL}"
218223
export EXP_OT_CLI_PATH="${ot_cli}"
219224
export EXP_OT_NCP_PATH="${ot_ncp}"
220225

@@ -246,6 +251,7 @@ test_teardown()
246251
write_syslog "EXIT ${EXIT_CODE} - output logs"
247252

248253
sudo pkill -f "${OTBR_AGENT}" || true
254+
sudo pkill -f "${OT_CTL}" || true
249255
sudo pkill -f "${OT_CLI}" || true
250256
sudo pkill -f "${OT_NCP}" || true
251257
wait

0 commit comments

Comments
 (0)