Skip to content

Commit

Permalink
[shell] resolve shellcheck warnings (openthread#4966)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhui committed May 19, 2020
1 parent cb9b353 commit dd0fa0d
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 81 deletions.
8 changes: 2 additions & 6 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@

nlbuild_autotools_stem="third_party/nlbuild-autotools/repo"

# Establish some key directories
abs_srcdir=$(cd "$(dirname "${0}")" && pwd)

srcdir=$(dirname ${0})
abs_srcdir=$(pwd)
abs_top_srcdir="${abs_srcdir}"

exec ${srcdir}/${nlbuild_autotools_stem}/scripts/bootstrap -I "${abs_top_srcdir}/${nlbuild_autotools_stem}" $*
(cd "$abs_srcdir" && exec "$abs_srcdir/$nlbuild_autotools_stem/scripts/bootstrap" -I "$abs_srcdir/$nlbuild_autotools_stem" "${@}")
2 changes: 1 addition & 1 deletion etc/docker/ot_sim/add_node
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker exec -it otsim node $1
docker exec -it otsim node "$1"
6 changes: 3 additions & 3 deletions script/check-ncp-rcp-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ EOF

echo "Step 2. Start retrieving dataset from Radio..."
RADIO_NCP_PATH="$(pwd)/$(ls output/*linux*/bin/ot-ncp-ftd)"
"$(pwd)/$(ls output/posix/*linux*/bin/ot-ncp)" -n --radio-version --ncp-dataset -- ${RADIO_NCP_PATH} 1
"$(pwd)/$(ls output/posix/*linux*/bin/ot-ncp)" -n --radio-version --ncp-dataset -- "${RADIO_NCP_PATH}" 1

echo "Step 3. Start posix app and check whether PAN dataset is the same..."
RADIO_RCP_PATH="$(pwd)/$(ls output/*linux*/bin/ot-rcp)"
Expand Down Expand Up @@ -126,8 +126,8 @@ expect eof
EOF

echo "Step 4. Start posix app and check whether it can get radio firmware version..."
RADIO_VERSION="$("$(pwd)/$(ls output/posix/*linux*/bin/ot-cli)" -n --radio-version --ncp-dataset -- ${RADIO_RCP_PATH} 1)" || true
test -n "{RADIO_VERSION}"
RADIO_VERSION="$("$(pwd)/$(ls output/posix/*linux*/bin/ot-cli)" -n --radio-version --ncp-dataset -- "${RADIO_RCP_PATH}" 1)" || true
test -n "${RADIO_VERSION}"
}

main()
Expand Down
2 changes: 0 additions & 2 deletions script/check-posix-build-autotools
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

set -euxo pipefail

readonly OT_BUILD_JOBS=$(getconf _NPROCESSORS_ONLN)

reset_source()
{
rm -rf build output tmp
Expand Down
8 changes: 4 additions & 4 deletions script/check-posix-build-cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ build()
"-DOT_FULL_LOGS=on"
)

mkdir -p $OT_BUILDDIR
cd $OT_BUILDDIR
cmake -GNinja "${options[@]}" $OT_SRCDIR
mkdir -p "$OT_BUILDDIR"
cd "$OT_BUILDDIR"
cmake -GNinja "${options[@]}" "$OT_SRCDIR"
ninja

cd $OT_SRCDIR
cd "$OT_SRCDIR"
}

main()
Expand Down
36 changes: 22 additions & 14 deletions script/check-posix-pty
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set -x

die()
{
echo " *** ERROR: " $*
echo " *** ERROR: " "$*"
exit 1
}

Expand Down Expand Up @@ -62,19 +62,21 @@ check()
OT_OUTPUT=/tmp/ot-output
socat -d -d pty,raw,echo=0 pty,raw,echo=0 >/dev/null 2>$SOCAT_OUTPUT &
while true; do
if test $(head -n2 $SOCAT_OUTPUT | wc -l) = 2; then
if test "$(head -n2 $SOCAT_OUTPUT | wc -l)" = 2; then
RADIO_PTY=$(head -n1 $SOCAT_OUTPUT | grep -o '/dev/.\+')
CORE_PTY=$(head -n2 $SOCAT_OUTPUT | tail -n1 | grep -o '/dev/.\+')
break
fi
echo 'Waiting for socat ready...'
sleep 1
done
echo 'RADIO_PTY' $DEVICE_PTY
echo 'CORE_PTY' $CORE_PTY
echo 'RADIO_PTY' "$DEVICE_PTY"
echo 'CORE_PTY' "$CORE_PTY"

