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 9UNITTESTS=" 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. 16ROOT_UNITTESTS=" 17 py/tuntap_unittest.py 18 py/simulator_unittest.py 19" 20 21set -e 22 23# Display help/usage message. 24usage() { 25 cat <<EOF 26Usage: ${0##*/} [OPTION]... 27Options: 28 -f force running all unit test modules, regardless of failure 29 -h display this help and exit 30EOF 31} 32 33# Parse command-line options. 34while 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 48done 49 50shift $((OPTIND-1)) 51if [[ $# > 0 ]]; then 52 echo "Invalid argument: $1" 53 exit 1 54fi 55 56# Invoke unit test scripts. 57for unittest_script in $UNITTESTS; do 58 echo "Running $unittest_script:": 59 python ${unittest_script} || test ${force_all} 60done 61 62for unittest_script in $ROOT_UNITTESTS; do 63 echo "Running $unittest_script as root:" 64 sudo PYTHONPATH=${PYTHONPATH} python ${unittest_script} || test ${force_all} 65done 66 67exit 0 68