From d0ae9f329685a19136cfd9a890b305db3bc384b9 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 30 Jun 2022 12:11:59 +0200 Subject: Improve tests --- tests/api_send_eth0_1s1r/out | 11 +++++++++++ tests/api_send_eth0_1s1r/receiver.py | 20 ++++++++++++++++++++ tests/api_send_eth0_1s1r/sender.py | 7 +++++++ tests/api_send_eth0_1s1r/simulator.py | 14 ++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 tests/api_send_eth0_1s1r/out create mode 100644 tests/api_send_eth0_1s1r/receiver.py create mode 100644 tests/api_send_eth0_1s1r/sender.py create mode 100755 tests/api_send_eth0_1s1r/simulator.py (limited to 'tests/api_send_eth0_1s1r') diff --git a/tests/api_send_eth0_1s1r/out b/tests/api_send_eth0_1s1r/out new file mode 100644 index 0000000..1634d95 --- /dev/null +++ b/tests/api_send_eth0_1s1r/out @@ -0,0 +1,11 @@ +[t=0.000,src=n0] Send 1 bytes to n1 on eth0 +[t=1.000,src=n1] Receive 1 bytes on eth0 +[t=1.000,src=n1] Received: Hello World! +[t=1.000,src=n0] Send 1 bytes to n1 on eth0 +[t=2.000,src=n1] Receive 1 bytes on eth0 +[t=3.000,src=n0] Send 1 bytes to n1 on eth0 +[t=3.000,src=n1] Received: Hello World! +[t=3.000,src=n1] Turned off +[t=4.000,src=n1] Turned on +[t=5.000,src=n1] Receive failed code=-1 +[t=5.000,src=esds] Simulation ends diff --git a/tests/api_send_eth0_1s1r/receiver.py b/tests/api_send_eth0_1s1r/receiver.py new file mode 100644 index 0000000..96305bf --- /dev/null +++ b/tests/api_send_eth0_1s1r/receiver.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +def execute(api): + ##### Simple receive + code, data=api.receive("eth0") + msg="Received: "+data if code == 0 else "Receive failed code="+str(code) + api.log(msg) + ##### Test if we still receive the data when we are not receiving + api.wait(2) + code, data=api.receive("eth0") + msg="Received: "+data if code == 0 else "Receive failed code="+str(code) + api.log(msg) + ##### Ensure data is not receive when turned off + api.turn_off() + api.wait(1) + api.turn_on() + code, data=api.receivet("eth0",1) + msg="Received: "+data if code == 0 else "Receive failed code="+str(code) + api.log(msg) + diff --git a/tests/api_send_eth0_1s1r/sender.py b/tests/api_send_eth0_1s1r/sender.py new file mode 100644 index 0000000..9f4aa85 --- /dev/null +++ b/tests/api_send_eth0_1s1r/sender.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +def execute(api): + api.send("eth0","Hello World!",1,1) + api.send("eth0","Hello World!",1,1) + api.wait(1) # Goto 3 seconds + api.send("eth0","Hello World!",1,1) diff --git a/tests/api_send_eth0_1s1r/simulator.py b/tests/api_send_eth0_1s1r/simulator.py new file mode 100755 index 0000000..ae5bbea --- /dev/null +++ b/tests/api_send_eth0_1s1r/simulator.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +# Load ESDS +import esds +import numpy as np + +B=np.full((2,2),8) +L=np.full((2,2),0) +s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}}) + +s.create_node("sender") +s.create_node("receiver") + +s.run() -- cgit v1.2.3