• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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
5import datetime, logging, time
6
7from autotest_lib.client.common_lib import error
8from autotest_lib.client.common_lib.cros import tpm_utils
9from autotest_lib.server import test
10from autotest_lib.server.cros.multimedia import remote_facade_factory
11
12
13LONG_TIMEOUT = 10
14SHORT_TIMEOUT = 5
15FAILED_TEST_LIST = list()
16
17
18class enterprise_CFM_Sanity(test.test):
19    """Tests the following fuctionality works on CFM enrolled devices:
20           1. Is able to reach the oobe screen
21           2. Is able to start a hangout session
22           3. Should not be able to start a hangout session if already in a
23              session.
24           4. Exits hangout session successfully.
25           5. Should be able to start a hangout session if currently not in
26              a session.
27           6. Is able to detect attached peripherals: mic, speaker, camera.
28           7. Is able to run hotrod diagnostics.
29    """
30    version = 1
31
32
33    def _hangouts_sanity_test(self):
34        """Execute a series of test actions and perform verifications.
35
36        @raises error.TestFail if any of the checks fail.
37        """
38        current_time = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
39        hangout_name = 'auto-hangout-' + current_time
40
41        self.cfm_facade.wait_for_telemetry_commands()
42        self.cfm_facade.wait_for_oobe_start_page()
43
44        if not self.cfm_facade.is_oobe_start_page():
45            raise error.TestFail('CFM did not reach oobe screen.')
46
47        self.cfm_facade.skip_oobe_screen()
48
49        if self.cfm_facade.is_ready_to_start_hangout_session():
50            self.cfm_facade.start_new_hangout_session(hangout_name)
51
52        if not self.cfm_facade.is_in_hangout_session():
53            raise error.TestFail('CFM was not able to start hangout session.')
54
55        time.sleep(LONG_TIMEOUT)
56        self.cfm_facade.unmute_mic()
57
58        if self.cfm_facade.is_ready_to_start_hangout_session():
59            raise error.TestFail('Is already in hangout session and should not '
60                                 'be able to start another session.')
61
62        if self.cfm_facade.is_oobe_start_page():
63            raise error.TestFail('CFM should be in hangout session and not on '
64                                 'oobe screen.')
65
66        time.sleep(SHORT_TIMEOUT)
67        self.cfm_facade.mute_mic()
68        time.sleep(SHORT_TIMEOUT)
69        self.cfm_facade.end_hangout_session()
70
71        if self.cfm_facade.is_in_hangout_session():
72            raise error.TestFail('CFM should not be in hangout session.')
73
74        if self.cfm_facade.is_oobe_start_page():
75            raise error.TestFail('CFM should not be on oobe screen.')
76
77        if not self.cfm_facade.is_ready_to_start_hangout_session():
78            raise error.TestFail('CFM should be in read state to start hangout '
79                           'session.')
80
81
82    def _peripherals_sanity_test(self):
83        """Checks for connected peripherals."""
84        self.cfm_facade.wait_for_telemetry_commands()
85
86        time.sleep(SHORT_TIMEOUT)
87
88        if not self.cfm_facade.get_mic_devices():
89            FAILED_TEST_LIST.append('No mic detected')
90
91        if not self.cfm_facade.get_speaker_devices():
92            FAILED_TEST_LIST.append('No speaker detected')
93
94        if not self.cfm_facade.get_camera_devices():
95            FAILED_TEST_LIST.append('No camera detected')
96
97        if not self.cfm_facade.get_preferred_mic():
98            FAILED_TEST_LIST.append('No preferred mic')
99
100        if not self.cfm_facade.get_preferred_speaker():
101            FAILED_TEST_LIST.append('No preferred speaker')
102
103        if not self.cfm_facade.get_preferred_camera():
104            FAILED_TEST_LIST.append('No preferred camera')
105
106
107    def _diagnostics_sanity_test(self):
108        """Runs hotrod diagnostics and checks status.
109
110        @raise error.TestFail if diagnostic checks fail.
111        """
112        self.cfm_facade.wait_for_telemetry_commands()
113
114        if self.cfm_facade.is_diagnostic_run_in_progress():
115            raise error.TestFail('Diagnostics should not be running.')
116
117        self.cfm_facade.run_diagnostics()
118
119        if not self.cfm_facade.is_diagnostic_run_in_progress():
120            raise error.TestFail('Diagnostics should be running.')
121
122        diag_results = self.cfm_facade.get_last_diagnostics_results()
123
124        if diag_results['status'] not in 'success':
125            logging.debug(diag_results['childrens'])
126            FAILED_TEST_LIST.append('Diagnostics failed')
127
128
129    def run_once(self, host=None):
130        """Runs the test."""
131        self.client = host
132
133        factory = remote_facade_factory.RemoteFacadeFactory(
134                host, no_chrome=True)
135        self.cfm_facade = factory.create_cfm_facade()
136
137        tpm_utils.ClearTPMOwnerRequest(self.client)
138
139        if self.client.servo:
140            self.client.servo.switch_usbkey('dut')
141            self.client.servo.set('usb_mux_sel3', 'dut_sees_usbkey')
142            time.sleep(SHORT_TIMEOUT)
143            self.client.servo.set('dut_hub1_rst1', 'off')
144            time.sleep(SHORT_TIMEOUT)
145
146        try:
147            self.cfm_facade.enroll_device()
148            self.cfm_facade.restart_chrome_for_cfm()
149
150            self._hangouts_sanity_test()
151            self._peripherals_sanity_test()
152            self._diagnostics_sanity_test()
153        except Exception as e:
154            raise error.TestFail(str(e))
155
156        tpm_utils.ClearTPMOwnerRequest(self.client)
157
158        if FAILED_TEST_LIST:
159            raise error.TestFail('Test failed because of following reasons: %s'
160                                 % ', '.join(map(str, FAILED_TEST_LIST)))
161