tests: Refactor run-all.sh

Reuse the code rather than duplicating the implementation
of starting the tests. To make that easier, allow passing
multiple modules with -f to run-tests.py.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2013-10-30 19:49:12 +02:00 committed by Jouni Malinen
parent 95194219df
commit f72434b43e
2 changed files with 56 additions and 81 deletions

View file

@ -17,90 +17,65 @@ else
fi fi
if [ "x$1" = "xconcurrent-valgrind" ]; then if [ "x$1" = "xconcurrent-valgrind" ]; then
if ! ./start.sh concurrent valgrind; then VALGRIND=valgrind
echo "Could not start test environment" > $LOGDIR/last-debug CONCURRENT=concurrent
exit 1 CONCURRENT_TESTS="-f test_p2p_autogo test_p2p_discovery test_p2p_grpform"
fi SUFFIX=-concurrent-valgrind
DATE=`ls -1tr $LOGDIR | tail -1 | cut -f1 -d-` shift
rm $LOGDIR/last-debug
for i in autogo discovery grpform; do
./run-tests.py -l $LOGDIR/$DATE-run-$i $DB -e $LOGDIR/$DATE-failed-$i -r $LOGDIR/results.txt -f test_p2p_$i || errors=1
cat $LOGDIR/$DATE-run-$i >> $LOGDIR/last-debug
done
./stop-wifi.sh
failures=`grep "ERROR SUMMARY" $LOGDIR/$DATE-valgrind-* | grep -v " 0 errors" | wc -l`
if [ $failures -gt 0 ]; then
echo "Mark as failed due to valgrind errors"
errors=1
fi
if [ $errors -gt 0 ]; then
tar czf /tmp/hwsim-tests-$DATE-FAILED-concurrent-valgrind.tar.gz $LOGDIR/$DATE*
exit 1
fi
elif [ "x$1" = "xconcurrent" ]; then elif [ "x$1" = "xconcurrent" ]; then
if ! ./start.sh concurrent; then CONCURRENT=concurrent
echo "Could not start test environment" > $LOGDIR/last-debug CONCURRENT_TESTS="-f test_p2p_autogo test_p2p_discovery test_p2p_grpform"
exit 1 unset VALGRIND
fi SUFFIX=-concurrent
DATE=`ls -1tr $LOGDIR | tail -1 | cut -f1 -d-` shift
rm $LOGDIR/last-debug
for i in autogo discovery grpform; do
./run-tests.py -l $LOGDIR/$DATE-run-$i $DB -e $LOGDIR/$DATE-failed-$i -r $LOGDIR/results.txt -f test_p2p_$i || errors=1
cat $LOGDIR/$DATE-run-$i >> $LOGDIR/last-debug
done
./stop-wifi.sh
if [ $errors -gt 0 ]; then
tar czf /tmp/hwsim-tests-$DATE-FAILED-concurrent.tar.gz $LOGDIR/$DATE*
exit 1
fi
elif [ "x$1" = "xvalgrind" ]; then elif [ "x$1" = "xvalgrind" ]; then
if ! ./start.sh valgrind; then VALGRIND=valgrind
unset CONCURRENT
unset CONCURRENT_TESTS
SUFFIX=-valgrind
shift
else
unset VALGRIND
unset CONCURRENT
unset CONCURRENT_TESTS
SUFFIX=
fi
if [ "x$1" = "xtrace" ] ; then
TRACE=trace
SUFFIX=$SUFFIX-trace
else
unset TRACE
fi
if ! ./start.sh $CONCURRENT $VALGRIND $TRACE; then
echo "Could not start test environment" > $LOGDIR/last-debug echo "Could not start test environment" > $LOGDIR/last-debug
exit 1 exit 1
fi fi
DATE=`ls -1tr $LOGDIR | tail -1 | cut -f1 -d-` DATE=`ls -1tr $LOGDIR | tail -1 | cut -f1 -d-`
./run-tests.py -l $LOGDIR/$DATE-run $DB -e $LOGDIR/$DATE-failed -r $LOGDIR/results.txt || errors=1 rm $LOGDIR/last-debug 2>/dev/null
cat $LOGDIR/$DATE-run > $LOGDIR/last-debug RUNTESTS="./run-tests.py -l $LOGDIR/$DATE-run $DB -e $LOGDIR/$DATE-failed -r $LOGDIR/results.txt $CONCURRENT_TESTS"
./stop-wifi.sh
if [ "$TRACE" != "" ] ; then
sudo trace-cmd record -o $LOGDIR/$DATE-trace.dat -e mac80211 -e cfg80211 su $USER -c $RUNTESTS || errors=1
else
$RUNTESTS || errors=1
fi
cat $LOGDIR/$DATE-run >> $LOGDIR/last-debug
./stop-wifi.sh
if [ ! -z "$VALGRIND" ] ; then
failures=`grep "ERROR SUMMARY" $LOGDIR/$DATE-valgrind-* | grep -v " 0 errors" | wc -l` failures=`grep "ERROR SUMMARY" $LOGDIR/$DATE-valgrind-* | grep -v " 0 errors" | wc -l`
if [ $failures -gt 0 ]; then if [ $failures -gt 0 ]; then
echo "Mark as failed due to valgrind errors" echo "Mark as failed due to valgrind errors"
errors=1 errors=1
fi fi
if [ $errors -gt 0 ]; then fi
tar czf /tmp/hwsim-tests-$DATE-FAILED-valgrind.tar.gz $LOGDIR/$DATE* if [ $errors -gt 0 ]; then
exit 1 tar czf /tmp/hwsim-tests-$DATE-FAILED$SUFFIX.tar.gz $LOGDIR/$DATE*
fi exit 1
elif [ "x$1" = "xtrace" ]; then
if ! ./start.sh trace; then
echo "Could not start test environment" > $LOGDIR/last-debug
exit 1
fi
DATE=`ls -1tr $LOGDIR | tail -1 | cut -f1 -d-`
sudo trace-cmd record -o $LOGDIR/$DATE-trace.dat -e mac80211 -e cfg80211 su $USER -c "./run-tests.py -l $LOGDIR/$DATE-run $DB -e $LOGDIR/$DATE-failed -r $LOGDIR/results.txt" || errors=1
if [ -e $LOGDIR/$DATE-failed ]; then
error=1
fi
sudo chown $USER $LOGDIR/$DATE-trace.dat
cat $LOGDIR/$DATE-run > $LOGDIR/last-debug
./stop-wifi.sh
if [ $errors -gt 0 ]; then
tar czf /tmp/hwsim-tests-$DATE-FAILED-trace.tar.gz $LOGDIR/$DATE*
exit 1
fi
else
if ! ./start.sh; then
echo "Could not start test environment" > $LOGDIR/last-debug
exit 1
fi
DATE=`ls -1tr $LOGDIR | tail -1 | cut -f1 -d-`
./run-tests.py -l $LOGDIR/$DATE-run $DB -e $LOGDIR/$DATE-failed -r $LOGDIR/results.txt || errors=1
cat $LOGDIR/$DATE-run > $LOGDIR/last-debug
./stop-wifi.sh
if [ $errors -gt 0 ]; then
tar czf /tmp/hwsim-tests-$DATE-FAILED.tar.gz $LOGDIR/$DATE*
exit 1
fi
fi fi
echo "ALL-PASSED" echo "ALL-PASSED"

