• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6"""The autotest performing uart_stress_tester on EC uart port. """
7import logging
8
9from autotest_lib.client.common_lib import error
10from autotest_lib.server.cros.faft.cr50_test import Cr50Test
11
12
13FLAG_FILENAME = '/tmp/chargen_testing'
14# A ChromeOS TPM command to burden CR50.
15TPM_CMD = ('trunks_client --stress_test')
16# A command line to burden Cr50 with TPM_CMD as long as FLAG_FILENAME exists.
17CR50_LOAD_GEN_CMD = 'while [ -f %s ]; do %s; done &' % (FLAG_FILENAME, TPM_CMD)
18
19# Character generator
20CHARGEN_CMD = 'chargen'
21
22class firmware_Cr50CCDUartStress(Cr50Test):
23    """A test that checks character loss with a UART and TPM stress workload."""
24
25    version = 1
26    flag_filename = '/tmp/chargen_testing'
27
28    def initialize(self, host, cmdline_args, full_args):
29        """Initialize the test
30
31        Raises:
32            TestNAError: if the test environment is not properly set.
33                         e.g. the servo type doesn't support this test, or
34                         EC Uart command, chargen is not available.
35        """
36        super(firmware_Cr50CCDUartStress,
37              self).initialize(host, cmdline_args, full_args)
38
39        # Don't bother if there is no Chrome EC or if EC hibernate doesn't work.
40        if not self.check_ec_capability():
41            raise error.TestNAError('Nothing needs to be tested on this device')
42
43        # Check EC chargen is available.
44        if not self.ec.has_command(CHARGEN_CMD):
45            raise error.TestNAError('chargen command is not available in EC.')
46        logging.info('Checked EC has the uart command, %r.', CHARGEN_CMD)
47
48        # Check CCD is in servo_type.
49        servo_type = self.servo.get_servo_version()
50        if 'ccd' not in servo_type:
51            raise error.TestNAError('unsupported servo type: %s' % servo_type)
52        logging.info('Checked the servo type is %r.', servo_type)
53
54        # Fast open cr50 and enable testlab.
55        self.fast_ccd_open(enable_testlab=True)
56        logging.info('CCD opened.')
57
58        # Change active device to the ccd device
59        if not self.servo.enable_ccd_servo_device():
60            raise error.TestNAError('Cannot make ccd active')
61        self.active_dev = self.servo.get_active_device_prefix()
62
63        # Store the original status of EC ec3po_interp_connect.
64        self.ec_ec3po_connect = self.servo.get('ec_ec3po_interp_connect',
65                                               prefix=self.active_dev)
66        # turn off EC ec3po_interp_connect
67        self.servo.set('ec_ec3po_interp_connect', 'off', prefix=self.active_dev)
68        logging.info('Turned off ec3po.')
69
70    def cleanup(self):
71        """Clean up Uart stress test, then cleanup Cr50Test"""
72        try:
73            # Terminate cr50 stressing command run.
74            self.host.run('rm -f ' + FLAG_FILENAME)
75
76            # Restore EC ec3po interpreter connect config.
77            if hasattr(self, 'ec_ec3po_connect'):
78                self.servo.set('ec_ec3po_interp_connect', self.ec_ec3po_connect,
79                               prefix=self.active_dev)
80            logging.info('Recovered ec3po.')
81        finally:
82            # Cleanup super class
83            super(firmware_Cr50CCDUartStress, self).cleanup()
84
85    def run_once(self, duration):
86        """The method called by the control file to start the test.
87
88        Args:
89            duration: time in seconds to run uart_stress_tester.
90
91        Raises:
92            TestFail: uart_stress_tester returned non-zero exit code for
93                      character loss or other reasons.
94        """
95
96        # Run TPM command to stress cr50 in CPU.
97        logging.info('Start to stress cr50 with TPM commands.')
98        self.host.run('touch ' + FLAG_FILENAME)
99        self.host.run('nohup sh -c %r &> /dev/null' % CR50_LOAD_GEN_CMD)
100
101        # Run uart_stress_tester.
102        uart_pty = self.servo.get('raw_ec_uart_pty', prefix=self.active_dev)
103        testcmd = 'uart_stress_tester.py -t %d -d %s' % (duration, uart_pty)
104
105        logging.info('Run Uart stress tester for %d seconds.', duration)
106        logging.info(testcmd)
107        try:
108            self.servo.system(testcmd, timeout=duration*2)
109        except error.AutoservRunError:
110            raise error.TestFail('Uart stress tester failed.')
111
112        logging.info('Uart stress tester passed.')
113