-
Notifications
You must be signed in to change notification settings - Fork 6
Unit Test Coverage Reporting
Bryce Salmi edited this page Feb 28, 2018
·
3 revisions
To manually unit test and provide code coverage report on a local computer, run the following command:
sudo .venv/bin/pytest --cov faradayio
This currently fails on local builds with:
(.venv) bryce@bryce-ubuntu:~/Documents/git/faradayio$ sudo .venv/bin/pytest --cov faradayio
============================= test session starts ==============================
platform linux -- Python 3.5.2, pytest-3.3.2, py-1.5.2, pluggy-0.6.0
rootdir: /home/bryce/Documents/git/faradayio, inifile:
plugins: cov-2.5.1
collected 37 items
tests/test_serial.py ................................. [ 89%]
tests/test_tun.py ..FF [100%]
----------- coverage: platform linux, python 3.5.2-final-0 -----------
Name Stmts Miss Cover
-------------------------------------------
faradayio/__init__.py 0 0 100%
faradayio/faraday.py 74 26 65%
-------------------------------------------
TOTAL 74 26 65%
=================================== FAILURES ===================================
_______________________________ test_tunSlipSend _______________________________
def test_tunSlipSend():
"""
Test SLIP data sent over the TUN adapter and serial port.
Start a TUN adapter and send data over it while a thread runs to receive
data sent over the tunnel and promptly send it over a serial port which is
running a serial loopback test. Ensures data at the end of the loopback
test is valid when received over serial. This test does not cover serial
to TUN/IP nor IP to TUN data validation.
"""
# Create a test serial port
serialInstance = faraday.SerialTestClass()
serialPort = serialInstance.serialPort
# Configure destination IP:port
destHost = '10.0.0.2'
destPort = 9999
# Start the monitor
isRunning = threading.Event()
isRunning.set()
TUNMonitor = faraday.Monitor(serialPort=serialPort,
isRunning=isRunning)
# Create an IP packet to send from TUN IP:port (arbitrary) to dest IP:port
srcPacket = (IP(dst=destHost,
src=TUNMonitor._TUN._tun.addr) /
UDP(sport=9998,
dport=destPort) / "Hello, world!").__bytes__()
# Use scapy to send packet over Faraday
> sendp(srcPacket, iface=TUNMonitor._TUN._tun.name)
tests/test_tun.py:110:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.5/site-packages/scapy/sendrecv.py:263: in sendp
__gen_send(conf.L2socket(iface=iface, *args, **kargs), x, inter=inter, loop=loop, count=count, verbose=verbose, realtime=realtime)
.venv/lib/python3.5/site-packages/scapy/arch/linux.py:435: in __init__
_flush_fd(self.ins)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
fd = 11
def _flush_fd(fd):
if type(fd) is not int:
fd = fd.fileno()
while 1:
r,w,e = select([fd],[],[],0)
if r:
> os.read(fd,MTU)
E OSError: [Errno 100] Network is down
.venv/lib/python3.5/site-packages/scapy/arch/linux.py:314: OSError
_______________________________ test_serialToTUN _______________________________
def test_serialToTUN():
"""
Test serial port to TUN link. Don't need a serial port but just assume that
an IP packet was received from the serial port and properly decoded with
SLIP. Send it to the TUN and verify that the IP:PORT receives the message.
"""
# Create a test serial port for TUN Monitor class. Won't be used.
serialInstance = faraday.SerialTestClass()
serialPort = serialInstance.serialPort
# Configure TUN IP:PORT and IP Packet source IP:PORT parameters for test
sourceAddress = '10.0.0.2'
sourcePort = 9998
destPort = 9999
# Start a TUN Monitor class
isRunning = threading.Event()
isRunning.set()
TUNMonitor = faraday.Monitor(serialPort=serialPort,
> isRunning=isRunning)
tests/test_tun.py:163:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
faradayio/faraday.py:146: in __init__
mtu=mtu)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <faradayio.faraday.TunnelServer object at 0x7f35bf8814e0>
addr = '10.0.0.1', netmask = '255.255.255.0', mtu = 1500, name = 'Faraday'
def __init__(self, addr,
netmask,
mtu,
name):
> self._tun = pytun.TunTapDevice(name=name)
E pytun.Error: [Errno 16] Device or resource busy
faradayio/faraday.py:99: Error
===================== 2 failed, 35 passed in 0.78 seconds ======================
TUN brought down...
Exception ignored in: <bound method TunnelServer.__del__ of <faradayio.faraday.TunnelServer object at 0x7f35bf8814e0>>
Traceback (most recent call last):
File "/home/bryce/Documents/git/faradayio/faradayio/faraday.py", line 112, in __del__
AttributeError: 'TunnelServer' object has no attribute '_tun'
Need to figure out why
To submit a coveralls
build manually, take note of the API token on the coveralls dashboard for the repository you are working with and use it in the following command:
COVERALLS_REPO_TOKEN=<insert API token here> coveralls
A FaradayRF project - Open Source Digital Radio