summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNamyoon Woo <namyoon@chromium.org>2019-07-10 13:57:40 -0700
committerCommit Bot <commit-bot@chromium.org>2019-07-18 22:42:02 +0000
commitd5a4014a7c9331e099d0eaeb8974e53841395ea3 (patch)
treec5d91d630da685d0fc6dab1c7b5ba94dc31d1aad
parent2e24a0b7e37d80aac75a6b9ceffbfc463456df7c (diff)
downloadchrome-ec-d5a4014a7c9331e099d0eaeb8974e53841395ea3.tar.gz
util: uart_stress_tester raises an error on character loss
This patch let the tester exit with an error code on test failure. It would make easy the future autotest to detect a failure. BUG=None BRANCH=None TEST=ran on fleex. $ uart_stress_tester.py /dev/ttyUSB1 /dev/ttyUSB2 -t 120 -d [before patch] ... INFO | UartSerial| EC | 14888 char lost / 1382400 (1.1 %) INFO | UartSerial| AP | 0 char lost / 1382400 (0.0 %) ERROR | ChargenTest | FAIL: lost 14888 character(s) from the test ... $ echo $? 0 [after patch] ... INFO | UartSerial| EC | 14888 char lost / 1382400 (1.1 %) INFO | UartSerial| AP | 0 char lost / 1382400 (0.0 %) ERROR | ChargenTest | FAIL: lost 14888 character(s) from the test Error: Test failed for losing 144888 character(s) ... $ echo $? 1 $ ./util/uart_stress_tester.py /dev/ttyUSB1 /dev/ttyUSB2 -t 120 -d Error: /dev/ttyUSB1 does not exist. $ echo $? 1 Change-Id: I210efd4ad7fdb8eb612206624eda6c39c5bb3b1c Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1696115 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rwxr-xr-xutil/uart_stress_tester.py35
1 files changed, 27 insertions, 8 deletions
diff --git a/util/uart_stress_tester.py b/util/uart_stress_tester.py
index 13828fe84e..e2f9f278fe 100755
--- a/util/uart_stress_tester.py
+++ b/util/uart_stress_tester.py
@@ -251,7 +251,11 @@ class UartSerial(object):
self.serial.close()
def stress_test_thread(self):
- """Test thread"""
+ """Test thread
+
+ Raises:
+ ChargenTestError: if broken character is found.
+ """
try:
self.serial.open()
self.serial.flushInput()
@@ -295,9 +299,11 @@ class UartSerial(object):
# If it is not alpha-numeric, terminate the test.
if ch_cap not in CRLF:
# If it is neither a CR nor LF, then it is an error case.
- self.logger.error(err_msg, 'Broken char captured',
- ch_exp, hex(ord(ch_cap)), self.num_ch_cap)
self.logger.error('Whole captured characters: %r', captured)
+ raise ChargenTestError(err_msg % ('Broken char captured', ch_exp,
+ hex(ord(ch_cap)),
+ self.num_ch_cap))
+
# Set the loop termination condition true.
total_num_ch = self.num_ch_cap
@@ -421,7 +427,11 @@ class ChargenTest(object):
self.logger.info('Ports are ready to test')
def print_result(self):
- """Display the test result for each UART port"""
+ """Display the test result for each UART port
+
+ Returns:
+ char_lost: Total number of characters lost
+ """
char_lost = 0
for _, ser in self.serials.items():
(tmp_lost, _, _) = ser.get_result()
@@ -434,8 +444,14 @@ class ChargenTest(object):
else:
self.logger.info('PASS: %s', msg)
+ return char_lost
+
def run(self):
- """Run the stress test on UART port(s)"""
+ """Run the stress test on UART port(s)
+
+ Raises:
+ ChargenTestError: If any characters are lost.
+ """
# Detect UART source type, and decide which command to test.
self.prepare()
@@ -450,9 +466,12 @@ class ChargenTest(object):
ser.wait_test_done()
# Print the result.
- self.print_result()
- self.logger.info('Test is done')
+ char_lost = self.print_result()
+ if char_lost:
+ raise ChargenTestError('Test failed: lost %d character(s)' %
+ char_lost)
+ self.logger.info('Test is done')
def parse_args(cmdline):
"""Parse command line arguments.
@@ -514,7 +533,7 @@ def main():
sys.exit(0)
except ChargenTestError as e:
- print('Error: ', str(e))
+ logging.error(str(e))
sys.exit(1)
if __name__ == '__main__':