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