1#!/bin/sh 2 3errors=0 4umask 0002 5 6DATE="$(date +%s)" 7unset LOGBASEDIR 8if [ -z "$LOGDIR" ]; then 9 LOGBASEDIR=logs 10 LOGDIR=$LOGBASEDIR/$DATE 11 mkdir -p $LOGDIR 12fi 13export LOGDIR 14 15if [ -z "$DBFILE" ]; then 16 DB="" 17else 18 DB="-S $DBFILE --commit $(git rev-parse HEAD)" 19 if [ -n "$BUILD" ]; then 20 DB="$DB -b $BUILD" 21 fi 22 if [ "$PREFILL_DB" = "y" ] ; then 23 DB="$DB --prefill-tests" 24 fi 25fi 26 27usage() 28{ 29 echo "$0 [-v | --valgrind | valgrind] [-t | --trace | trace]" 30 echo "\t[-n <num> | --channels <num>] [-B | --build]" 31 echo "\t[-c | --codecov ] [run-tests.py parameters]" 32 exit 1 33} 34 35unset VALGRIND 36unset TRACE 37unset TRACE_ARGS 38unset RUN_TEST_ARGS 39unset BUILD 40unset BUILD_ARGS 41unset CODECOV 42unset VM 43while [ "$1" != "" ]; do 44 case $1 in 45 -v | --valgrind | valgrind) 46 shift 47 echo "$0: using valgrind" 48 VALGRIND=valgrind 49 ;; 50 -t | --trace | trace) 51 shift 52 echo "$0: using Trace" 53 TRACE=trace 54 ;; 55 -n | --channels) 56 shift 57 NUM_CH=$1 58 shift 59 echo "$0: using channels=$NUM_CH" 60 ;; 61 -B | --build) 62 shift 63 echo "$0: build before running tests" 64 BUILD=build 65 ;; 66 -c | --codecov) 67 shift 68 echo "$0: using code coverage" 69 CODECOV=lcov 70 BUILD_ARGS=-c 71 ;; 72 -h | --help) 73 usage 74 ;; 75 -V | --vm) 76 shift 77 echo "$0: running inside a VM" 78 VM=VM 79 ;; 80 81 *) 82 RUN_TEST_ARGS="$RUN_TEST_ARGS$1 " 83 shift 84 ;; 85 esac 86done 87 88if [ ! -z "$RUN_TEST_ARGS" ]; then 89 echo "$0: passing the following args to run-tests.py: $RUN_TEST_ARGS" 90fi 91 92unset SUFFIX 93if [ ! -z "$BUILD" ]; then 94 SUFFIX=-build 95fi 96 97if [ ! -z "$VALGRIND" ]; then 98 SUFFIX=$SUFFIX-valgrind 99fi 100 101if [ ! -z "$TRACE" ]; then 102 SUFFIX=$SUFFIX-trace 103 TRACE_ARGS="-T" 104fi 105 106if [ ! -z "$CODECOV" ]; then 107 SUFFIX=$SUFFIX-codecov 108fi 109 110if [ ! -z "$BUILD" ]; then 111 echo "Building with args=$BUILD_ARGS" 112 if ! ./build.sh $BUILD_ARGS; then 113 echo "Failed building components" 114 exit 1 115 fi 116fi 117 118if ! ./start.sh $VM $VALGRIND $TRACE channels=$NUM_CH; then 119 if ! [ -z "$LOGBASEDIR" ] ; then 120 echo "Could not start test environment" > $LOGDIR/run 121 fi 122 exit 1 123fi 124 125# Only use sudo if not already root. 126if [ "$(id -u)" != 0 ]; then 127 SUDO=sudo 128else 129 SUDO= 130fi 131${SUDO} ./run-tests.py -D --logdir "$LOGDIR" $TRACE_ARGS -q $DB $RUN_TEST_ARGS || errors=1 132 133./stop.sh 134 135if [ ! -z "$VALGRIND" ] ; then 136 failures=`grep "ERROR SUMMARY" $LOGDIR/valgrind-* | grep -v " 0 errors" | wc -l` 137 if [ $failures -gt 0 ]; then 138 echo "Mark as failed due to valgrind errors" 139 errors=1 140 fi 141fi 142 143if tail -100 $LOGDIR/auth_serv | grep -q MEMLEAK; then 144 echo "Mark as failed due to authentication server memory leak" 145 errors=1 146fi 147 148if [ ! -z "$CODECOV" ] ; then 149 lcov -q --capture --directory ../../wpa_supplicant --output-file $LOGDIR/wpas_lcov.info 150 genhtml -q $LOGDIR/wpas_lcov.info --output-directory $LOGDIR/wpas_lcov 151 lcov -q --capture --directory ../../hostapd --output-file $LOGDIR/hostapd_lcov.info 152 genhtml -q $LOGDIR/hostapd_lcov.info --output-directory $LOGDIR/hostapd_lcov 153fi 154 155if [ $errors -gt 0 ]; then 156 if [ -z $VM ]; then 157 tar czf /tmp/hwsim-tests-$DATE-FAILED$SUFFIX.tar.gz $LOGDIR/ 158 fi 159 exit 1 160fi 161 162echo "ALL-PASSED" 163