1616from termcolor import colored
1717
1818import testcases
19+ from docker import DockerRunner
1920from result import TestResult
2021from testcases import Perspective
2122
@@ -98,9 +99,12 @@ def __init__(
9899 self .measurement_results [server ][client ][measurement ] = {}
99100
100101 def _is_unsupported (self , lines : List [str ]) -> bool :
101- return any ("exited with code 127" in str (line ) for line in lines ) or any (
102- "exit status 127" in str (line ) for line in lines
103- )
102+ for line in lines :
103+ if "sim exited with code 127" in str (line ):
104+ continue
105+ if "exited with code 127" in str (line ) or "exit status 127" in str (line ):
106+ return True
107+ return False
104108
105109 def _check_impl_is_compliant (self , name : str ) -> bool :
106110 """ check if an implementation return UNSUPPORTED for unknown test cases """
@@ -121,46 +125,48 @@ def _check_impl_is_compliant(self, name: str) -> bool:
121125
122126 # check that the client is capable of returning UNSUPPORTED
123127 logging .debug ("Checking compliance of %s client" , name )
124- cmd = (
125- "CERTS=" + certs_dir .name + " "
126- "TESTCASE_CLIENT=" + random_string (6 ) + " "
127- "SERVER_LOGS=/dev/null "
128- "CLIENT_LOGS=" + client_log_dir .name + " "
129- "WWW=" + www_dir .name + " "
130- "DOWNLOADS=" + downloads_dir .name + " "
131- 'SCENARIO="simple-p2p --delay=15ms --bandwidth=10Mbps --queue=25" '
132- "CLIENT=" + self ._implementations [name ]["image" ] + " "
133- "docker-compose up --timeout 0 --abort-on-container-exit -V sim client"
134- )
135- output = subprocess .run (
136- cmd , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT
137- )
138- if not self ._is_unsupported (output .stdout .splitlines ()):
128+ env_sim = {"SCENARIO" : "simple-p2p --delay=15ms --bandwidth=10Mbps --queue=25" }
129+ env_client = {
130+ "CERTS" : "./certs" ,
131+ "TESTCASE_CLIENT" : random_string (6 ),
132+ "DOWNLOADS" : downloads_dir .name ,
133+ "CLIENT_LOGS" : client_log_dir .name ,
134+ "CLIENT" : self ._implementations [name ]["image" ],
135+ }
136+ env = {}
137+ env .update (env_sim )
138+ env .update (env_client )
139+ r = DockerRunner (15 )
140+ r .add_container ("client" , env )
141+ r .add_container ("sim" , env )
142+ output , expired = r .run ()
143+ if expired or not self ._is_unsupported (output .splitlines ()):
139144 logging .error ("%s client not compliant." , name )
140- logging .debug ("%s" , output . stdout . decode ( "utf-8" ) )
145+ logging .debug ("%s" , output )
141146 self .compliant [name ] = False
142147 return False
143148 logging .debug ("%s client compliant." , name )
144149
145150 # check that the server is capable of returning UNSUPPORTED
146151 logging .debug ("Checking compliance of %s server" , name )
147152 server_log_dir = tempfile .TemporaryDirectory (dir = "/tmp" , prefix = "logs_server_" )
148- cmd = (
149- "CERTS=" + certs_dir .name + " "
150- "TESTCASE_SERVER=" + random_string (6 ) + " "
151- "SERVER_LOGS=" + server_log_dir .name + " "
152- "CLIENT_LOGS=/dev/null "
153- "WWW=" + www_dir .name + " "
154- "DOWNLOADS=" + downloads_dir .name + " "
155- "SERVER=" + self ._implementations [name ]["image" ] + " "
156- "docker-compose up -V server"
157- )
158- output = subprocess .run (
159- cmd , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT
160- )
161- if not self ._is_unsupported (output .stdout .splitlines ()):
153+ env_server = {
154+ "CERTS" : "./certs" ,
155+ "TESTCASE_SERVER" : random_string (6 ),
156+ "SERVER_LOGS" : server_log_dir .name ,
157+ "WWW" : www_dir .name ,
158+ "SERVER" : self ._implementations [name ]["image" ],
159+ }
160+ env = {}
161+ env .update (env_sim )
162+ env .update (env_server )
163+ r = DockerRunner (15 )
164+ r .add_container ("server" , env )
165+ r .add_container ("sim" , env )
166+ output , expired = r .run ()
167+ if expired or not self ._is_unsupported (output .splitlines ()):
162168 logging .error ("%s server not compliant." , name )
163- logging .debug ("%s" , output . stdout . decode ( "utf-8" ) )
169+ logging .debug ("%s" , output )
164170 self .compliant [name ] = False
165171 return False
166172 logging .debug ("%s server compliant." , name )
@@ -329,74 +335,54 @@ def _run_test(
329335 server_keylog_file = server_log_dir .name + "/keys.log" ,
330336 )
331337 print (
332- "Server: "
333- + server
334- + ". Client: "
335- + client
336- + ". Running test case: "
337- + str (testcase )
338+ "Server: {}. Client: {}. Running test: {}" .format (
339+ server , client , str (testcase )
340+ )
338341 )
339342
340343 reqs = " " .join ([testcase .urlprefix () + p for p in testcase .get_paths ()])
341344 logging .debug ("Requests: %s" , reqs )
342- params = (
343- "WAITFORSERVER=server:443 "
344- "CERTS=" + testcase .certs_dir () + " "
345- "TESTCASE_SERVER=" + testcase .testname (Perspective .SERVER ) + " "
346- "TESTCASE_CLIENT=" + testcase .testname (Perspective .CLIENT ) + " "
347- "WWW=" + testcase .www_dir () + " "
348- "DOWNLOADS=" + testcase .download_dir () + " "
349- "SERVER_LOGS=" + server_log_dir .name + " "
350- "CLIENT_LOGS=" + client_log_dir .name + " "
351- 'SCENARIO="{}" '
352- "CLIENT=" + self ._implementations [client ]["image" ] + " "
353- "SERVER=" + self ._implementations [server ]["image" ] + " "
354- 'REQUESTS="' + reqs + '" '
355- ).format (testcase .scenario ())
356- params += " " .join (testcase .additional_envs ())
357- containers = "sim client server " + " " .join (testcase .additional_containers ())
358- cmd = (
359- params
360- + " docker-compose up --abort-on-container-exit --timeout 1 "
361- + containers
362- )
363- logging .debug ("Command: %s" , cmd )
345+ r = DockerRunner (timeout = testcase .timeout ())
346+ env_server = {
347+ "CERTS" : "./certs" ,
348+ "TESTCASE_SERVER" : testcase .testname (Perspective .SERVER ),
349+ "WWW" : testcase .www_dir (),
350+ "SERVER_LOGS" : server_log_dir .name ,
351+ "SERVER" : self ._implementations [server ]["image" ],
352+ }
353+ env_client = {
354+ "CERTS" : "./certs" ,
355+ "TESTCASE_CLIENT" : testcase .testname (Perspective .CLIENT ),
356+ "DOWNLOADS" : testcase .download_dir (),
357+ "CLIENT_LOGS" : client_log_dir .name ,
358+ "CLIENT" : self ._implementations [client ]["image" ],
359+ "REQUESTS" : reqs ,
360+ }
361+ env_sim = {
362+ "SCENARIO" : testcase .scenario (),
363+ "WAITFORSERVER" : "server:443" ,
364+ }
365+ env = {}
366+ env .update (env_server )
367+ env .update (env_client )
368+ env .update (env_sim )
369+ r .add_container (name = "server" , env = env )
370+ r .add_container (name = "client" , env = env )
371+ r .add_container (name = "sim" , env = env )
372+ for c in testcase .additional_containers ():
373+ r .add_container (name = c , env = testcase .additional_envs ())
374+ output , expired = r .run ()
364375
365376 status = TestResult .FAILED
366- output = ""
367- expired = False
368- try :
369- r = subprocess .run (
370- cmd ,
371- shell = True ,
372- stdout = subprocess .PIPE ,
373- stderr = subprocess .STDOUT ,
374- timeout = testcase .timeout (),
375- )
376- output = r .stdout
377- except subprocess .TimeoutExpired as ex :
378- output = ex .stdout
379- expired = True
380-
381- logging .debug ("%s" , output .decode ("utf-8" ))
382-
383- if expired :
384- logging .debug ("Test failed: took longer than %ds." , testcase .timeout ())
385- r = subprocess .run (
386- "docker-compose stop " + containers ,
387- shell = True ,
388- stdout = subprocess .PIPE ,
389- stderr = subprocess .STDOUT ,
390- timeout = 60 ,
391- )
392- logging .debug ("%s" , r .stdout .decode ("utf-8" ))
393377
394378 # copy the pcaps from the simulator
395379 self ._copy_logs ("sim" , sim_log_dir )
396380 self ._copy_logs ("client" , client_log_dir )
397381 self ._copy_logs ("server" , server_log_dir )
398382
399- if not expired :
383+ if expired :
384+ logging .debug ("Test failed: took longer than %ds." , testcase .timeout ())
385+ else :
400386 lines = output .splitlines ()
401387 if self ._is_unsupported (lines ):
402388 status = TestResult .UNSUPPORTED
0 commit comments