Skip to content

Commit

Permalink
[tests] enhance ncp mode test script
Browse files Browse the repository at this point in the history
  • Loading branch information
Irving-cl committed Oct 25, 2024
1 parent 952fc6a commit 5a8db5b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 39 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ncp_mode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
BUILD_TARGET: check
OTBR_MDNS: ${{ matrix.mdns }}
OTBR_COVERAGE: 1
OTBR_VERBOSE: 1
OTBR_OPTIONS: "-DCMAKE_BUILD_TYPE=Debug -DOT_THREAD_VERSION=1.4 -DOTBR_COVERAGE=ON -DOTBR_DBUS=ON -DOTBR_FEATURE_FLAGS=ON -DOTBR_TELEMETRY_DATA_API=ON -DOTBR_UNSECURE_JOIN=ON -DOTBR_TREL=ON -DBUILD_TESTING=OFF"
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -60,8 +62,20 @@ jobs:
run: tests/scripts/bootstrap.sh
- name: Build
run: |
OTBR_BUILD_DIR="./build/temp" script/cmake-build -DCMAKE_BUILD_TYPE=Debug -DOT_THREAD_VERSION=1.4 -DOTBR_COVERAGE=ON -DOTBR_DBUS=ON -DOTBR_FEATURE_FLAGS=ON -DOTBR_TELEMETRY_DATA_API=ON -DOTBR_WEB=ON -DOTBR_UNSECURE_JOIN=ON -DOTBR_TREL=ON
OTBR_BUILD_DIR="./build/temp" script/cmake-build "${OTBR_OPTIONS}"
- name: Build OTBR Docker Image
run: |
sudo docker build -t otbr-ncp \
-f ./etc/docker/Dockerfile . \
--build-arg NAT64=0 \
--build-arg NAT64_SERVICE=0 \
--build-arg DNS64=0 \
--build-arg WEB_GUI=0 \
--build-arg REST_API=0 \
--build-arg FIREWALL=0 \
--build-arg OTBR_OPTIONS="${OTBR_OPTIONS}"
- name: Run
run: OTBR_VERBOSE=1 OTBR_TOP_BUILDDIR="./build/temp" script/test ncp_mode
run: |
top_builddir="./build/temp" tests/scripts/ncp_mode build_ot_sim expect
- name: Codecov
uses: codecov/codecov-action@v4
5 changes: 1 addition & 4 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,11 @@ main()
do_doxygen
;;
help)
print_usage
print_usage 1
;;
meshcop)
top_builddir="${OTBR_TOP_BUILDDIR}" print_result ./tests/scripts/meshcop
;;
ncp_mode)
top_builddir="${OTBR_TOP_BUILDDIR}" print_result ./tests/scripts/ncp_mode
;;
openwrt)
print_result ./tests/scripts/openwrt
;;
Expand Down
124 changes: 91 additions & 33 deletions tests/scripts/ncp_mode
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ readonly OT_CLI
OT_NCP="${OT_NCP:-ot-ncp-ftd}"
readonly OT_NCP

OTBR_DOCKER_IMAGE="${OTBR_DOCKER_IMAGE:-otbr-ncp}"
readonly OTBR_DOCKER_IMAGE

ABS_TOP_BUILDDIR="$(cd "${top_builddir:-"${SCRIPT_DIR}"/../../}" && pwd)"
readonly ABS_TOP_BUILDDIR

Expand Down Expand Up @@ -126,12 +129,39 @@ readonly TUN_NAME
#----------------------------------------
# Test steps
#----------------------------------------
build_ot_simulation()
do_build_ot_simulation()
{
sudo rm -rf "${ABS_TOP_OT_BUILDDIR}/ncp"
sudo rm -rf "${ABS_TOP_OT_BUILDDIR}/cli"
OT_CMAKE_BUILD_DIR=${ABS_TOP_OT_BUILDDIR}/ncp "${ABS_TOP_OT_SRCDIR}"/script/cmake-build simulation -DOT_MTD=OFF -DOT_APP_CLI=OFF -DOT_APP_RCP=OFF
OT_CMAKE_BUILD_DIR=${ABS_TOP_OT_BUILDDIR}/cli "${ABS_TOP_OT_SRCDIR}"/script/cmake-build simulation -DOT_MTD=OFF -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF -DOT_RCP=OFF
OT_CMAKE_BUILD_DIR=${ABS_TOP_OT_BUILDDIR}/ncp "${ABS_TOP_OT_SRCDIR}"/script/cmake-build simulation \
-DOT_MTD=OFF -DOT_RCP=OFF -DOT_APP_CLI=OFF -DOT_APP_RCP=OFF \
-DOT_BORDER_ROUTING=ON -DOT_NCP_INFRA_IF=ON -DOT_SIMULATION_INFRA_IF=OFF \
-DBUILD_TESTING=OFF
OT_CMAKE_BUILD_DIR=${ABS_TOP_OT_BUILDDIR}/cli "${ABS_TOP_OT_SRCDIR}"/script/cmake-build simulation \
-DOT_MTD=OFF -DOT_RCP=OFF -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \
-DOT_BORDER_ROUTING=OFF \
-DBUILD_TESTING=OFF
}

