Simplify stm32f429i-disc1 test runner UI
- Change some info-level logs to be debug.
- Include openocd config file in python module.
- Provide default value for openocd_config command line argument.
- Shorter log format.
- Don't log backtrace for caught TestingFailure exceptions.
New example output (with test_runner.py):
~/pigweed/pigweed$ pw test --root out/stm32f429i-disc1/ --runner stm32f429i_disc1_unit_test_runner -- --port /dev/ttyACM0
▒█████▄ █▓ ▄███▒ ▒█ ▒█ ░▓████▒ ░▓████▒ ▒▓████▄
▒█░ █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█ ▒█ ▀ ▒█ ▀ ▒█ ▀█▌
▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█ ▒███ ▒███ ░█ █▌
▒█▀ ░█░ ▓█ █▓ ░█░ █ ▒█ ▒█ ▄ ▒█ ▄ ░█ ▄█▌
▒█ ░█░ ░▓███▀ ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀
20191202 10:45:09 AM INF Scanning for tests...
20191202 10:45:09 AM INF Found 4 test groups (10 tests).
20191202 10:45:09 AM INF Running test groups //pw_status:tests, //pw_preprocessor:tests, //pw_string:tests, //pw_span:tests
20191202 10:45:09 AM INF Test 1/10: [RUN] format_test
2019-12-02 10:45:09 INFO | Flashing firmware to device...
2019-12-02 10:45:10 INFO | Successfully flashed firmware to device!
2019-12-02 10:45:10 INFO |
[==========] Running all tests.
[ RUN ] Format.ValidFormatString_Succeeds
[ OK ] Format.ValidFormatString_Succeeds
[ RUN ] Format.ValidFormatStringAndArguments_Succeeds
[ OK ] Format.ValidFormatStringAndArguments_Succeeds
[ RUN ] Format.InvalidConversionSpecifier_ReturnsInvalidArgumentAndTerminates
../../pw_string/format_test.cc:51: Failure
Expected: Status::INVALID_ARGUMENT == result.status()
Actual: 3 == OK
../../pw_string/format_test.cc:52: Failure
Expected: "" equals buffer
Actual: equals abc 12345
[ FAILED ] Format.InvalidConversionSpecifier_ReturnsInvalidArgumentAndTerminates
[ RUN ] Format.EmptyBuffer_ReturnsResourceExhausted
[ OK ] Format.EmptyBuffer_ReturnsResourceExhausted
[ RUN ] Format.FormatLargerThanBuffer_ReturnsResourceExhausted
[ OK ] Format.FormatLargerThanBuffer_ReturnsResourceExhausted
[ RUN ] Format.ArgumentLargerThanBuffer_ReturnsResourceExhausted
[ OK ] Format.ArgumentLargerThanBuffer_ReturnsResourceExhausted
[ RUN ] Format.CallFormatWithVaList_CallsCorrectFormatOverload
[ OK ] Format.CallFormatWithVaList_CallsCorrectFormatOverload
[==========] Done running all tests.
[ PASSED ] 6 test(s).
[ FAILED ] 1 test(s).
2019-12-02 10:45:10 ERROR | Test suite had one or more failures.
Change-Id: I8ca4af75bb04ffb8f4a50d26e5ac0ef41e7d762a
diff --git a/targets/stm32f429i-disc1/openocd_stm32f4xx.cfg b/targets/stm32f429i-disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg
similarity index 100%
rename from targets/stm32f429i-disc1/openocd_stm32f4xx.cfg
rename to targets/stm32f429i-disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg
diff --git a/targets/stm32f429i-disc1/py/stm32f429i_disc1_utils/unit_test_runner.py b/targets/stm32f429i-disc1/py/stm32f429i_disc1_utils/unit_test_runner.py
index 0c6f298..c1a5b77 100755
--- a/targets/stm32f429i-disc1/py/stm32f429i_disc1_utils/unit_test_runner.py
+++ b/targets/stm32f429i-disc1/py/stm32f429i_disc1_utils/unit_test_runner.py
@@ -18,11 +18,14 @@
import serial
import subprocess
import sys
-import traceback
import coloredlogs
-from serial.tools import list_ports
+# Path used to access non-python resources in this python module.
+_DIR = os.path.dirname(__file__)
+
+# Path to default openocd configuration file.
+_OPENOCD_CONFIG = os.path.join(_DIR, 'openocd_stm32f4xx.cfg')
_LOG = logging.getLogger('unit_test_runner')
@@ -45,7 +48,7 @@
'Flashes and then runs on-device unit tests')
parser.add_argument('binary', help='The target test binary to run')
parser.add_argument('--openocd-config',
- required=True,
+ default=_OPENOCD_CONFIG,
help='Path to openocd configuration file')
parser.add_argument('--port',
required=True,
@@ -81,7 +84,7 @@
flash_tool, '-f', openocd_config, '-c', 'init', '-c', 'reset run',
'-c', 'exit'
]
- _LOG.info('Resetting device...')
+ _LOG.debug('Resetting device...')
process = subprocess.run(cmd,
stdout=subprocess.PIPE,
@@ -92,7 +95,7 @@
else:
_LOG.debug(f'\n{process.stdout.decode("utf-8", errors="replace")}')
- _LOG.info('Successfully reset device!')
+ _LOG.debug('Successfully reset device!')
def read_serial(openocd_config, port, baud_rate, test_timeout) -> bytes:
@@ -127,6 +130,9 @@
# passes, two lines if mixed.)
device.timeout = 0.01
+ # Remove carriage returns.
+ serial_data = serial_data.replace(b'\r', b'')
+
# Try to trim captured results to only contain most recent test run.
test_start_index = serial_data.rfind(_TESTS_STARTING_STRING)
return serial_data if test_start_index == -1 else serial_data[
@@ -170,6 +176,7 @@
_LOG.info(f'\n{test_output.decode("utf-8", errors="replace")}')
raise TestingFailure('Test suite had one or more failures.')
+ # TODO(amontanez): Do line-by-line logging of captured output.
_LOG.debug(f'\n{test_output.decode("utf-8", errors="replace")}')
_LOG.info('Test passed!')
@@ -182,13 +189,12 @@
Returns true on test pass.
"""
- _LOG.info('Launching test binary {}'.format(binary))
+ _LOG.debug('Launching test binary {}'.format(binary))
try:
flash_device(binary, openocd_config)
serial_data = read_serial(openocd_config, port, baud, test_timeout)
handle_test_results(serial_data)
except TestingFailure as err:
- traceback.print_tb(err.__traceback__)
_LOG.error(err)
return False
@@ -208,7 +214,7 @@
'color': 'red'
}
},
- fmt='TEST - %(asctime)s - %(levelname)s - %(message)s')
+ fmt='%(asctime)s %(levelname)s | %(message)s')
if run_device_test(args.binary, args.test_timeout, args.openocd_config,
args.baud, args.port):