1#!/bin/bash 2 3# SPDX-License-Identifier: GPL-2.0-only 4# This file is part of Scapy 5# See https://scapy.net/ for more information 6 7# test.sh 8# Usage: 9# ./test.sh [tox version] [both/root/non_root (default root)] 10# Examples: 11# ./test.sh 3.7 both 12# ./test.sh 3.9 non_root 13 14if [ "$OSTYPE" = "linux-gnu" ] 15then 16 # Linux 17 OSTOX="linux" 18 UT_FLAGS+=" -K tshark" 19 if [ -z "$SIMPLE_TESTS" ] 20 then 21 # check vcan 22 sudo modprobe -n -v vcan 23 if [[ $? -ne 0 ]] 24 then 25 # The vcan module is currently unavailable on xenial builds 26 UT_FLAGS+=" -K vcan_socket" 27 fi 28 else 29 UT_FLAGS+=" -K vcan_socket" 30 fi 31elif [[ "$OSTYPE" = "darwin"* ]] || [[ "$OSTYPE" = "FreeBSD" ]] || [[ "$OSTYPE" = *"bsd"* ]] 32then 33 OSTOX="bsd" 34 # Travis CI in macOS 10.13+ can't load kexts. Need this for tuntaposx. 35 UT_FLAGS+=" -K tun -K tap" 36 if [[ "$OSTYPE" = "openbsd"* ]] 37 then 38 # Note: LibreSSL 3.6.* does not support X25519 according to 39 # the cryptogaphy module source code 40 UT_FLAGS+=" -K libressl" 41 fi 42fi 43 44if [ ! -z "$GITHUB_ACTIONS" ] 45then 46 # Due to a security policy, the firewall of the Azure runner 47 # (Standard_DS2_v2) that runs Github Actions on Linux blocks ICMP. 48 UT_FLAGS+=" -K icmp_firewall" 49fi 50 51# pypy 52if python --version 2>&1 | grep -q PyPy 53then 54 UT_FLAGS+=" -K not_pypy" 55 # Code coverage with PyPy makes it very, very slow. Tests work 56 # but take around 30minutes, so we disable it. 57 export DISABLE_COVERAGE=" " 58fi 59 60# macos -k scanner has glitchy coverage. skip it 61if [ "$OSTOX" = "bsd" ] && [[ "$UT_FLAGS" = *"-k scanner"* ]]; then 62 export DISABLE_COVERAGE=" " 63fi 64 65# libpcap 66if [[ ! -z "$SCAPY_USE_LIBPCAP" ]]; then 67 UT_FLAGS+=" -K veth" 68fi 69 70# Create version tag (github actions) 71PY_VERSION="py${1//./}" 72PY_VERSION=${PY_VERSION/pypypy/pypy} 73TESTVER="$PY_VERSION-$OSTOX" 74 75# Chose whether to run root or non_root 76SCAPY_TOX_CHOSEN=${2} 77if [ "${SCAPY_TOX_CHOSEN}" == "" ] 78then 79 case ${PY_VERSION} in 80 py27|py38) 81 SCAPY_TOX_CHOSEN="both" 82 ;; 83 *) 84 SCAPY_TOX_CHOSEN="root" 85 esac 86fi 87 88if [ -z $TOXENV ] 89then 90 case ${SCAPY_TOX_CHOSEN} in 91 both) 92 export TOXENV="${TESTVER}-non_root,${TESTVER}-root" 93 ;; 94 root) 95 export TOXENV="${TESTVER}-root" 96 ;; 97 *) 98 export TOXENV="${TESTVER}-non_root" 99 ;; 100 esac 101fi 102 103# Configure OpenSSL 104export OPENSSL_CONF=$(${PYTHON:=python} `dirname $BASH_SOURCE`/openssl.py) 105 106# Dump vars (environment is already entirely dumped in install.sh) 107echo OSTOX=$OSTOX 108echo UT_FLAGS=$UT_FLAGS 109echo TOXENV=$TOXENV 110echo OPENSSL_CONF=$OPENSSL_CONF 111echo OPENSSL_VER=$(openssl version) 112echo COVERAGE=$([ -z "$DISABLE_COVERAGE" ] && echo "enabled" || echo "disabled") 113 114if [ "$OSTYPE" = "linux-gnu" ] 115then 116 echo SMBCLIENT=$(smbclient -V) 117fi 118 119# Launch Scapy unit tests 120# export TOX_PARALLEL_NO_SPINNER=1 121tox -- ${UT_FLAGS} || exit 1 122 123# Stop if NO_BASH_TESTS is set 124if [ ! -z "$SIMPLE_TESTS" ] 125then 126 exit $? 127fi 128 129# Start Scapy in interactive mode 130TEMPFILE=$(mktemp) 131cat <<EOF > "${TEMPFILE}" 132print("Scapy on %s" % sys.version) 133sys.exit() 134EOF 135echo "DEBUG: TEMPFILE=${TEMPFILE}" 136./run_scapy -H -c "${TEMPFILE}" || exit 1 137