From: mart Date: Sun, 15 Nov 2015 17:35:38 +0000 (+0100) Subject: generatie van testkazen erbij, alleen results nog X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=60f999428fcc82cb4fc291daa2bd2db5bc279fe4;p=tt2015.git generatie van testkazen erbij, alleen results nog --- diff --git a/.gitignore b/.gitignore index ce15282..b828972 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,3 @@ -tt.fmt -tt.aux -tt.bbl -tt.blg -tt.log -tt.out -tt.toc -tt.pdf -*.eps - # LaTeX temporary files *.aux *.log @@ -49,4 +39,5 @@ C:\\nppdf32Log\\debuglog.txt # andere binaries *.odt *.pyc +[0-9][0-9].py sn.txt diff --git a/a2/code/client/gen.py b/a2/code/client/gen.py index 1e3bc20..0a8da3a 100644 --- a/a2/code/client/gen.py +++ b/a2/code/client/gen.py @@ -4,15 +4,24 @@ import sys import random import string -def test(corruptDestinationPort, corruptSourcePort, numpackets, payloadsize, outOfOrder, serverPort): +def test( + corruptDestinationPort, + corruptSourcePort, + numSegments, + payloadSize, + outOfOrder, + expectedResult, + serverPort): msgs = [] ownSeqnr = 101 # Make the messages - for _ in range(numpackets): - #msgs.append((ownSeqnr, ''.join(random.choice(string.ascii_letters) for _ in range(payloadsize)))) - msgs.append((ownSeqnr, ''.join(random.choice(string.ascii_letters) for _ in range(payloadsize)))) - ownSeqnr += payloadsize + for _ in range(numSegments): + msgs.append(( + ownSeqnr, + ''.join(random.choice(string.ascii_letters) for _ in + range(payloadSize)))) + ownSeqnr += payloadSize # Out of order if outOfOrder and len(msgs) > 1: @@ -21,7 +30,13 @@ def test(corruptDestinationPort, corruptSourcePort, numpackets, payloadsize, out msgs[indexes[0]], msgs[indexes[1]] = msgs[indexes[1]], msgs[indexes[0]] print msgs - sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=0) + sender = Sender( + serverIP="127.0.0.1", + networkInterface="lo", + isLocal=True, + serverPort=serverPort, + waitTime=1, + isVerbose=0) # isLocal is True if the interface is a local one response = sender.sendInput("S", 100, 100) @@ -33,9 +48,11 @@ def test(corruptDestinationPort, corruptSourcePort, numpackets, payloadsize, out # an example for the echo handling server if sender.isTimeout == False: # in case something was received #print 'swapped {} {}'.format(indexes[0], indexes[1]) - corruptDestinationPort = -1 if not corruptDestinationPort else random.randint(0, len(msgs)) + corruptDestinationPort = \ + -1 if not corruptDestinationPort else random.randint(0, len(msgs)) oldDestinationPort = sender.serverPort - corruptSourcePort = -1 if not corruptSourcePort else random.randint(0, len(msgs)) + corruptSourcePort = \ + -1 if not corruptSourcePort else random.randint(0, len(msgs)) oldSourcePort = sender.senderPort for i, (seq, m) in enumerate(msgs): if i == corruptDestinationPort: @@ -47,18 +64,32 @@ def test(corruptDestinationPort, corruptSourcePort, numpackets, payloadsize, out sender.senderPort = sender.senderPort+1 else: sender.senderPort = oldSourcePort - sender.sendInput("A", seq, sender.lastSeqReceived + 1, None) # send some data - sender.sendInput("PA", seq, sender.lastSeqReceived + 1, m) # send some data + print sender.sendInput("A", seq, sender.lastSeqReceived + 1, None) + print sender.sendInput("PA", seq, sender.lastSeqReceived + 1, m) - print 'response: ', sender.sendInput("FA", ownSeqnr, sender.lastSeqReceived + 1) # close connection (the echo also closes) - print 'response: ', sender.sendInput("RP", ownSeqnr+1, 0) # reset connection + print sender.sendInput("FA", ownSeqnr, sender.lastSeqReceived + 1) + print sender.sendInput("RP", ownSeqnr+1, 0) sender.sendReset() # switch sender port print 'Succes!' - if __name__ == '__main__': serverPort = 10000 if len(sys.argv) > 1: serverPort = int(sys.argv[1]) - test(corruptDestinationPort=False, corruptSourcePort=False, numpackets=2, payloadsize=1, outOfOrder=False, serverPort=serverPort) + tcs = [ + {'expectedResult': [], + 'numSegments': 0, + 'corruptDestinationPort': False, + 'corruptSourcePort': False, + 'payloadSize': 0, + 'outOfOrder': False}, + ] + for i, d in enumerate(tcs, 1): + with open('{:02d}.py'.format(i), 'w') as f: + f.write("""\ +#!/usr/bin/python +import gen +gen.test({}, serverPort={}) +""".format(', '.join('{}={}'.format(k, v) for k, v in d.items()), serverPort)) + print 'Testkaas {} geschreven'.format(i) diff --git a/a2/code/setup/iptables.sh b/a2/code/setup/iptables.sh old mode 100644 new mode 100755