Commit 5e7c6074 authored by StevenWdV's avatar StevenWdV

Simplified test framework

parent cb86c02e
......@@ -3,6 +3,7 @@ import binascii
import sys
import threading
import unittest
import os
timeout = 100
winsize = 100
......@@ -11,12 +12,10 @@ netem_add = "sudo tc qdisc add dev {} root netem".format(intf)
netem_change = "sudo tc qdisc change dev {} root netem {}".format(intf, "{}")
netem_del = "sudo tc qdisc del dev {} root netem".format(intf)
infile = "20190216_214527.zip" # TODO
infile = "in.txt"
outfile = "out.txt"
server_finished = False
wait_server_lock = threading.Lock()
wait_server = threading.Condition(wait_server_lock)
server_thread: threading.Thread
def run_command_with_output(command, input=None, cwd=None, shell=True):
......@@ -53,26 +52,14 @@ def run_command(command, cwd=None, shell=True):
print("2. problem running command : \n ", str(command), " ", process.returncode)
def run_server_wait() -> None:
global server_finished
server_finished = False
run_command_with_output(run_server)
wait_server_lock.acquire()
server_finished = True
wait_server.notify()
wait_server_lock.release()
def transfer_file() -> None:
# launch localhost client connecting to server
# client sends content to server
# server receives content from client
run_command_with_output(run_client)
wait_server_lock.acquire()
wait_server.wait_for(lambda: server_finished)
wait_server_lock.release()
global server_thread
server_thread.join()
# content received by server matches the content sent by client
file = open(infile, "r+b")
......@@ -94,8 +81,15 @@ class TestbTCPFramework(unittest.TestCase):
# default netem rule (does nothing)
run_command(netem_add)
try:
os.remove(outfile)
except OSError:
pass
# launch localhost server
threading.Thread(target=run_server_wait).start()
global server_thread
server_thread = threading.Thread(target=lambda: run_command_with_output(run_server))
server_thread.start()
def tearDown(self):
"""Clean up after testing"""
......@@ -105,6 +99,11 @@ class TestbTCPFramework(unittest.TestCase):
# close server
# Already done
try:
os.remove(outfile)
except OSError:
pass
def test_ideal_network(self):
print("reliability over an ideal framework")
# setup environment (nothing to set)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment