summaryrefslogtreecommitdiff
path: root/cts/common
diff options
context:
space:
mode:
authorYilin Yang <kerker@google.com>2020-09-26 13:49:12 +0800
committerCommit Bot <commit-bot@chromium.org>2020-09-29 11:18:54 +0000
commit17d47b68f8730a5404e9d2379a4b1a20c87d045b (patch)
treead737cb0eb68f69f88b48c8228eb741ee419dd9c /cts/common
parent60f8307462bbb8dad78985f4321a2740bd0e828c (diff)
downloadchrome-ec-17d47b68f8730a5404e9d2379a4b1a20c87d045b.tar.gz
cts: Migrate cts.py to python2/3 compatible
BUG=chromium:1031705 BRANCH=master TEST=None Signed-off-by: kerker <kerker@chromium.org> Change-Id: If043aa2d7d8b758571f43730635f741e3b81d8ad Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2431316 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'cts/common')
-rw-r--r--cts/common/board.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/cts/common/board.py b/cts/common/board.py
index db7f535391..478da1479c 100644
--- a/cts/common/board.py
+++ b/cts/common/board.py
@@ -2,6 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# Note: This is a py2/3 compatible file.
+
+from __future__ import print_function
+
from abc import ABCMeta
from abc import abstractmethod
import os
@@ -9,6 +13,8 @@ import shutil
import subprocess as sp
import serial
+import six
+
OCD_SCRIPT_DIR = '/usr/share/openocd/scripts'
OPENOCD_CONFIGS = {
@@ -24,7 +30,13 @@ FLASH_OFFSETS = {
REBOOT_MARKER = 'UART initialized after reboot'
-class Board(object):
+def get_subprocess_args():
+ if six.PY3:
+ return {'encoding': 'utf-8'}
+ return {}
+
+
+class Board(six.with_metaclass(ABCMeta, object)):
"""Class representing a single board connected to a host machine.
Attributes:
@@ -38,8 +50,6 @@ class Board(object):
tty: String of file descriptor for tty_port
"""
- __metaclass__ = ABCMeta # This is an Abstract Base Class (ABC)
-
def __init__(self, board, module, hla_serial=None):
"""Initializes a board object with given attributes.
@@ -80,7 +90,7 @@ class Board(object):
List of serials
"""
usb_args = ['sudo', 'lsusb', '-v', '-d', '0x0483:0x374b']
- st_link_info = sp.check_output(usb_args)
+ st_link_info = sp.check_output(usb_args, **get_subprocess_args())
st_serials = []
for line in st_link_info.split('\n'):
if 'iSerial' not in line:
@@ -123,7 +133,7 @@ class Board(object):
def dump_openocd_log(self):
with open(self.openocd_log) as log:
- print log.read()
+ print(log.read())
def build(self, ec_dir):
"""Builds test suite module for board.
@@ -151,7 +161,7 @@ class Board(object):
def dump_build_log(self):
with open(self.build_log) as log:
- print log.read()
+ print(log.read())
def flash(self, image_path):
"""Flashes board with most recent build ec.bin."""
@@ -212,7 +222,7 @@ class Board(object):
line = []
boot = 0
while True:
- c = self.tty.read()
+ c = self.tty.read().decode('utf-8')
if not c:
break
line.append(c)
@@ -240,7 +250,8 @@ class Board(object):
for device in com_devices:
self.tty_port = os.path.join(dev_dir, device)
properties = sp.check_output(
- ['udevadm', 'info', '-a', '-n', self.tty_port, '--query=property'])
+ ['udevadm', 'info', '-a', '-n', self.tty_port, '--query=property'],
+ **get_subprocess_args())
for line in [l.strip() for l in properties.split('\n')]:
if line.startswith(id_prefix):
if self.hla_serial == line[len(id_prefix):]:
@@ -311,7 +322,7 @@ class TestHarness(Board):
f.write(s)
self.hla_serial = s
- print 'Your TH serial', s, 'has been saved as', self.serial_path
+ print('Your TH serial', s, 'has been saved as', self.serial_path)
return