1 #!/bin/bash 2 3 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 4 # Use of this source code is governed by a BSD-style license that can be 5 # found in the LICENSE file. 6 7 # Runs the lansim unit tests. 8 9 UNITTESTS=" 10 pyiftun_unittest.py 11 py/tools_unittest.py 12 " 13 14 # Unittests that require creating a TUN/TAP interface (and thus access to 15 # /dev/net/tun) need to be run as root. 16 ROOT_UNITTESTS=" 17 py/tuntap_unittest.py 18 py/simulator_unittest.py 19 " 20 21 set -e 22 23 # Display help/usage message. 24 usage() { 25 cat <<EOF 26 Usage: ${0##*/} [OPTION]... 27 Options: 28 -f force running all unit test modules, regardless of failure 29 -h display this help and exit 30 EOF 31 } 32 33 # Parse command-line options. 34 while getopts ":fh" opt; do 35 case $opt in 36 f) 37 force_all=1 38 ;; 39 h) 40 usage 41 exit 42 ;; 43 \?) 44 echo "Invalid option: -$OPTARG" >&2 45 exit 1 46 ;; 47 esac 48 done 49 50 shift $((OPTIND-1)) 51 if [[ $# > 0 ]]; then 52 echo "Invalid argument: $1" 53 exit 1 54 fi 55 56 # Invoke unit test scripts. 57 for unittest_script in $UNITTESTS; do 58 echo "Running $unittest_script:": 59 python ${unittest_script} || test ${force_all} 60 done 61 62 for unittest_script in $ROOT_UNITTESTS; do 63 echo "Running $unittest_script as root:" 64 sudo PYTHONPATH=${PYTHONPATH} python ${unittest_script} || test ${force_all} 65 done 66 67 exit 0 68