test: regroup model tests in test_model and run it with Travis-CI

This commit is contained in:
Florent Kermarrec 2019-11-23 14:55:38 +01:00
parent 7f31186b8c
commit 36c9951235
8 changed files with 169 additions and 169 deletions

View File

@ -2,14 +2,6 @@ PYTHON = python3
CMD = $(PYTHON)
model_tb:
cd ../ && PYTHONPATH=./ $(CMD) test/model/mac.py
cd ../ && PYTHONPATH=./ $(CMD) test/model/arp.py
cd ../ && PYTHONPATH=./ $(CMD) test/model/ip.py
cd ../ && PYTHONPATH=./ $(CMD) test/model/udp.py
cd ../ && PYTHONPATH=./ $(CMD) test/model/icmp.py
cd ../ && PYTHONPATH=./ $(CMD) test/model/etherbone.py
examples:
cd ../examples && $(PYTHON) make.py -t base -s BaseSoC -p kc705 -Ob run False build-bitstream
cd ../examples && $(PYTHON) make.py -t base -s BaseSoCDevel -p kc705 -Ob run False build-bitstream
@ -20,4 +12,4 @@ examples:
cd ../examples && $(PYTHON) make.py -t tty -s TTYSoC -p kc705 -Ob run False build-bitstream
cd ../examples && $(PYTHON) make.py -t tty -s TTYSoCDevel -p kc705 -Ob run False build-bitstream
all: model_tb examples
all: examples

View File

@ -125,37 +125,3 @@ class ARP(Module):
request.sender_ip = self.ip_address
request.target_mac = 0xffffffffffff
request.target_ip = ip_address
if __name__ == "__main__":
from test.model.dumps import *
from test.model.mac import *
errors = 0
# ARP request
packet = MACPacket(arp_request)
packet.decode_remove_header()
packet = ARPPacket(packet)
# check decoding
packet.decode()
# print(packet)
errors += verify_packet(packet, arp_request_infos)
# check encoding
packet.encode()
packet.decode()
# print(packet)
errors += verify_packet(packet, arp_request_infos)
# ARP Reply
packet = MACPacket(arp_reply)
packet.decode_remove_header()
packet = ARPPacket(packet)
# check decoding
packet.decode()
# print(packet)
errors += verify_packet(packet, arp_reply_infos)
# check encoding
packet.encode()
packet.decode()
# print(packet)
errors += verify_packet(packet, arp_reply_infos)
print("arp errors " + str(errors))

View File

@ -2,7 +2,6 @@
# License: BSD
import math
import copy
from litex.soc.interconnect.stream_sim import *
from litex.tools.remote.etherbone import *
@ -56,31 +55,3 @@ class Etherbone(Module):
def process(self, packet):
pass
if __name__ == "__main__":
# Writes/Reads
writes = EtherboneWrites(base_addr=0x1000, datas=[i for i in range(16)])
reads = EtherboneReads(base_ret_addr=0x2000, addrs=[i for i in range(16)])
# Record
record = EtherboneRecord()
record.writes = writes
record.reads = reads
record.wcount = len(writes.get_datas())
record.rcount = len(reads.get_addrs())
# Packet
packet = EtherbonePacket()
packet.records = [deepcopy(record) for i in range(8)]
# print(packet)
packet.encode()
# print(packet)
# Send packet over UDP to check against Wireshark dissector
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(bytes(packet), ("192.168.1.1", 20000))
packet = EtherbonePacket(packet)
packet.decode()
print(packet)

View File

@ -86,26 +86,3 @@ class ICMP(Module):
def process(self, packet):
pass
if __name__ == "__main__":
from test.model.dumps import *
from test.model.mac import *
from test.model.ip import *
errors = 0
# ICMP packet
packet = MACPacket(ping_request)
packet.decode_remove_header()
# print(packet)
packet = IPPacket(packet)
packet.decode()
# print(packet)
packet = ICMPPacket(packet)
packet.decode()
# print(packet)
errors += verify_packet(packet, ping_request_infos)
packet.encode()
packet.decode()
# print(packet)
errors += verify_packet(packet, ping_request_infos)
print("icmp errors " + str(errors))

View File

@ -133,27 +133,3 @@ class IP(Module):
elif packet.protocol == icmp_protocol:
if self.icmp_callback is not None:
self.icmp_callback(packet)
if __name__ == "__main__":
from test.model.dumps import *
from test.model.mac import *
errors = 0
# UDP packet
packet = MACPacket(udp)
packet.decode_remove_header()
# print(packet)
packet = IPPacket(packet)
# check decoding
errors += not packet.check_checksum()
packet.decode()
# print(packet)
errors += verify_packet(packet, {})
# check encoding
packet.encode()
packet.insert_checksum()
errors += not packet.check_checksum()
packet.decode()
# print(packet)
errors += verify_packet(packet, {})
print("ip errors " + str(errors))

View File

@ -136,26 +136,3 @@ class MAC(Module):
self.arp_callback(packet)
else:
raise ValueError # XXX handle this properly
if __name__ == "__main__":
from test.model.dumps import *
errors = 0
packet = MACPacket(arp_request)
packet.decode_remove_header()
# print(packet)
errors += verify_packet(packet, arp_request_infos)
packet.encode_header()
packet.decode_remove_header()
# print(packet)
errors += verify_packet(packet, arp_request_infos)
# print(packet)
packet = MACPacket(arp_reply)
packet.decode_remove_header()
errors += verify_packet(packet, arp_reply_infos)
packet.encode_header()
packet.decode_remove_header()
# print(packet)
errors += verify_packet(packet, arp_reply_infos)
print("mac errors " + str(errors))

