1# Lint as: python2, python3 2# Copyright (c) 2020 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""These are convenience functions that ideally are never run, but in case of 7problems collect additional information about some part of the system (both 8DUT and test-driving host. 9 10Given this sporadic nature, this is not wrapped in a class but merely a 11collection of functions that get the necessary inputs at the time when they're 12called and need them. 13 14The functions return a (multi-line) string that can be attached to test errors 15and similar places that end up in the logs.""" 16 17 18def collect_usb_state(servo): 19 """Collect status on USB ports and attached devices, USB mass storage in 20 particular. 21 22 _servo is a server.cros.servo object that can call into the DUT and query 23 elements. 24 25 collects the DUT-side output of : 26 - `lsusb` and `lsusb -t` output to learn about the topology; 27 - `ls -lv /dev/sd*` to learn which storage devices are known to the OS and 28 what partition scheme is assumed by the kernel (-v to sort numerically); 29 - `fdisk -l` for the partitioning as reported in GPT/MBR 30 31 Note that the return value begins with a newline. 32 """ 33 lines = [] 34 for cmd in [ 35 'lsusb', 36 'lsusb -t', 37 'ls -lv /dev/sd*', 38 'fdisk -l' 39 ]: 40 output = servo.system_output(cmd, ignore_status=True) 41 lines.append('') 42 lines.append('%s:' % cmd) 43 lines.extend(' %s' % line for line in output.splitlines()) 44 return '\n'.join(lines) 45 46# Add more collect functions here as necessary 47