RADIO_NCP_PATH="$(pwd)/$(ls output/*linux*/bin/ot-rcp)"
$RADIO_NCP_PATH 1 >$RADIO_PTY <$RADIO_PTY &

# shellcheck disable=SC2094
$RADIO_NCP_PATH 1 >"$RADIO_PTY" <"$RADIO_PTY" &

# Cover setting a valid network interface name.
readonly VALID_NETIF_NAME="wan$(date +%H%M%S)"
Expand All @@ -84,26 +86,28 @@ check()
)

if [[ ${DAEMON} == 1 ]]; then
sudo "$(pwd)/$(ls output/posix/*linux*/bin/ot-daemon)" "${options[@]}" -I "${VALID_NETIF_NAME}" ${CORE_PTY} &
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=
else
OT_CLI_CMD="$(pwd)/$(ls output/posix/*linux*/bin/ot-cli) "${options[@]}" ${CORE_PTY}"
OT_CLI_CMD="$(pwd)/$(ls output/posix/*linux*/bin/ot-cli)"
OT_CLI_ARG="${CORE_PTY}"
fi

sudo ${OT_CLI_CMD} -I "${VALID_NETIF_NAME}" -n
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_CMD} -I "${INVALID_NETIF_NAME}" -n || test $? = 2
sudo "${OT_CLI_CMD}" "${OT_CLI_ARG}" -I "${INVALID_NETIF_NAME}" -n || test $? = 2

if [[ ${DAEMON} == 1 ]]; then
sudo ${OT_CLI_CMD} panid 0xface | grep 'Done' || die 'failed to set panid with ot-ctl'
sudo "${OT_CLI_CMD}" "${OT_CLI_ARG}" panid 0xface | grep 'Done' || die 'failed to set panid with ot-ctl'
fi

sudo expect <<EOF >"${OT_OUTPUT}" &
spawn ${OT_CLI_CMD}
sudo expect <<EOF | tee "${OT_OUTPUT}" &
spawn ${OT_CLI_CMD} ${OT_CLI_ARG}
send "panid 0xface\r\n"
expect "Done"
send "ifconfig up\r\n"
Expand Down Expand Up @@ -142,7 +146,7 @@ EOF
sudo killall -9 expect || true
sudo killall -9 ot-ctl || true
NETIF_INDEX=$(ip link show "${VALID_NETIF_NAME}" | cut -f 1 -d ":" | head -n 1)
sudo PATH="$(dirname ${OT_CLI_CMD}):${PATH}" \
sudo PATH="$(dirname "${OT_CLI_CMD}"):${PATH}" \
python3 "$PWD/tests/scripts/misc/test_multicast_join.py" "${NETIF_INDEX}" \
|| die 'multicast group join failed'
fi
Expand All @@ -153,7 +157,11 @@ EOF
echo "CoAP response is: ${coap_response}"

# Verify CoAP response contains the extended address
[[ ${coap_response} == *${extaddr}* ]] && echo 'Success' || die 'failed to get extended address'
if [[ ${coap_response} == *${extaddr}* ]]; then
echo 'Success'
else
die 'failed to get extended address'
fi
}

main()
Expand Down
6 changes: 3 additions & 3 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ do_unit()
local builddir="${OT_BUILDDIR}/cmake/openthread-simulation-${THREAD_VERSION}"
if [[ ! -d ${builddir} ]]; then
echo "Cannot find build directory!"
exit -1
exit 1
fi

cd "${builddir}"
Expand Down Expand Up @@ -410,8 +410,8 @@ envsetup()
export -n VERBOSE
fi

read -r -a ot_extra_options <<<"${OT_OPTIONS-}"
ot_extra_options=${ot_extra_options:-()}
read -r -a ot_extra_options_in <<<"${OT_OPTIONS-}"
ot_extra_options=${ot_extra_options_in:-()}
}

main()
Expand Down
42 changes: 21 additions & 21 deletions tests/toranj/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright (c) 2018, The OpenThread Authors.
# All rights reserved.
Expand Down Expand Up @@ -27,15 +27,12 @@
# POSSIBILITY OF SUCH DAMAGE.
#

cd $(dirname $0)
cd ../..