View file

@ -85,16 +85,16 @@ def main():
parser.add_argument('-b', metavar='<build>', dest='build', help='build ID') parser.add_argument('-b', metavar='<build>', dest='build', help='build ID')
parser.add_argument('-L', action='store_true', dest='update_tests_db', parser.add_argument('-L', action='store_true', dest='update_tests_db',
help='List tests (and update descriptions in DB)') help='List tests (and update descriptions in DB)')
parser.add_argument('-f', dest='testmodule', metavar='<test module>', parser.add_argument('-f', dest='testmodules', metavar='<test module>',
help='execute only tests from this test module', help='execute only tests from these test modules',
type=str, choices=[[]] + test_modules) type=str, choices=[[]] + test_modules, nargs='+')
parser.add_argument('tests', metavar='<test>', nargs='*', type=str, parser.add_argument('tests', metavar='<test>', nargs='*', type=str,
help='tests to run (only valid without -f)', help='tests to run (only valid without -f)',
choices=[[]] + test_names) choices=[[]] + test_names)
args = parser.parse_args() args = parser.parse_args()
if args.tests and args.testmodule: if args.tests and args.testmodules:
print 'Invalid arguments - both test module and tests given' print 'Invalid arguments - both test module and tests given'
sys.exit(2) sys.exit(2)
@ -168,8 +168,8 @@ def main():
if args.tests: if args.tests:
if not t.__name__ in args.tests: if not t.__name__ in args.tests:
continue continue
if args.testmodule: if args.testmodules:
if not t.__module__ == args.testmodule: if not t.__module__ in args.testmodules:
continue continue
reset_devs(dev, apdev) reset_devs(dev, apdev)
logger.info("START " + t.__name__) logger.info("START " + t.__name__)