diff options
Diffstat (limited to 'extra/tigertool/tigertest.py')
-rwxr-xr-x | extra/tigertool/tigertest.py | 105 |
1 files changed, 52 insertions, 53 deletions
diff --git a/extra/tigertool/tigertest.py b/extra/tigertool/tigertest.py index 0cd31c8cce..b1186cca77 100755 --- a/extra/tigertool/tigertest.py +++ b/extra/tigertool/tigertest.py @@ -1,11 +1,7 @@ #!/usr/bin/env python3 -# Copyright 2022 The Chromium OS Authors. All rights reserved. +# Copyright 2022 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# -# Ignore indention messages, since legacy scripts use 2 spaces instead of 4. -# pylint: disable=bad-indentation,docstring-section-indent -# pylint: disable=docstring-trailing-quotes """Smoke test of tigertool binary.""" @@ -13,7 +9,6 @@ import argparse import subprocess import sys - # Script to control tigertail USB-C Mux board. # # optional arguments: @@ -35,58 +30,62 @@ import sys def testCmd(cmd, expected_results): - """Run command on console, check for success. - - Args: - cmd: shell command to run. - expected_results: a list object of strings expected in the result. - - Raises: - Exception on fail. - """ - print('run: ' + cmd) - try: - p = subprocess.run(cmd, shell=True, check=False, capture_output=True) - output = p.stdout.decode('utf-8') - error = p.stderr.decode('utf-8') - assert p.returncode == 0 - for result in expected_results: - output.index(result) - except Exception as e: - print('FAIL') - print('cmd: ' + cmd) - print('error: ' + str(e)) - print('stdout:\n' + output) - print('stderr:\n' + error) - print('expected: ' + str(expected_results)) - print('RC: ' + str(p.returncode)) - raise e + """Run command on console, check for success. + + Args: + cmd: shell command to run. + expected_results: a list object of strings expected in the result. + + Raises: + Exception on fail. + """ + print("run: " + cmd) + try: + p = subprocess.run(cmd, shell=True, check=False, capture_output=True) + output = p.stdout.decode("utf-8") + error = p.stderr.decode("utf-8") + assert p.returncode == 0 + for result in expected_results: + output.index(result) + except Exception as e: + print("FAIL") + print("cmd: " + cmd) + print("error: " + str(e)) + print("stdout:\n" + output) + print("stderr:\n" + error) + print("expected: " + str(expected_results)) + print("RC: " + str(p.returncode)) + raise e + def test_sequence(): - testCmd('./tigertool.py --reboot', ['PASS']) - testCmd('./tigertool.py --setserialno test', ['PASS']) - testCmd('./tigertool.py --check_serial', ['test', 'PASS']) - testCmd('./tigertool.py -s test --check_serial', ['test', 'PASS']) - testCmd('./tigertool.py -m A', ['Mux set to A', 'PASS']) - testCmd('./tigertool.py -m B', ['Mux set to B', 'PASS']) - testCmd('./tigertool.py -m off', ['Mux set to off', 'PASS']) - testCmd('./tigertool.py -p', ['PASS']) - testCmd('./tigertool.py -r rw', ['PASS']) - testCmd('./tigertool.py -r ro', ['PASS']) - testCmd('./tigertool.py --check_version', ['RW', 'RO', 'PASS']) - - print('PASS') + testCmd("./tigertool.py --reboot", ["PASS"]) + testCmd("./tigertool.py --setserialno test", ["PASS"]) + testCmd("./tigertool.py --check_serial", ["test", "PASS"]) + testCmd("./tigertool.py -s test --check_serial", ["test", "PASS"]) + testCmd("./tigertool.py -m A", ["Mux set to A", "PASS"]) + testCmd("./tigertool.py -m B", ["Mux set to B", "PASS"]) + testCmd("./tigertool.py -m off", ["Mux set to off", "PASS"]) + testCmd("./tigertool.py -p", ["PASS"]) + testCmd("./tigertool.py -r rw", ["PASS"]) + testCmd("./tigertool.py -r ro", ["PASS"]) + testCmd("./tigertool.py --check_version", ["RW", "RO", "PASS"]) + + print("PASS") + def main(argv): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('-c', '--count', type=int, default=1, - help='loops to run') + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "-c", "--count", type=int, default=1, help="loops to run" + ) + + opts = parser.parse_args(argv) - opts = parser.parse_args(argv) + for i in range(1, opts.count + 1): + print("Iteration: %d" % i) + test_sequence() - for i in range(1, opts.count + 1): - print('Iteration: %d' % i) - test_sequence() -if __name__ == '__main__': +if __name__ == "__main__": main(sys.argv[1:]) |