1
- #!/usr/bin/env python2
1
+ #!/usr/bin/env python
2
2
#
3
3
# Copyright 2016 The Chromium OS Authors. All rights reserved.
4
4
# Use of this source code is governed by a BSD-style license that can be
16
16
# $ ./cts.py
17
17
# It'll run mock tests. The result will be stored in CTS_TEST_RESULT_DIR.
18
18
19
+ # Note: This is a py2/3 compatible file.
20
+
21
+ from __future__ import print_function
19
22
20
23
import argparse
21
24
import os
@@ -76,10 +79,10 @@ def __init__(self, ec_dir, th, dut, module):
76
79
77
80
def build (self ):
78
81
"""Build images for DUT and TH."""
79
- print 'Building DUT image...'
82
+ print ( 'Building DUT image...' )
80
83
if not self .dut .build (self .ec_dir ):
81
84
raise RuntimeError ('Building module %s for DUT failed' % (self .module ))
82
- print 'Building TH image...'
85
+ print ( 'Building TH image...' )
83
86
if not self .th .build (self .ec_dir ):
84
87
raise RuntimeError ('Building module %s for TH failed' % (self .module ))
85
88
@@ -88,11 +91,11 @@ def flash_boards(self):
88
91
cts_module = 'cts_' + self .module
89
92
image_path = os .path .join ('build' , self .th .board , cts_module , 'ec.bin' )
90
93
self .identify_boards ()
91
- print 'Flashing TH with' , image_path
94
+ print ( 'Flashing TH with' , image_path )
92
95
if not self .th .flash (image_path ):
93
96
raise RuntimeError ('Flashing TH failed' )
94
97
image_path = os .path .join ('build' , self .dut .board , cts_module , 'ec.bin' )
95
- print 'Flashing DUT with' , image_path
98
+ print ( 'Flashing DUT with' , image_path )
96
99
if not self .dut .flash (image_path ):
97
100
raise RuntimeError ('Flashing DUT failed' )
98
101
@@ -212,7 +215,7 @@ def parse_output(self, output):
212
215
213
216
def get_return_code_name (self , code , strip_prefix = False ):
214
217
name = ''
215
- for k , v in self .return_codes .iteritems ():
218
+ for k , v in self .return_codes .items ():
216
219
if v == code :
217
220
if strip_prefix :
218
221
name = k [len (CTS_RC_PREFIX ):]
@@ -299,52 +302,52 @@ def evaluate_result(self, result, expected_rc, expected_string):
299
302
300
303
def run (self ):
301
304
"""Resets boards, records test results in results dir."""
302
- print 'Reading serials...'
305
+ print ( 'Reading serials...' )
303
306
self .identify_boards ()
304
- print 'Opening DUT tty...'
307
+ print ( 'Opening DUT tty...' )
305
308
self .dut .setup_tty ()
306
- print 'Opening TH tty...'
309
+ print ( 'Opening TH tty...' )
307
310
self .th .setup_tty ()
308
311
309
312
# Boards might be still writing to tty. Wait a few seconds before flashing.
310
313
time .sleep (3 )
311
314
312
315
# clear buffers
313
- print 'Clearing DUT tty...'
316
+ print ( 'Clearing DUT tty...' )
314
317
self .dut .read_tty ()
315
- print 'Clearing TH tty...'
318
+ print ( 'Clearing TH tty...' )
316
319
self .th .read_tty ()
317
320
318
321
# Resets the boards and allows them to run tests
319
322
# Due to current (7/27/16) version of sync function,
320
323
# both boards must be rest and halted, with the th
321
324
# resuming first, in order for the test suite to run in sync
322
- print 'Halting TH...'
325
+ print ( 'Halting TH...' )
323
326
if not self .th .reset_halt ():
324
327
raise RuntimeError ('Failed to halt TH' )
325
- print 'Halting DUT...'
328
+ print ( 'Halting DUT...' )
326
329
if not self .dut .reset_halt ():
327
330
raise RuntimeError ('Failed to halt DUT' )
328
- print 'Resuming TH...'
331
+ print ( 'Resuming TH...' )
329
332
if not self .th .resume ():
330
333
raise RuntimeError ('Failed to resume TH' )
331
- print 'Resuming DUT...'
334
+ print ( 'Resuming DUT...' )
332
335
if not self .dut .resume ():
333
336
raise RuntimeError ('Failed to resume DUT' )
334
337
335
338
time .sleep (MAX_SUITE_TIME_SEC )
336
339
337
- print 'Reading DUT tty...'
340
+ print ( 'Reading DUT tty...' )
338
341
dut_output , _ = self .dut .read_tty ()
339
342
self .dut .close_tty ()
340
- print 'Reading TH tty...'
343
+ print ( 'Reading TH tty...' )
341
344
th_output , _ = self .th .read_tty ()
342
345
self .th .close_tty ()
343
346
344
- print 'Halting TH...'
347
+ print ( 'Halting TH...' )
345
348
if not self .th .reset_halt ():
346
349
raise RuntimeError ('Failed to halt TH' )
347
- print 'Halting DUT...'
350
+ print ( 'Halting DUT...' )
348
351
if not self .dut .reset_halt ():
349
352
raise RuntimeError ('Failed to halt DUT' )
350
353
@@ -353,7 +356,7 @@ def run(self):
353
356
'reading ttyACMx, please kill that process and try '
354
357
'again.' )
355
358
356
- print 'Pursing results...'
359
+ print ( 'Pursing results...' )
357
360
th_results , dut_results = self .evaluate_run (dut_output , th_output )
358
361
359
362
# Print out results
@@ -372,7 +375,7 @@ def run(self):
372
375
with open (dest , 'w' ) as fl :
373
376
fl .write (dut_output )
374
377
375
- print self .formatted_results
378
+ print ( self .formatted_results )
376
379
377
380
# TODO(chromium:735652): Should set exit code for the shell
378
381
0 commit comments