View File

@ -97,30 +97,3 @@ class UDP(Module):
if packet.dst_port == 20000:
if self.etherbone_callback is not None:
self.etherbone_callback(packet)
if __name__ == "__main__":
from test.model.dumps import *
from test.model.mac import *
from test.model.ip import *
errors = 0
# UDP packet
packet = MACPacket(udp)
packet.decode_remove_header()
# print(packet)
packet = IPPacket(packet)
packet.decode()
# print(packet)
packet = UDPPacket(packet)
packet.decode()
# print(packet)
if packet.length != (len(packet)+udp_header.length):
errors += 1
errors += verify_packet(packet, udp_infos)
packet.encode()
packet.decode()
# print(packet)
if packet.length != (len(packet)+udp_header.length):
errors += 1
errors += verify_packet(packet, udp_infos)
print("udp errors " + str(errors))

168
test/test_model.py Normal file
View File

@ -0,0 +1,168 @@
# This file is Copyright (c) 2015-2019 Florent Kermarrec <florent@enjoy-digital.fr>
# License: BSD
import unittest
from liteeth.common import *
from test.model.dumps import *
from test.model.mac import MACPacket
from test.model.arp import ARPPacket
from test.model.ip import IPPacket
from test.model.icmp import ICMPPacket
from test.model.udp import UDPPacket
from litex.tools.remote.etherbone import *
from test.model.etherbone import Etherbone
class TestModel(unittest.TestCase):
def test_mac(self):
errors = 0
packet = MACPacket(arp_request)
packet.decode_remove_header()
# print(packet)
errors += verify_packet(packet, arp_request_infos)
packet.encode_header()
packet.decode_remove_header()
# print(packet)
errors += verify_packet(packet, arp_request_infos)
# print(packet)
packet = MACPacket(arp_reply)
packet.decode_remove_header()
errors += verify_packet(packet, arp_reply_infos)
packet.encode_header()
packet.decode_remove_header()
# print(packet)
errors += verify_packet(packet, arp_reply_infos)
self.assertEqual(errors, 0)
def test_arp(self):
errors = 0
# ARP request
packet = MACPacket(arp_request)
packet.decode_remove_header()
packet = ARPPacket(packet)
# check decoding
packet.decode()
# print(packet)
errors += verify_packet(packet, arp_request_infos)
# check encoding
packet.encode()
packet.decode()
# print(packet)
errors += verify_packet(packet, arp_request_infos)
# ARP Reply
packet = MACPacket(arp_reply)
packet.decode_remove_header()
packet = ARPPacket(packet)
# check decoding
packet.decode()
# print(packet)
errors += verify_packet(packet, arp_reply_infos)
# check encoding
packet.encode()
packet.decode()
# print(packet)
errors += verify_packet(packet, arp_reply_infos)
self.assertEqual(errors, 0)
def test_ip(self):
errors = 0
# UDP packet
packet = MACPacket(udp)
packet.decode_remove_header()
# print(packet)
packet = IPPacket(packet)
# check decoding
errors += not packet.check_checksum()
packet.decode()
# print(packet)
errors += verify_packet(packet, {})
# check encoding
packet.encode()
packet.insert_checksum()
errors += not packet.check_checksum()
packet.decode()
# print(packet)
errors += verify_packet(packet, {})
self.assertEqual(errors, 0)
def test_icmp(self):
errors = 0
# ICMP packet
packet = MACPacket(ping_request)
packet.decode_remove_header()
# print(packet)
packet = IPPacket(packet)
packet.decode()
# print(packet)
packet = ICMPPacket(packet)
packet.decode()
# print(packet)
errors += verify_packet(packet, ping_request_infos)
packet.encode()
packet.decode()
# print(packet)
errors += verify_packet(packet, ping_request_infos)
self.assertEqual(errors, 0)
def test_udp(self):
errors = 0
# UDP packet
packet = MACPacket(udp)
packet.decode_remove_header()
# print(packet)
packet = IPPacket(packet)
packet.decode()
# print(packet)
packet = UDPPacket(packet)
packet.decode()
# print(packet)
if packet.length != (len(packet)+udp_header.length):
errors += 1
errors += verify_packet(packet, udp_infos)
packet.encode()
packet.decode()
# print(packet)
if packet.length != (len(packet)+udp_header.length):
errors += 1
errors += verify_packet(packet, udp_infos)
self.assertEqual(errors, 0)
def test_etherbone(self):
# Writes/Reads
writes = EtherboneWrites(base_addr=0x1000, datas=[i for i in range(16)])
reads = EtherboneReads(base_ret_addr=0x2000, addrs=[i for i in range(16)])
# Record
record = EtherboneRecord()
record.writes = writes
record.reads = reads
record.wcount = len(writes.get_datas())
record.rcount = len(reads.get_addrs())
# Packet
packet = EtherbonePacket()
from copy import deepcopy
packet.records = [deepcopy(record) for i in range(8)]
# print(packet)
packet.encode()
# print(packet)
# Send packet over UDP to check against Wireshark dissector
#import socket
#sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#sock.sendto(bytes(packet), ("192.168.1.1", 20000))
packet = EtherbonePacket(packet)
packet.decode()
print(packet)
self.assertEqual(0, 0) # FIXME