def initialize(self, host, cfm_test):
        """
        Initializes the test.

        @param host The host the test is run against
        @param cfm_test CfmTest instance to execute.
        """
        (super(ConfigurableCfmTest, self)
            .initialize(host,
                        cfm_test.configuration.run_test_only,
                        cfm_test.configuration.skip_enrollment))
        self.cfm_test = cfm_test
        device_collector = usb_device_collector.UsbDeviceCollector(host)
        port_manager = usb_port_manager.UsbPortManager(host)
        crash_file_detector = crash_detector.CrashDetector(host)
        # Call get_new_crash_files() once. This records the current crash
        # files so that subsequent calls only check the delta, i.e.
        # new crash files from here on.
        crash_file_detector.get_new_crash_files()
        # self.cfm_facade is inherited from CfmBaseTest.
        context = action_context.ActionContext(
                cfm_facade=self.cfm_facade,
                file_contents_collector=HostFileContentsCollector(host),
                host=host,
                usb_device_collector=device_collector,
                usb_port_manager=port_manager,
                crash_detector=crash_file_detector)
        self.test_runner = TestRunner(context)
예제 #2
0
    def run_once(self,
                 host,
                 client_autotest,
                 action_sequence,
                 repeat,
                 usb_list=None,
                 usb_checks=None,
                 crash_check=False,
                 stress_rack=False):
        self.client_autotest = client_autotest
        self.host = host
        self.autotest_client = autotest.Autotest(self.host)
        self.usb_list = usb_list
        self.usb_checks = usb_checks
        self.crash_check = crash_check

        self.suspend_status = False
        self.login_status = False
        self.fail_reasons = list()
        self.action_step = None

        self.plug_port = self.prep_servo_for_test(stress_rack)

        # Unplug, plug, compare usb peripherals, and leave plugged.
        self.check_connected_peripherals()

        action_sequence = action_sequence.upper()
        actions = action_sequence.split(',')
        boot_id = 0
        self.detect_crash = crash_detector.CrashDetector(self.host)
        self.detect_crash.remove_crash_files()

        # Run camera client test to gather media_V4L2_test binary.
        if 'media_v4l2_test' in str(self.usb_checks):
            self.autotest_client.run_test("camera_V4L2")

        for iteration in xrange(1, repeat + 1):
            step = 0
            for action in actions:
                step += 1
                action = action.strip()
                self.action_step = 'STEP %d.%d. %s' % (iteration, step, action)
                logging.info(self.action_step)

                if action == 'RESUME':
                    self.action_resume(boot_id)
                    time.sleep(_WAIT_DELAY)
                elif action == 'OPENLID':
                    self.open_lid(boot_id)
                    time.sleep(_WAIT_DELAY)
                elif action == 'UNPLUG':
                    self.plug_peripherals(False)
                elif action == 'PLUG':
                    self.plug_peripherals(True)
                elif self.suspend_status == False:
                    if action.startswith('LOGIN'):
                        if self.login_status:
                            logging.debug('Skipping login. Already logged in.')
                            continue
                        else:
                            self.action_login()
                            self.login_status = True
                    elif action == 'REBOOT':
                        self.host.reboot()
                        time.sleep(_WAIT_DELAY * 3)
                        self.login_status = False
                    elif action == 'SUSPEND':
                        boot_id = self.action_suspend()
                    elif action == 'CLOSELID':
                        boot_id = self.close_lid()
                else:
                    logging.info('WRONG ACTION: %s .', self.action_step)
                self.check_status()

            if self.fail_reasons:
                raise error.TestFail('Failures reported: %s' %
                                     str(self.fail_reasons))
예제 #3
0
    def run_once(self, host, peripherals_to_check):
        """
        Main function to run autotest.

        @param host: Host object representing the DUT.
        @param peripherals_to_check: List of USB specs to check.
        """
        self.client = host
        self.crash_list = []

        factory = remote_facade_factory.RemoteFacadeFactory(host,
                                                            no_chrome=True)
        self.cfm_facade = factory.create_cfm_facade()

        detect_crash = crash_detector.CrashDetector(self.client)

        tpm_utils.ClearTPMOwnerRequest(self.client)

        factory = remote_facade_factory.RemoteFacadeFactory(host,
                                                            no_chrome=True)
        self.cfm_facade = factory.create_cfm_facade()

        if detect_crash.is_new_crash_present():
            self.crash_list.append('New Warning or Crash Detected before ' +
                                   'plugging in usb peripherals.')

        # Turns on the USB port on the servo so that any peripheral connected to
        # the DUT it is visible.
        if self.client.servo:
            self.client.servo.switch_usbkey('dut')
            self.client.servo.set('usb_mux_sel3', 'dut_sees_usbkey')
            time.sleep(_SHORT_TIMEOUT)
            self.client.servo.set('dut_hub1_rst1', 'off')
            time.sleep(_SHORT_TIMEOUT)

        if detect_crash.is_new_crash_present():
            self.crash_list.append('New Warning or Crash Detected after ' +
                                   'plugging in usb peripherals.')

        cros_peripherals = self._get_cros_usb_peripherals(peripherals_to_check)
        logging.info('Peripherals detected by CrOS: %s', cros_peripherals)

        try:
            self._enroll_device_and_skip_oobe()
            cfm_peripherals = self._get_connected_cfm_hangouts_peripherals(
                peripherals_to_check)
            logging.info('Peripherals detected by hangouts: %s',
                         cfm_peripherals)
        except Exception as e:
            exception_msg = str(e)
            if self.crash_list:
                crash_identified_at = (' ').join(self.crash_list)
                exception_msg += '. ' + crash_identified_at
                self._upload_crash_count(len(detect_crash.get_crash_files()))
            raise error.TestFail(str(exception_msg))

        if detect_crash.is_new_crash_present():
            self.crash_list.append('New Warning or Crash detected after '
                                   'device enrolled into CFM.')

        tpm_utils.ClearTPMOwnerRequest(self.client)

        if self.crash_list:
            crash_identified_at = (', ').join(self.crash_list)
        else:
            crash_identified_at = 'No Crash or Warning detected.'

        self._upload_crash_count(len(detect_crash.get_crash_files()))

        peripherals_diff = cfm_peripherals.get_diff(cros_peripherals)
        if peripherals_diff:
            raise error.TestFail('Peripherals do not match.\n'
                                 'Diff: {0} \n Cros: {1} \n Hangouts: {2} \n.'
                                 'No of Crashes: {3}. Crashes: {4}'.format(
                                     peripherals_diff, cros_peripherals,
                                     cfm_peripherals,
                                     len(detect_crash.get_crash_files()),
                                     crash_identified_at))