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