summaryrefslogtreecommitdiff
path: root/cts/common
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2016-11-09 16:43:50 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-06-16 21:10:54 -0700
commit3e4d3fd71249d9511ff8b61b44dbc358191cb90f (patch)
tree37dfc5fa8491c4c1ae31ba6073a1cdd8eef275fb /cts/common
parentfd528684dd5fae6fcad45678a9cd64a1cf6febac (diff)
downloadchrome-ec-3e4d3fd71249d9511ff8b61b44dbc358191cb90f.tar.gz
eCTS: Hide expected messages
This patch hides expected messages from output to the terminal and reorganizes log directory as follows: - All test output goes under /tmp/ects/$dut/$module - Openocd output is recorded in openocd.log - uart outputs are recorded in uart_th.log and uart_dut.log - build output is recorded in build.log - Check exit code from all subprocess calls - Dump build log if build fails - Dump openocd log if openocd fails BUG=chromium:664309 BRANCH=none TEST=cts.py --setup and build images in chroot then run cts.py -m meta outside chroot. Change-Id: I13294c3bf777ad7ae590459d3cf5aea405d59f96 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/409536 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'cts/common')
-rw-r--r--cts/common/board.py69
1 files changed, 55 insertions, 14 deletions
diff --git a/cts/common/board.py b/cts/common/board.py
index dd730087ec..7b618c8300 100644
--- a/cts/common/board.py
+++ b/cts/common/board.py
@@ -6,6 +6,7 @@ from abc import ABCMeta, abstractmethod
import fcntl
import os
import select
+import shutil
import subprocess as sp
import time
@@ -38,26 +39,35 @@ class Board(object):
"""
__metaclass__ = ABCMeta # This is an Abstract Base Class (ABC)
- def __init__(self, board, hla_serial=None):
+ def __init__(self, board, module, hla_serial=None):
"""Initializes a board object with given attributes
Args:
board: String containing board name
+ module: String of the test module you are building,
+ i.e. gpio, timer, etc.
hla_serial: Serial number if board's adaptor is an HLA
"""
if not board in OPENOCD_CONFIGS:
msg = 'OpenOcd configuration not found for ' + board
raise RuntimeError(msg)
- self.openocd_config = OPENOCD_CONFIGS[board]
if not board in FLASH_OFFSETS:
msg = 'Flash offset not found for ' + board
raise RuntimeError(msg)
- self.flash_offset = FLASH_OFFSETS[board]
self.board = board
+ self.flash_offset = FLASH_OFFSETS[self.board]
+ self.openocd_config = OPENOCD_CONFIGS[self.board]
+ self.module = module
self.hla_serial = hla_serial
self.tty_port = None
self.tty = None
+ def reset_log_dir(self):
+ """Reset log directory"""
+ if os.path.isdir(self.log_dir):
+ shutil.rmtree(self.log_dir)
+ os.makedirs(self.log_dir)
+
@staticmethod
def get_stlink_serials():
"""Gets serial numbers of all st-link v2.1 board attached to host
@@ -95,14 +105,24 @@ class Board(object):
for cmd in commands:
args += ['-c', cmd]
args += ['-c', 'shutdown']
- return sp.call(args)
+
+ rv = 1
+ with open(self.openocd_log, 'a') as output:
+ rv = sp.call(args, stdout=output, stderr=sp.STDOUT)
+
+ if rv != 0:
+ self.dump_openocd_log()
+
+ return rv == 0
+
+ def dump_openocd_log(self):
+ with open(self.openocd_log) as log:
+ print log.read()
def build(self, module, ec_dir, debug=False):
"""Builds test suite module for board
Args:
- module: String of the test module you are building,
- i.e. gpio, timer, etc.
ec_dir: String of the ec directory path
debug: True means compile in debug messages when building (may
affect test results)
@@ -110,14 +130,24 @@ class Board(object):
cmds = ['make',
'--directory=' + ec_dir,
'BOARD=' + self.board,
- 'CTS_MODULE=' + module,
+ 'CTS_MODULE=' + self.module,
'-j']
if debug:
cmds.append('CTS_DEBUG=TRUE')
- print ' '.join(cmds)
- return sp.call(cmds)
+ rv = 1
+ with open(self.build_log, 'a') as output:
+ rv = sp.call(cmds, stdout=output, stderr=sp.STDOUT)
+
+ if rv != 0:
+ self.dump_build_log()
+
+ return rv == 0
+
+ def dump_build_log(self):
+ with open(self.build_log) as log:
+ print log.read()
def flash(self, image_path):
"""Flashes board with most recent build ec.bin"""
@@ -138,7 +168,7 @@ class Board(object):
def reset(self):
"""Reset board (used when can't connect to TTY)"""
- self.send_open_ocd_commands(['init', 'reset init', 'resume'])
+ return self.send_open_ocd_commands(['init', 'reset init', 'resume'])
def setup_tty(self):
"""Call this before trying to call readOutput for the first time.
@@ -230,14 +260,20 @@ class TestHarness(Board):
serial_path: Path to file containing serial number
"""
- def __init__(self, board, serial_path):
+ def __init__(self, board, module, log_dir, serial_path):
"""Initializes a board object with given attributes
Args:
+ board: board name
+ module: module name
serial_path: Path to file containing serial number
"""
- Board.__init__(self, board=board)
+ Board.__init__(self, board, module)
+ self.log_dir = log_dir
+ self.openocd_log = os.path.join(log_dir, 'openocd_th.log')
+ self.build_log = os.path.join(log_dir, 'build_th.log')
self.serial_path = serial_path
+ self.reset_log_dir()
def get_serial(self):
"""Loads serial number from saved location"""
@@ -283,16 +319,21 @@ class DeviceUnderTest(Board):
th: Reference to test harness board to which this DUT is attached
"""
- def __init__(self, board, th, hla_ser=None):
+ def __init__(self, board, th, module, log_dir, hla_ser=None):
"""Initializes a Device Under Test object with given attributes
Args:
board: String containing board name
th: Reference to test harness board to which this DUT is attached
+ module: module name
hla_serial: Serial number if board uses an HLA adaptor
"""
- Board.__init__(self, board, hla_serial=hla_ser)
+ Board.__init__(self, board, module, hla_serial=hla_ser)
self.th = th
+ self.log_dir = log_dir
+ self.openocd_log = os.path.join(log_dir, 'openocd_dut.log')
+ self.build_log = os.path.join(log_dir, 'build_dut.log')
+ self.reset_log_dir()
def get_serial(self):
"""Get serial number.