11#!/usr/bin/env python
22import time
3+ import random
34import re
45import subprocess
56import signal
89def run (cmd , verbose = False , ** kwargs ):
910 if verbose :
1011 print " [s] Running %r" % (cmd ,)
11- p = subprocess .Popen (cmd .split (), stdout = subprocess .PIPE , ** kwargs )
12+ p = subprocess .Popen (cmd .split (),
13+ stdout = subprocess .PIPE ,
14+ ** kwargs )
1215 p .wait ()
1316
1417 if verbose :
@@ -23,7 +26,10 @@ def run(cmd, verbose=False, **kwargs):
2326def spawn (cmd , verbose = False , ** kwargs ):
2427 if verbose :
2528 print " [r] Waiting for %r" % (cmd ,)
26- p = subprocess .Popen (cmd .split (), stdout = subprocess .PIPE , stderr = subprocess .PIPE , ** kwargs )
29+ p = subprocess .Popen (cmd .split (),
30+ stdout = subprocess .PIPE ,
31+ stderr = subprocess .PIPE ,
32+ ** kwargs )
2733 time .sleep (0.4 )
2834 return p
2935
@@ -66,20 +72,35 @@ def gen(prog, arg="", **kwargs):
6672
6773tests = {
6874 'tut1' : (gen ('send' ), gen ('receive' , java = 'Recv' ), 'Hello World!' ),
69- 'tut2' : (gen ('new_task' , arg = 'xxxxxx ' ), gen ('worker' ), 'xxxxxx ' ),
70- 'tut3' : (gen ('emit_log' , arg = '123456 ' ), gen ('receive_logs' ), '123456 ' ),
75+ 'tut2' : (gen ('new_task' , arg = '%(arg)s ' ), gen ('worker' ), '%(arg)s ' ),
76+ 'tut3' : (gen ('emit_log' , arg = '%(arg)s ' ), gen ('receive_logs' ), '%(arg)s ' ),
7177 }
7278
7379
7480verbose = len (sys .argv ) > 1
81+ errors = 0
7582
7683for test in sorted (tests .keys ()):
77- (send_progs , recv_progs , mask ) = tests [test ]
78- for scwd , scmd in send_progs :
79- for rcwd , rcmd in recv_progs :
84+ (send_progs , recv_progs , output_mask ) = tests [test ]
85+ for scwd , send_cmd in send_progs :
86+ for rcwd , recv_cmd in recv_progs :
87+ ctx = {
88+ 'arg' : 'rand_%s' % (random .randint (1 ,100 ),)
89+ }
90+ rcmd = recv_cmd % ctx
91+ scmd = send_cmd % ctx
92+ mask = output_mask % ctx
8093 p = spawn (rcmd , verbose = verbose , cwd = rcwd )
8194 run (scmd , verbose = verbose , cwd = scwd )
8295 if wait (p , mask , verbose = verbose ):
8396 print " [+] %s %-20s ok" % (test , scwd + '/' + rcwd )
8497 else :
85- print " [!] %s %-20s FAILED %r %r" % (test , scwd + '/' + rcwd , rcmd , scmd )
98+ print " [!] %s %-20s FAILED %r %r" % \
99+ (test , scwd + '/' + rcwd , rcmd , scmd )
100+ errors += 1
101+
102+ if errors :
103+ print " [!] %s tests failed" % (errors ,)
104+
105+ sys .exit (errors )
106+
0 commit comments