Skip to content

Commit

Permalink
Minor tests & coverage fixes (#3924)
Browse files Browse the repository at this point in the history
* Lord of the fix: The Return of the tests

* Various minor test fixes

* Appveyor: use new codecov

* Better codecov rules
  • Loading branch information
gpotter2 committed Mar 9, 2023
1 parent 378be02 commit 181aa4d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ test_script:

after_test:
# Run codecov
- "%PYTHON%\\python -m tox -e codecov"
- ps: $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe
- codecov.exe
10 changes: 3 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,14 @@ version = { attr="scapy.VERSION" }

# coverage

[tool.coverage]
concurrency = "multiprocessing"
[tool.coverage.run]
concurrency = [ "thread", "multiprocessing" ]
source = [ "scapy" ]
omit = [
# Scapy specific paths
"scapy/tools/UTscapy.py",
"test/*",
# Scapy external modules
"scapy/libs/six.py",
"scapy/libs/winpcapy.py",
"scapy/libs/ethertypes.py",
# .tox specific path
".tox/*",
# OS specific paths
"/private/*",
]
1 change: 1 addition & 0 deletions test/imports.uts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Import tests
~ not_pypy

+ Import tests
~ imports
Expand Down
17 changes: 10 additions & 7 deletions test/linux.uts
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,14 @@ with patch("scapy.layers.l2.get_if_hwaddr") as mgih:
conf.iface = bck_conf_iface
conf.route6.resync()

= IPv6
~ linux
= IPv6 - check OS routes
~ linux ipv6

addrs = in6_getifaddr()
if len(addrs) == 0:
assert True
else:
assert all([in6_isvalid(addr[0]) for addr in in6_getifaddr()])
assert set([addr[2] for addr in in6_getifaddr()]) == conf.route6.ipv6_ifaces
if addrs:
assert all(in6_isvalid(addr[0]) for addr in in6_getifaddr()), 'invalid ipv6 address'
ifaces6 = [addr[2] for addr in in6_getifaddr()]
assert all(iface in ifaces6 for iface in conf.route6.ipv6_ifaces), 'ipv6 interface has route but no real'


= veth interface error handling
Expand Down Expand Up @@ -314,8 +313,12 @@ assert _interface_selection(None, IP(dst="8.8.8.8")/UDP()) == conf.iface
exit_status = os.system("ip link add name scapy0 type dummy")
exit_status = os.system("ip addr add 192.0.2.1/24 dev scapy0")
exit_status = os.system("ip link set scapy0 up")
conf.ifaces.reload()
conf.route.resync()
assert _interface_selection(None, IP(dst="192.0.2.42")/UDP()) == "scapy0"
exit_status = os.system("ip link del name dev scapy0")
conf.ifaces.reload()
conf.route.resync()

= Test 802.Q sniffing
~ linux needs_root veth
Expand Down
3 changes: 2 additions & 1 deletion test/pipetool.uts
Original file line number Diff line number Diff line change
Expand Up @@ -720,5 +720,6 @@ s.send(bytes(HTTP()/HTTPRequest(Host="www.google.com")))
result = c.q.get(timeout=10)
p.stop()

assert result.startswith(b"HTTP/1.1 200 OK")
result
assert result.startswith(b"HTTP/1.1 200 OK") or result.startswith(b"HTTP/1.1 302 Found")

2 changes: 1 addition & 1 deletion test/regression.uts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ except:
assert not conf.use_bpf

= Configuration conf.use_pcap
~ linux
~ linux libpcap

if not conf.use_pcap:
assert not conf.iface.provider.libpcap
Expand Down
21 changes: 4 additions & 17 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


[tox]
envlist = py{27,34,35,36,37,38,39,310,py27,py39}-{linux,bsd}_{non_root,root},
py{27,34,35,36,37,38,39,310,py27,py39}-windows,
envlist = py{27,34,35,36,37,38,39,310,311,py27,py39}-{linux,bsd}_{non_root,root},
py{27,34,35,36,37,38,39,310,311,py27,py39}-windows,
skip_missing_interpreters = true
minversion = 4.0

Expand Down Expand Up @@ -44,6 +44,7 @@ commands =
bsd_non_root: {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c test/configs/bsd.utsc -K manufdb -K tshark -N {posargs}
bsd_root: sudo -E {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c test/configs/bsd.utsc -K manufdb -K tshark {posargs}
windows: {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c test/configs/windows.utsc {posargs}
coverage combine
coverage xml -i

# Variants of the main tests
Expand Down Expand Up @@ -72,6 +73,7 @@ commands =
bash -c "rm -rf /tmp/can-utils /tmp/can-isotp"
lsmod
sudo -E {envpython} -m coverage run -m scapy.tools.UTscapy -c ./test/configs/linux.utsc {posargs}
coverage combine
coverage xml -i

# Test used by upstream pyca/cryptography
Expand All @@ -83,21 +85,6 @@ commands =
python -c "import cryptography; print('DEBUG: cryptography %s' % cryptography.__version__)"
python -m scapy.tools.UTscapy -c ./test/configs/cryptography.utsc

# Specific functions or tests

[testenv:codecov]
description = "Upload coverage results to codecov"
passenv =
TOXENV
CI
TRAVIS
TRAVIS_*
APPVEYOR
APPVEYOR_*
deps = codecov
commands = codecov -e TOXENV


# The files listed past the first argument of the sphinx-apidoc command are ignored
[testenv:apitree]
description = "Regenerates the API reference doc tree"
Expand Down

0 comments on commit 181aa4d

Please sign in to comment.