[ot-ctl] fix reset in non-interactive mode (#5011)

* set close on exec
* explicitly close socket on reset
* enhance ot-ctl to exit on peer close
* added test for the change
This commit is contained in:
Yakun Xu
2020-05-28 10:31:16 -07:00
committed by GitHub
parent 204308f4a7
commit 5e65833d72
4 changed files with 119 additions and 83 deletions
+14 -14
View File
@@ -89,25 +89,25 @@ check()
sudo "$(pwd)/$(ls output/posix/*linux*/bin/ot-daemon)" "${options[@]}" -I "${VALID_NETIF_NAME}" "${CORE_PTY}" &
sleep 1
OT_CLI_CMD="$(pwd)/$(ls output/posix/*linux*/bin/ot-ctl)"
OT_CLI_ARG=
sudo "${OT_CLI_CMD}" panid 0xface | grep 'Done' || die 'failed to set panid with ot-ctl'
# verify this reset and factoryreset end immediately
sudo "${OT_CLI_CMD}" reset
sudo "${OT_CLI_CMD}" factoryreset
else
OT_CLI_CMD="$(pwd)/$(ls output/posix/*linux*/bin/ot-cli)"
OT_CLI_ARG="${CORE_PTY}"
fi
OT_CLI="$(pwd)/$(ls output/posix/*linux*/bin/ot-cli)"
sudo "${OT_CLI}" -I "${VALID_NETIF_NAME}" -n "${CORE_PTY}"
sudo "${OT_CLI_CMD}" "${OT_CLI_ARG}" -I "${VALID_NETIF_NAME}" -n
# Cover setting a too long(max is 15 characters) network interface name.
# Expect exit code to be 2(OT_EXIT_INVALID_ARGUMENTS).
readonly INVALID_NETIF_NAME="wan0123456789123"
sudo "${OT_CLI}" -I "${INVALID_NETIF_NAME}" -n "${CORE_PTY}" || test $? = 2
# Cover setting a too long(max is 15 characters) network interface name.
# Expect exit code to be 2(OT_EXIT_INVALID_ARGUMENTS).
readonly INVALID_NETIF_NAME="wan0123456789123"
sudo "${OT_CLI_CMD}" "${OT_CLI_ARG}" -I "${INVALID_NETIF_NAME}" -n || test $? = 2
if [[ ${DAEMON} == 1 ]]; then
sudo "${OT_CLI_CMD}" "${OT_CLI_ARG}" panid 0xface | grep 'Done' || die 'failed to set panid with ot-ctl'
OT_CLI_CMD="$(pwd)/$(ls output/posix/*linux*/bin/ot-cli) ${CORE_PTY}"
fi
sudo expect <<EOF | tee "${OT_OUTPUT}" &
spawn ${OT_CLI_CMD} ${OT_CLI_ARG}
spawn ${OT_CLI_CMD}
send "panid 0xface\r\n"
expect "Done"
send "ifconfig up\r\n"
@@ -160,7 +160,7 @@ EOF
if [[ ${coap_response} == *${extaddr}* ]]; then
echo 'Success'
else
die 'failed to get extended address'
die 'Failed to get extended address'
fi
}