Permalink
Browse files

allow to send more than one message

  • Loading branch information...
1 parent 6672773 commit 86a04aa817253848d6f3eb2d863817a56625c499 @tpo committed Jun 19, 2013
Showing with 43 additions and 16 deletions.
  1. +3 −2 README.md
  2. +40 −14 test.py
View
@@ -13,15 +13,16 @@ Wie testen:
3. weitere Hilfe via
python test.py --help
- usage: test.py [-h] [-v] [n_intermediates] [n_sources] [n_sinks]
+ usage: test.py [-h] [-v] [n_intermediates] [n_sources] [n_sinks] [n_messages]
Mesh network test harness. Please edit the variable "implementations" at the
- top of this file to test with additionalmesh implementations.
+ top of this file to test with additional/alternative mesh implementations.
positional arguments:
n_intermediates connecting nodes
n_sources source nodes
n_sinks sink nodes
+ n_messages # of messages to send
optional arguments:
-h, --help show this help message and exit
View
54 test.py
@@ -10,6 +10,7 @@
import subprocess
import time
import select
+from string import find
# add path to your mesh implementation to this array
implementations = [ './meshnode.py' ]
@@ -21,6 +22,9 @@
# must not have a trailing newline
THE_MESSAGE = "detachement and love"
+PASSED = 0
+FAILED = 127
+
be_verbose = False
class MeshNode(object):
@@ -132,9 +136,10 @@ def receive( nodes_sink ):
'additional/alternative mesh implementations.')
parser.add_argument('-v', help='be verbose', dest='be_verbose', action='store_true')
- parser.add_argument('n_intermediates', help="connecting nodes", type=int, nargs='?', default=1)
- parser.add_argument('n_sources', help="source nodes", type=int, nargs='?', default=1)
- parser.add_argument('n_sinks', help="sink nodes", type=int, nargs='?', default=1)
+ parser.add_argument('n_intermediates', help="connecting nodes", type=int, nargs='?', default=1)
+ parser.add_argument('n_sources', help="source nodes", type=int, nargs='?', default=1)
+ parser.add_argument('n_sinks', help="sink nodes", type=int, nargs='?', default=1)
+ parser.add_argument('n_messages', help="# of messages to send", type=int, nargs='?', default=1)
args = parser.parse_args()
@@ -169,25 +174,46 @@ def receive( nodes_sink ):
### do random other interconnects: TODO ##
dbg("sende Daten durch Netz")
- send( THE_MESSAGE, get_random(nodes_source).port )
+ for i in range(args.n_messages):
+ send( THE_MESSAGE + str(i), get_random(nodes_source).port )
dbg("warte, dass Daten Netz durchqueren")
- time.sleep(1)
+ time.sleep(2)
dbg("empfange und ueberpruefe Daten")
- exit_code = 127 # fail
- message = receive( nodes_sink )
- if message == THE_MESSAGE:
- print "Test passed"
- exit_code = 0
- else:
- print "Test failed"
- print "Expected: " + THE_MESSAGE
- print "Received: " + message
+ messages = []
+ for i in range(args.n_messages):
+ messages.append( receive( nodes_sink ) )
+
+ exit_code = PASSED
+
+ for i in range(args.n_messages):
+
+ needed_message = THE_MESSAGE + str(i)
+ message_found = False
+
+ for m in range(args.n_messages):
+ if messages[m] == needed_message:
+ message_found = True
+ break
+
+ if message_found == False:
+ print "Failed to find message '" + needed_message + "'"
+ exit_code = FAILED
dbg("beende Knoten")
for node in nodes_all:
node.proc.terminate()
node.proc.wait()
+ if exit_code == FAILED:
+ print "Test failed"
+ print "I've received to following messages:"
+
+ for i in range(args.n_messages):
+ print messages[i]
+
+ else:
+ print "Test passed"
+
exit(exit_code)

0 comments on commit 86a04aa

Please sign in to comment.