Skip to content

Commit

Permalink
fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
polybassa committed Sep 23, 2024
1 parent 57cd90f commit 1b12525
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
1 change: 1 addition & 0 deletions test/contrib/automotive/scanner/enumerator.uts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class MockISOTPSocket(SuperSocket):
return len(sx)
@staticmethod
def select(sockets, remain=None):
time.sleep(0)
return sockets

sock = MockISOTPSocket()
Expand Down
80 changes: 43 additions & 37 deletions test/sendsniff.uts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
+ Test bridge_and_sniff() using tap sockets

~ tap

= Create two tap interfaces

import subprocess
from threading import Thread

tap0, tap1 = [TunTapInterface("tap%d" % i) for i in range(2)]

chk_kwargs = {"timeout": 3}
Expand Down Expand Up @@ -264,43 +268,6 @@ with VEthPair('a_0', 'a_1') as veth_0:
assert (xfrm_count['b_0'] == 2)


= sr() performance test

import subprocess
import shlex

try:
# Create a dedicated network name space to simulate remote host
subprocess.check_call(shlex.split("sudo ip netns add scapy"))
# Create a virtual Ethernet pair to connect default and new NS
subprocess.check_call(shlex.split("sudo ip link add type veth"))
# Move veth1 to the new NS
subprocess.check_call(shlex.split("sudo ip link set veth1 netns scapy"))
# Setup vNIC in the default NS
subprocess.check_call(shlex.split("sudo ip link set veth0 up"))
subprocess.check_call(shlex.split("sudo ip addr add 192.168.168.1/24 dev veth0"))
# Setup vNIC in the dedicated NS
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set lo up"))
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set veth1 up"))
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip addr add 192.168.168.2/24 dev veth1"))
# Perform test
conf.route.resync()
res, unansw = sr(IP(dst='192.168.168.2') / ICMP(seq=(1, 1000)), timeout=1, verbose=False)
finally:
try:
# Bring down the interfaces
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set veth1 down"))
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set lo down"))
# Delete the namespace
subprocess.check_call(shlex.split("sudo ip netns delete scapy"))
# Remove the virtual Ethernet pair
subprocess.check_call(shlex.split("sudo ip link delete veth0"))
except subprocess.CalledProcessError as e:
print(f"Error during cleanup: {e}")

len(res) == 1000


############
############
+ Test arpleak() using a tap socket
Expand Down Expand Up @@ -428,3 +395,42 @@ finally:
e = os.system("ip netns del blob1")
conf.ifaces.reload()
conf.route.resync()


= sr() performance test
~ linux needs_root veth

import subprocess
import shlex

try:
# Create a dedicated network name space to simulate remote host
subprocess.check_call(shlex.split("sudo ip netns add scapy"))
# Create a virtual Ethernet pair to connect default and new NS
subprocess.check_call(shlex.split("sudo ip link add type veth"))
# Move veth1 to the new NS
subprocess.check_call(shlex.split("sudo ip link set veth1 netns scapy"))
# Setup vNIC in the default NS
subprocess.check_call(shlex.split("sudo ip link set veth0 up"))
subprocess.check_call(shlex.split("sudo ip addr add 192.168.168.1/24 dev veth0"))
# Setup vNIC in the dedicated NS
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set lo up"))
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set veth1 up"))
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip addr add 192.168.168.2/24 dev veth1"))
# Perform test
conf.route.resync()
res, unansw = sr(IP(dst='192.168.168.2') / ICMP(seq=(1, 1000)), timeout=1, verbose=False)
finally:
try:
# Bring down the interfaces
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set veth1 down"))
subprocess.check_call(shlex.split("sudo ip netns exec scapy ip link set lo down"))
# Delete the namespace
subprocess.check_call(shlex.split("sudo ip netns delete scapy"))
# Remove the virtual Ethernet pair
subprocess.check_call(shlex.split("sudo ip link delete veth0"))
except subprocess.CalledProcessError as e:
print(f"Error during cleanup: {e}")

len(res) == 1000

0 comments on commit 1b12525

Please sign in to comment.