1# Report installed versions
2echo "### INSTALLED VERSIONS ###"
3python -c 'import sys; print("sys.path:" , sys.path)'
4for DEPENDENCY in "six" "cryptography" "mock" "pcap" "dnet" "coverage"
5do
6  python -c 'import '$DEPENDENCY'; print("'$DEPENDENCY': "+str(getattr('$DEPENDENCY', "__version__", "no __version__ attribute")))'
7  echo "----"
8done
9
10# Dump environment variables
11echo "SCAPY_SUDO=" $SCAPY_SUDO
12echo "TRAVIS_OS_NAME=" $TRAVIS_OS_NAME
13
14# Dump Scapy config
15python --version
16python -c "from scapy.all import *; print(conf)"
17
18# Don't run tests that require root privileges
19if [ -z "$SCAPY_SUDO" -o "$SCAPY_SUDO" = "false" ]
20then
21  UT_FLAGS="-K netaccess -K needs_root -K manufdb"
22  SCAPY_SUDO=""
23else
24  SCAPY_SUDO="$SCAPY_SUDO -H"
25fi
26
27if [ "$SCAPY_USE_PCAPDNET" = "yes" ]
28then
29  UT_FLAGS+=" -K not_pcapdnet"
30fi
31# IPv6 is not available yet on travis
32UT_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
36UT_FLAGS+=" -K crypto_advanced"
37
38if python --version 2>&1 | grep -q PyPy
39then
40  # cryptography requires PyPy >= 2.6, Travis CI uses 2.5.0
41  UT_FLAGS+=" -K crypto -K not_pypy"
42fi
43
44if python --version 2>&1 | grep -q '^Python 3\.'
45then
46  # Some Python 3 tests currently fail. They should be tracked and
47  # fixed.
48  UT_FLAGS+=" -K FIXME_py3"
49fi
50
51if python --version 2>&1 | grep -q '^Python 3\.[012345]'
52then
53  # Python 3 < 3.6 has weird behavior with random.seed()
54  UT_FLAGS+=" -K random_weird_py3"
55fi
56
57if python --version 2>&1 | grep -q '^Python 3\.[0123]'
58then
59  # cryptography with Python 3 < 3.4 requires 3.3.7, Travis provides 3.3.6
60  UT_FLAGS+=" -K crypto"
61fi
62
63# Set PATH
64## /Users/travis/Library/Python/2.7/bin: pip when non-root on osx
65for _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"
67done
68
69# Create a fake Python executable
70if [ "$SCAPY_COVERAGE" = "yes" ]
71then
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
86else
87  PYTHON="`which python`"
88fi
89
90# Do we have tcpdump or thsark?
91which tcpdump >/dev/null 2>&1 || UT_FLAGS+=" -K tcpdump"
92which tshark >/dev/null 2>&1 || UT_FLAGS+=" -K tshark"
93
94if [ -n "$SCAPY_SUDO" ]
95then
96  SCAPY_SUDO="$SCAPY_SUDO --preserve-env"
97fi
98
99# Dump Environment (so that we can check PATH, UT_FLAGS, etc.)
100set
101
102# Run unit tests
103cd test/
104
105if [ "$TRAVIS_OS_NAME" = "osx" ]
106then
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"
112fi
113
114if [ "$TRAVIS_OS_NAME" = "linux" ]
115then
116  UT_FLAGS+=" -K osx"
117fi
118
119# Run all normal and contrib tests
120PYTHON="$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
123if [ "$TRAVIS_OS_NAME" = "linux" ] && [ -n "$SCAPY_SUDO" ]
124then
125  echo "Running TLS netaccess tests"
126  PYTHON="$PYTHON" $SCAPY_SUDO ./run_tests -q -F -t tls/tests_tls_netaccess.uts $UT_FLAGS || exit $?
127else
128  echo "NOT running TLS netaccess tests"
129fi
130
131if [ "$SCAPY_COVERAGE" = "yes" ]; then
132  coverage combine ./
133  codecov
134fi
135