1313
1414from tools .serve .serve import make_hosts_file
1515
16- from .base import (RefTestImplementation ,
16+ from .base import (TestExecutor , RefTestExecutor , RefTestImplementation ,
1717 crashtest_result_converter ,
1818 testharness_result_converter ,
1919 reftest_result_converter ,
2020 TimedRunner )
21- from .process import ProcessTestExecutor
2221from .protocol import ConnectionlessProtocol
2322from ..browsers .base import browser_command
2423
2726webdriver = None
2827
2928
30- class ServoExecutor (ProcessTestExecutor ):
31- def __init__ (self , logger , browser , server_config , headless : bool ,
32- timeout_multiplier , debug_info ,
33- pause_after_test , reftest_screenshot = "unexpected" ):
34- ProcessTestExecutor .__init__ (self , logger , browser , server_config ,
35- timeout_multiplier = timeout_multiplier ,
36- debug_info = debug_info ,
37- reftest_screenshot = reftest_screenshot )
38- self .pause_after_test = pause_after_test
29+ class ServoExecutorMixin :
30+ def __init__ (self , * args , ** kwargs ):
31+ super ().__init__ (* args , ** kwargs )
32+ self .binary = self .browser .binary
33+ self .interactive = (False if self .debug_info is None
34+ else self .debug_info .interactive )
35+ self .pause_after_test = kwargs .get ('pause_after_test' , False )
3936 self .environment = {}
40- self .protocol = ConnectionlessProtocol (self , browser )
41- self .headless = headless
37+ self .protocol = ConnectionlessProtocol (self , self . browser )
38+ self .headless = kwargs . get ( ' headless' , False )
4239
4340 self .wpt_prefs_path = self .find_wpt_prefs ()
4441
4542 hosts_fd , self .hosts_path = tempfile .mkstemp ()
4643 with os .fdopen (hosts_fd , "w" ) as f :
47- f .write (make_hosts_file (server_config , "127.0.0.1" ))
44+ f .write (make_hosts_file (self . server_config , "127.0.0.1" ))
4845
4946 self .env_for_tests = os .environ .copy ()
5047 self .env_for_tests ["HOST_FILE" ] = self .hosts_path
5148 self .env_for_tests ["RUST_BACKTRACE" ] = "1"
5249
50+ def setup (self , runner , protocol = None ):
51+ self .runner = runner
52+ self .runner .send_message ("init_succeeded" )
53+ return True
54+
5355 def teardown (self ):
5456 try :
5557 os .unlink (self .hosts_path )
5658 except OSError :
5759 pass
58- ProcessTestExecutor .teardown (self )
60+ super () .teardown ()
5961
6062 def on_environment_change (self , new_environment ):
6163 self .environment = new_environment
@@ -66,7 +68,8 @@ def on_output(self, line):
6668 if self .interactive :
6769 print (line )
6870 else :
69- self .logger .process_output (self .proc .pid , line , " " .join (self .command ), self .test .url )
71+ self .logger .process_output (
72+ self .proc .pid , line , " " .join (self .command ), self .test .url )
7073
7174 def find_wpt_prefs (self ):
7275 default_path = os .path .join ("resources" , "wpt-prefs.json" )
@@ -103,20 +106,20 @@ def build_servo_command(self, test, extra_args=None):
103106 if extra_args :
104107 args += extra_args
105108 args += self .browser .binary_args
106- debug_args , command = browser_command (self .binary , args , self .debug_info )
109+ debug_args , command = browser_command (
110+ self .binary , args , self .debug_info )
107111 return debug_args + command
108112
109113
110- class ServoTestharnessExecutor (ServoExecutor ):
114+ class ServoTestharnessExecutor (ServoExecutorMixin , TestExecutor ):
111115 convert_result = testharness_result_converter
112116
113117 def __init__ (self , logger , browser , server_config , headless ,
114118 timeout_multiplier = 1 , debug_info = None ,
115119 pause_after_test = False , ** kwargs ):
116- ServoExecutor .__init__ (self , logger , browser , server_config , headless ,
117- timeout_multiplier = timeout_multiplier ,
118- debug_info = debug_info ,
119- pause_after_test = pause_after_test )
120+ super ().__init__ (logger , browser , server_config , headless = headless ,
121+ timeout_multiplier = timeout_multiplier , debug_info = debug_info ,
122+ pause_after_test = pause_after_test )
120123 self .result_data = None
121124 self .result_flag = None
122125
@@ -179,10 +182,11 @@ def on_output(self, line):
179182 try :
180183 self .result_data = json .loads (decoded_line [len (prefix ):])
181184 except json .JSONDecodeError as error :
182- self .logger .error (f"Could not process test output JSON: { error } " )
185+ self .logger .error (
186+ f"Could not process test output JSON: { error } " )
183187 self .result_flag .set ()
184188 else :
185- ServoExecutor .on_output (self , line )
189+ super () .on_output (line )
186190
187191 def on_finish (self ):
188192 self .result_flag .set ()
@@ -204,21 +208,21 @@ def __exit__(self, *args, **kwargs):
204208 pass
205209
206210
207- class ServoRefTestExecutor (ServoExecutor ):
211+ class ServoRefTestExecutor (ServoExecutorMixin , RefTestExecutor ):
208212 convert_result = reftest_result_converter
209213
210214 def __init__ (self , logger , browser , server_config , binary = None , timeout_multiplier = 1 ,
211215 screenshot_cache = None , debug_info = None , pause_after_test = False ,
212216 reftest_screenshot = "unexpected" , ** kwargs ):
213- ServoExecutor .__init__ (self ,
214- logger ,
215- browser ,
216- server_config ,
217- headless = True ,
218- timeout_multiplier = timeout_multiplier ,
219- debug_info = debug_info ,
220- reftest_screenshot = reftest_screenshot ,
221- pause_after_test = pause_after_test )
217+ super () .__init__ (self ,
218+ logger ,
219+ browser ,
220+ server_config ,
221+ headless = True ,
222+ timeout_multiplier = timeout_multiplier ,
223+ debug_info = debug_info ,
224+ reftest_screenshot = reftest_screenshot ,
225+ pause_after_test = pause_after_test )
222226
223227 self .screenshot_cache = screenshot_cache
224228 self .reftest_screenshot = reftest_screenshot
@@ -230,7 +234,7 @@ def reset(self):
230234
231235 def teardown (self ):
232236 os .rmdir (self .tempdir )
233- ServoExecutor .teardown (self )
237+ super () .teardown ()
234238
235239 def screenshot (self , test , viewport_size , dpi , page_ranges ):
236240 with TempFilename (self .tempdir ) as output_path :
@@ -256,7 +260,8 @@ def screenshot(self, test, viewport_size, dpi, page_ranges):
256260 self .proc .kill ()
257261 raise
258262 else :
259- self .proc = subprocess .Popen (self .command , env = self .env_for_tests )
263+ self .proc = subprocess .Popen (
264+ self .command , env = self .env_for_tests )
260265 try :
261266 rv = self .proc .wait ()
262267 except KeyboardInterrupt :
@@ -287,7 +292,8 @@ def do_test(self, test):
287292class ServoTimedRunner (TimedRunner ):
288293 def run_func (self ):
289294 try :
290- self .result = (True , self .func (self .protocol , self .url , self .timeout ))
295+ self .result = (True , self .func (
296+ self .protocol , self .url , self .timeout ))
291297 except Exception as e :
292298 message = getattr (e , "message" , "" )
293299 if message :
@@ -301,20 +307,20 @@ def set_timeout(self):
301307 pass
302308
303309
304- class ServoCrashtestExecutor (ServoExecutor ):
310+ class ServoCrashtestExecutor (ServoExecutorMixin , TestExecutor ):
305311 convert_result = crashtest_result_converter
306312
307313 def __init__ (self , logger , browser , server_config , headless ,
308314 binary = None , timeout_multiplier = 1 , screenshot_cache = None ,
309315 debug_info = None , pause_after_test = False ):
310- ServoExecutor .__init__ (self ,
311- logger ,
312- browser ,
313- server_config ,
314- headless ,
315- timeout_multiplier = timeout_multiplier ,
316- debug_info = debug_info ,
317- pause_after_test = pause_after_test )
316+ super () .__init__ (self ,
317+ logger ,
318+ browser ,
319+ server_config ,
320+ headless ,
321+ timeout_multiplier = timeout_multiplier ,
322+ debug_info = debug_info ,
323+ pause_after_test = pause_after_test )
318324
319325 self .pause_after_test = pause_after_test
320326 self .protocol = ConnectionlessProtocol (self , browser )
0 commit comments