1 # Report installed versions 2 echo "### INSTALLED VERSIONS ###" 3 python -c 'import sys; print("sys.path:" , sys.path)' 4 for DEPENDENCY in "six" "cryptography" "mock" "pcap" "dnet" "coverage" 5 do 6 python -c 'import '$DEPENDENCY'; print("'$DEPENDENCY': "+str(getattr('$DEPENDENCY', "__version__", "no __version__ attribute")))' 7 echo "----" 8 done 9 10 # Dump environment variables 11 echo "SCAPY_SUDO=" $SCAPY_SUDO 12 echo "TRAVIS_OS_NAME=" $TRAVIS_OS_NAME 13 14 # Dump Scapy config 15 python --version 16 python -c "from scapy.all import *; print(conf)" 17 18 # Don't run tests that require root privileges 19 if [ -z "$SCAPY_SUDO" -o "$SCAPY_SUDO" = "false" ] 20 then 21 UT_FLAGS="-K netaccess -K needs_root -K manufdb" 22 SCAPY_SUDO="" 23 else 24 SCAPY_SUDO="$SCAPY_SUDO -H" 25 fi 26 27 if [ "$SCAPY_USE_PCAPDNET" = "yes" ] 28 then 29 UT_FLAGS+=" -K not_pcapdnet" 30 fi 31 # IPv6 is not available yet on travis 32 UT_FLAGS+=" -K ipv6" 33 34 # AES-CCM, ChaCha20Poly1305 and X25519 were added to Cryptography v2.0 35 # but the minimal version mandated by scapy is v1.7 36 UT_FLAGS+=" -K crypto_advanced" 37 38 if python --version 2>&1 | grep -q PyPy 39 then 40 # cryptography requires PyPy >= 2.6, Travis CI uses 2.5.0 41 UT_FLAGS+=" -K crypto -K not_pypy" 42 fi 43 44 if python --version 2>&1 | grep -q '^Python 3\.' 45 then 46 # Some Python 3 tests currently fail. They should be tracked and 47 # fixed. 48 UT_FLAGS+=" -K FIXME_py3" 49 fi 50 51 if python --version 2>&1 | grep -q '^Python 3\.[012345]' 52 then 53 # Python 3 < 3.6 has weird behavior with random.seed() 54 UT_FLAGS+=" -K random_weird_py3" 55 fi 56 57 if python --version 2>&1 | grep -q '^Python 3\.[0123]' 58 then 59 # cryptography with Python 3 < 3.4 requires 3.3.7, Travis provides 3.3.6 60 UT_FLAGS+=" -K crypto" 61 fi 62 63 # Set PATH 64 ## /Users/travis/Library/Python/2.7/bin: pip when non-root on osx 65 for _path in /sbin /usr/sbin /usr/local/sbin /Users/travis/Library/Python/2.7/bin; do 66 [ -d "$_path" ] && echo "$PATH" | grep -qvE "(^|:)$_path(:|$)" && export PATH="$PATH:$_path" 67 done 68 69 # Create a fake Python executable 70 if [ "$SCAPY_COVERAGE" = "yes" ] 71 then 72 echo '#!/bin/bash' > test/python 73 echo "[ \"\$*\" = \"--version\" ] && echo \"`python --version`\" && exit 0" >> test/python 74 echo "`which coverage` run --rcfile=../.coveragerc --concurrency=multiprocessing -a \$*" >> test/python 75 chmod +x test/python 76 77 # Copy the fake Python interpreter to bypass /etc/sudoers rules on Ubuntu 78 if [ -n "$SCAPY_SUDO" ] 79 then 80 $SCAPY_SUDO cp test/python /usr/local/sbin/ 81 PYTHON=/usr/local/sbin/python 82 else 83 PATH="`pwd`/test":$PATH 84 PYTHON="`pwd`/test/python" 85 fi 86 else 87 PYTHON="`which python`" 88 fi 89 90 # Do we have tcpdump or thsark? 91 which tcpdump >/dev/null 2>&1 || UT_FLAGS+=" -K tcpdump" 92 which tshark >/dev/null 2>&1 || UT_FLAGS+=" -K tshark" 93 94 if [ -n "$SCAPY_SUDO" ] 95 then 96 SCAPY_SUDO="$SCAPY_SUDO --preserve-env" 97 fi 98 99 # Dump Environment (so that we can check PATH, UT_FLAGS, etc.) 100 set 101 102 # Run unit tests 103 cd test/ 104 105 if [ "$TRAVIS_OS_NAME" = "osx" ] 106 then 107 if [ -z "$SCAPY_USE_PCAPDNET" ] 108 then 109 PYTHON="$PYTHON" $SCAPY_SUDO ./run_tests -q -F -t bpf.uts $UT_FLAGS || exit $? 110 fi 111 UT_FLAGS+=" -K manufdb -K linux" 112 fi 113 114 if [ "$TRAVIS_OS_NAME" = "linux" ] 115 then 116 UT_FLAGS+=" -K osx" 117 fi 118 119 # Run all normal and contrib tests 120 PYTHON="$PYTHON" $SCAPY_SUDO ./run_tests -c ./configs/travis.utsc -T "bpf.uts" -T "mock_windows.uts" $UT_FLAGS || exit $? 121 122 # Run unit tests with openssl if we have root privileges 123 if [ "$TRAVIS_OS_NAME" = "linux" ] && [ -n "$SCAPY_SUDO" ] 124 then 125 echo "Running TLS netaccess tests" 126 PYTHON="$PYTHON" $SCAPY_SUDO ./run_tests -q -F -t tls/tests_tls_netaccess.uts $UT_FLAGS || exit $? 127 else 128 echo "NOT running TLS netaccess tests" 129 fi 130 131 if [ "$SCAPY_COVERAGE" = "yes" ]; then 132 coverage combine ./ 133 codecov 134 fi 135