3 if [ -z "${PYTHON}" ]; then
8 echo "Usage: $0 [OPTION]..."
9 echo "Run Ryu's test suite(s)"
11 echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
12 echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
13 echo " -c, --coverage Generate coverage report"
14 echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
15 echo " -p, --pycodestyle, --pep8 Just run pycodestyle(pep8)"
16 echo " -P, --no-pycodestyle, --no-pep8 Don't run pycodestyle(pep8)"
17 echo " -l, --pylint Just run pylint"
18 echo " -i, --integrated Run integrated test"
19 echo " -v, --verbose Run verbose pylint analysis"
20 echo " -h, --help Print this usage message"
22 echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
23 echo " If no virtualenv is found, the script will ask if you would like to create one. If you "
24 echo " prefer to run tests NOT in a virtual environment, simply pass the -N option."
31 -V|--virtual-env) always_venv=1; never_venv=0;;
32 -N|--no-virtual-env) always_venv=0; never_venv=1;;
34 -p|--pycodestyle|--pep8) just_pycodestyle=1; never_venv=1; always_venv=0;;
35 -P|--no-pycodestyle|--no-pep8) no_pycodestyle=1;;
36 -l|--pylint) just_pylint=1;;
37 -i|--integrated) integrated=1;;
38 -c|--coverage) coverage=1;;
39 -v|--verbose) verbose=1;;
40 -*) noseopts="$noseopts $1";;
41 *) noseargs="$noseargs $1"
46 with_venv=tools/with_venv.sh
63 # If enabled, tell nose to collect coverage data
64 if [ $coverage -eq 1 ]; then
65 noseopts="$noseopts --with-coverage --cover-package=ryu"
69 # Just run the test suites in current environment
70 ${wrapper} rm -f ./$PLUGIN_DIR/tests.sqlite
72 if [ $verbose -eq 1 ]; then
75 ${wrapper} $NOSETESTS 2> run_tests.log
77 # If we get some short import error right away, print the error log directly
79 if [ "$RESULT" -ne "0" ];
81 ERRSIZE=`wc -l run_tests.log | awk '{print \$1}'`
82 if [ $verbose -eq 0 -a "$ERRSIZE" -lt "40" ];
91 echo "Running pylint ..."
92 PYLINT_OPTIONS="--rcfile=.pylintrc --output-format=parseable"
93 PYLINT_INCLUDE="ryu bin/ryu bin/ryu-manager ryu/tests/bin/ryu-client"
94 export PYTHONPATH=$PYTHONPATH:.ryu
97 ${wrapper} pylint $PYLINT_OPTIONS $PYLINT_INCLUDE > $PYLINT_LOG
98 #BASE_CMD="pylint $PYLINT_OPTIONS $PYLINT_INCLUDE > $PYLINT_LOG"
99 #[ $verbose -eq 1 ] && $BASE_CMD || msg_count=`$BASE_CMD | grep 'ryu/' | wc -l`
100 #if [ $verbose -eq 0 ]; then
101 # echo "Pylint messages count: " $msg_count
103 export PYTHONPATH=$OLD_PYTHONPATH
107 PYCODESTYLE=$(which pycodestyle || which pep8)
108 if [ -z "${PYCODESTYLE}" ]
110 echo "Please install pycodestyle or pep8"
113 echo "Running $(basename ${PYCODESTYLE}) ..."
115 PYCODESTYLE_OPTIONS="--repeat --show-source"
116 PYCODESTYLE_INCLUDE="ryu setup*.py"
117 PYCODESTYLE_LOG=pycodestyle.log
118 ${wrapper} ${PYCODESTYLE} $PYCODESTYLE_OPTIONS $PYCODESTYLE_INCLUDE | tee $PYCODESTYLE_LOG
122 echo "Running integrated test ..."
124 INTEGRATED_TEST_RUNNER="./ryu/tests/integrated/run_tests_with_ovs12.py"
125 sudo PYTHONPATH=. nosetests -s $INTEGRATED_TEST_RUNNER
127 #NOSETESTS="nosetests $noseopts $noseargs"
128 NOSETESTS="${PYTHON} ./ryu/tests/run_tests.py $noseopts $noseargs"
130 #if [ -n "$PLUGIN_DIR" ]
132 # if ! [ -f ./$PLUGIN_DIR/run_tests.py ]
134 # echo "Could not find run_tests.py in plugin directory $PLUGIN_DIR"
139 if [ $never_venv -eq 0 ]
141 # Remove the virtual environment if --force used
142 if [ $force -eq 1 ]; then
143 echo "Cleaning virtualenv..."
146 if [ -e ${venv} ]; then
147 wrapper="${with_venv}"
149 if [ $always_venv -eq 1 ]; then
150 # Automatically install the virtualenv
151 ${PYTHON} tools/install_venv.py
152 wrapper="${with_venv}"
154 echo -e "No virtual environment found...create one? (Y/n) \c"
156 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
157 # Install the virtualenv and run the test suite in it
158 ${PYTHON} tools/install_venv.py
165 # Delete old coverage data from previous runs
166 if [ $coverage -eq 1 ]; then
167 ${wrapper} coverage erase
170 if [ $just_pycodestyle -eq 1 ]; then
174 if [ $just_pylint -eq 1 ]; then
179 if [ $integrated -eq 1 ]; then
186 if [ $no_pycodestyle -eq 0 ]; then
190 if [ $coverage -eq 1 ]; then
191 echo "Generating coverage report in coverage.xml and covhtml/"
192 ${wrapper} coverage xml -i
193 ${wrapper} coverage html -d covhtml -i