From 6dcf5415a941b8a800c0cc2d60b27077cc945436 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 9 Apr 2018 09:37:24 -0700 Subject: [PATCH] [toranj] add cleanup code after every test-case (#2650) This commit adds `cleanup()` function in the `toranj` start script. The cleanup code removes logs and any flash files, issues a `killall` to remove any lingering `wpantund` instances (`wpantund` processes may still be running from previous `wpan.Node` objects which are not yet garbage collected by python). It also deletes any `wpan` network interfaces (this addresses the situation where even after `killall wpantund` the network interface may stay active by kernel for some short time, not allowing the next test-case to create network interface with same name). --- tests/toranj/start.sh | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/toranj/start.sh b/tests/toranj/start.sh index 95d317207..0594411ee 100755 --- a/tests/toranj/start.sh +++ b/tests/toranj/start.sh @@ -32,20 +32,38 @@ die() { exit 1 } +cleanup() { + # Clear logs and flash files + sudo rm tmp/*.flash > /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 + + sleep 0.3 +} + run() { counter=0 while true; do - # Clear logs and flash files - sudo rm tmp/*.flash > /dev/null 2>&1 - sudo rm *.log > /dev/null 2>&1 - sudo python $1 && return + if sudo python $1; then + cleanup + return + fi # On Travis, we allow a failed test to be retried up to 3 attempts. if [ "$BUILD_TARGET" = "toranj-test-framework" ]; then if [ "$counter" -lt 2 ]; then counter=$((counter+1)) echo Attempt $counter running "$1" failed. Trying again. + cleanup sleep 10 continue fi @@ -85,6 +103,8 @@ make -j 8 || die cd tests/toranj +cleanup + run test-001-get-set.py run test-002-form.py run test-003-join.py @@ -93,3 +113,5 @@ run test-005-discover-scan.py run test-006-traffic-router-end-device.py run test-007-traffic-router-sleepy.py run test-008-permit-join.py + +exit 0