display_usage()
{
echo ""
echo "Toranj Build script "
echo ""
echo "Usage: $(basename $0) [options] <config>"
echo "Usage: $(basename "$0") [options] <config>"
echo " <config> can be:"
echo " ncp : Build OpenThread NCP FTD mode with simulation platform"
echo " rcp : Build OpenThread RCP (NCP in radio mode) with simulation platform"
Expand All @@ -51,10 +48,13 @@ display_usage()

die()
{
echo " *** ERROR: " $*
echo " *** ERROR: " "$*"
exit 1
}

cd "$(dirname "$0")" || die "cd failed"
cd ../.. || die "cd failed"

coverage=no
tests=no

Expand Down Expand Up @@ -83,13 +83,13 @@ fi

build_config=$1

configure_options=" \
--disable-docs \
--enable-tests=$tests \
--enable-coverage=$coverage \
--enable-ftd \
--enable-ncp \
"
configure_options=(
"--disable-docs"
"--enable-tests=$tests"
"--enable-coverage=$coverage"
"--enable-ftd"
"--enable-ncp"
)

if [ -n "${top_builddir}" ]; then
top_srcdir=$(pwd)
Expand All @@ -104,22 +104,22 @@ case ${build_config} in
echo "==================================================================================================="
echo "Building OpenThread NCP FTD mode with POSIX platform"
echo "==================================================================================================="
./bootstrap || die
cd "${top_builddir}"
./bootstrap || die "bootstrap failed"
cd "${top_builddir}" || die "cd failed"
cppflags_config='-DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"../tests/toranj/openthread-core-toranj-config-simulation.h\"'
${top_srcdir}/configure \
CPPFLAGS="$cppflags_config" \
--with-examples=simulation \
$configure_options || die
"${configure_options[@]}" || die
make -j 8 || die
;;

rcp)
echo "===================================================================================================="
echo "Building OpenThread RCP (NCP in radio mode) with POSIX platform"
echo "===================================================================================================="
./bootstrap || die
cd "${top_builddir}"
./bootstrap || die "bootstrap failed"
cd "${top_builddir}" || die "cd failed"
cppflags_config='-DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"../tests/toranj/openthread-core-toranj-config-simulation.h\"'
${top_srcdir}/configure \
CPPFLAGS="$cppflags_config " \
Expand All @@ -136,13 +136,13 @@ case ${build_config} in
echo "===================================================================================================="
echo "Building OpenThread POSIX App NCP"
echo "===================================================================================================="
./bootstrap || die
cd "${top_builddir}"
./bootstrap || die "bootstrap failed"
cd "${top_builddir}" || die "cd failed"
cppflags_config='-DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"../tests/toranj/openthread-core-toranj-config-posix.h\"'
${top_srcdir}/configure \
CPPFLAGS="$cppflags_config" \
--with-platform=posix \
$configure_options || die
"${configure_options[@]}" || die
make -j 8 || die
;;

Expand Down
24 changes: 11 additions & 13 deletions tests/toranj/start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright (c) 2018, The OpenThread Authors.
# All rights reserved.
Expand Down Expand Up @@ -29,24 +29,22 @@

die()
{
echo " *** ERROR: " $*
echo " *** ERROR: " "$*"
exit 1
}

cleanup()
{
# Clear logs and flash files
sudo rm tmp/*.flash tmp/*.data tmp/*.swap >/dev/null 2>&1
sudo rm *.log >/dev/null 2>&1
sudo rm ./*.log >/dev/null 2>&1

# Clear any wpantund instances
sudo killall wpantund >/dev/null 2>&1

wpan_interfaces=$(ifconfig 2>/dev/null | grep -o wpan[0-9]*)

for interface in $wpan_interfaces; do
sudo ip link delete $interface >/dev/null 2>&1
done
while read -r interface; do
sudo ip link delete "$interface" >/dev/null 2>&1
done < <(ifconfig 2>/dev/null | grep -o "wpan[0-9]*")

sleep 0.3
}
Expand All @@ -56,7 +54,7 @@ run()
counter=0
while true; do

if sudo -E python $1; then
if sudo -E python "$1"; then
cleanup
return
fi
Expand All @@ -76,7 +74,7 @@ run()
done
}

cd $(dirname $0)
cd "$(dirname "$0")" || die "cd failed"

if [ "$COVERAGE" = 1 ]; then
coverage_option="--enable-coverage"
Expand All @@ -94,11 +92,11 @@ case $TORANJ_POSIX_RCP_MODEL in
esac

if [ "$use_posix_with_rcp" = "no" ]; then
./build.sh ${coverage_option} ncp || die
./build.sh ${coverage_option} ncp || die "ncp build failed"

else
./build.sh ${coverage_option} rcp || die
./build.sh ${coverage_option} posix || die
./build.sh ${coverage_option} rcp || die "rcp build failed"
./build.sh ${coverage_option} posix || die "posix build failed"
fi

cleanup
Expand Down
Loading

0 comments on commit dd0fa0d

Please sign in to comment.