summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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__':