1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#!/usr/bin/env python3
# Copyright 2022 The Chromium OS Authors. All rights reserved.
# 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."""
import argparse
import subprocess
import sys
# Script to control tigertail USB-C Mux board.
#
# optional arguments:
# -h, --help show this help message and exit
# -s SERIALNO, --serialno SERIALNO
# serial number of board to use
# -b BUS, --bus BUS Which rail to log: [vbus|cc1|cc2]
# --setserialno SETSERIALNO
# serial number to set on the board.
# --check_serial check serial number set on the board.
# -m MUX, --mux MUX mux selection
# -p, --power check VBUS
# -l POWERLOG, --powerlog POWERLOG
# log VBUS
# -r SYSJUMP, --sysjump SYSJUMP
# region selection
# --reboot reboot tigertail
# --check_version check tigertail version
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
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')
def main(argv):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-c', '--count', type=int, default=1,
help='loops to run')
opts = parser.parse_args(argv)
for i in range(1, opts.count + 1):
print('Iteration: %d' % i)
test_sequence()
if __name__ == '__main__':
main(sys.argv[1:])
|