do_build_otbr_docker()
{
otbr_docker_options=(
"-DOT_THREAD_VERSION=1.4"
"-DOTBR_DBUS=ON"
"-DOTBR_FEATURE_FLAGS=ON"
"-DOTBR_TELEMETRY_DATA_API=ON"
"-DOTBR_TREL=ON"
"-DOTBR_LINK_METRICS_TELEMETRY=ON"
)
sudo docker build -t "${OTBR_DOCKER_IMAGE}" \
-f ./etc/docker/Dockerfile . \
--build-arg NAT64=0 \
--build-arg NAT64_SERVICE=0 \
--build-arg DNS64=0 \
--build-arg WEB_GUI=0 \
--build-arg REST_API=0 \
--build-arg FIREWALL=0 \
--build-arg OTBR_OPTIONS="${otbr_docker_options[*]}"
}

test_setup()
Expand All @@ -143,9 +173,14 @@ test_setup()
# OPENTHREAD_POSIX_DAEMON_SOCKET_LOCK
sudo rm -vf "/tmp/openthread.lock"

[[ ${BUILD_OT_SIM} == 1 ]] && build_ot_simulation
ot_cli=$(find "${ABS_TOP_OT_BUILDDIR}" -name "${OT_CLI}")
ot_ncp=$(find "${ABS_TOP_OT_BUILDDIR}" -name "${OT_NCP}")
executable_or_die "${ot_cli}"
executable_or_die "${ot_ncp}"

export EXP_OTBR_AGENT_PATH="${OTBR_AGENT_PATH}"
export EXP_OT_CLI_PATH="${ot_cli}"
export EXP_OT_NCP_PATH="${ot_ncp}"

# We will be creating a lot of log information
# Rotate logs so we have a clean and empty set of logs uncluttered with other stuff
Expand Down Expand Up @@ -217,45 +252,68 @@ otbr_exec_expect_script()
done
}

parse_args()
do_expect()
{
BUILD_OT_SIM=1
RUN_ALL_TESTS=1
if [[ $# != 0 ]]; then
otbr_exec_expect_script "$@"
else
mapfile -t test_files < <(find "${EXPECT_SCRIPT_DIR}" -type f -name "ncp_*.exp")
otbr_exec_expect_script "${test_files[@]}" || die "ncp expect script failed!"
fi

while [[ $# -gt 0 ]]; do
case $1 in
--build-ot-sim)
BUILD_OT_SIM="$2"
shift
;;
--one-test)
RUN_ALL_TESTS=0
TEST_NAME="$2"
shift
;;
esac
shift
done
exit 0
}

main()
print_usage()
{
parse_args "$@"
cat <<EOF
USAGE: $0 COMMAND
COMMAND:
build_ot_sim Build simulated ot-cli-ftd and ot-ncp-ftd for testing.
build_otbr_docker Build otbr docker image for testing.
expect Run expect tests for otbr NCP mode.
help Print this help.
EXAMPLES:
$0 build_ot_sim build_otbr_docker expect
EOF
exit "$1"
}

test_setup
main()
{
if [[ $# == 0 ]]; then
print_usage 1
fi

export EXP_OTBR_AGENT_PATH="${OTBR_AGENT_PATH}"
export EXP_TUN_NAME="${TUN_NAME}"
export EXP_LEADER_NODE_ID="${LEADER_NODE_ID}"
export EXP_OT_CLI_PATH="${ot_cli}"
export EXP_OT_NCP_PATH="${ot_ncp}"
export EXP_OTBR_DOCKER_IMAGE="${OTBR_DOCKER_IMAGE}"

if [[ ${RUN_ALL_TESTS} == 0 ]]; then
otbr_exec_expect_script "${EXPECT_SCRIPT_DIR}/${TEST_NAME}" || die "ncp expect script failed!"
else
mapfile -t test_files < <(find "${EXPECT_SCRIPT_DIR}" -type f -name "ncp_*.exp")
otbr_exec_expect_script "${test_files[@]}" || die "ncp expect script failed!"
fi
while [[ $# != 0 ]]; do
case "$1" in
build_ot_sim)
do_build_ot_simulation
;;
build_otbr_docker)
do_build_otbr_docker
;;
expect)
shift
test_setup
do_expect "$@"
;;
help)
print_usage 1
;;
*)
echo
echo -e "${OTBR_COLOR_FAIL}Warning:${OTBR_COLOR_NONE} Ignoring: '$1'"
;;
esac
shift
done
}

main "$@"

0 comments on commit 5a8db5b

Please sign in to comment.