• 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
6import logging
7import time
8
9from autotest_lib.client.common_lib import error
10from autotest_lib.server.cros.cfm import cfm_base_test
11
12
13LONG_TIMEOUT = 10
14SHORT_TIMEOUT = 5
15FAILED_TEST_LIST = list()
16
17
18class enterprise_CFM_Sanity(cfm_base_test.CfmBaseTest):
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    def _hangouts_sanity_test(self):
33        """Execute a series of test actions and perform verifications.
34
35        @raises error.TestFail if any of the checks fail.
36        """
37        current_time = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
38        hangout_name = 'auto-hangout-' + current_time
39
40        if self.cfm_facade.is_ready_to_start_hangout_session():
41            self.cfm_facade.start_new_hangout_session(hangout_name)
42
43        if not self.cfm_facade.is_in_hangout_session():
44            raise error.TestFail('CFM was not able to start hangout session.')
45
46        time.sleep(LONG_TIMEOUT)
47        self.cfm_facade.unmute_mic()
48
49        if self.cfm_facade.is_ready_to_start_hangout_session():
50            raise error.TestFail('Is already in hangout session and should not '
51                                 'be able to start another session.')
52
53        if self.cfm_facade.is_oobe_start_page():
54            raise error.TestFail('CFM should be in hangout session and not on '
55                                 'oobe screen.')
56
57        time.sleep(SHORT_TIMEOUT)
58        self.cfm_facade.mute_mic()
59        time.sleep(SHORT_TIMEOUT)
60        self.cfm_facade.end_hangout_session()
61
62        if self.cfm_facade.is_in_hangout_session():
63            raise error.TestFail('CFM should not be in hangout session.')
64
65        if self.cfm_facade.is_oobe_start_page():
66            raise error.TestFail('CFM should not be on oobe screen.')
67
68        if not self.cfm_facade.is_ready_to_start_hangout_session():
69            raise error.TestFail('CFM should be in read state to start hangout '
70                           'session.')
71
72
73    def _peripherals_sanity_test(self):
74        """Checks for connected peripherals."""
75        self.cfm_facade.wait_for_telemetry_commands()
76
77        time.sleep(SHORT_TIMEOUT)
78
79        if not self.cfm_facade.get_mic_devices():
80            FAILED_TEST_LIST.append('No mic detected')
81
82        if not self.cfm_facade.get_speaker_devices():
83            FAILED_TEST_LIST.append('No speaker detected')
84
85        if not self.cfm_facade.get_camera_devices():
86            FAILED_TEST_LIST.append('No camera detected')
87
88        if not self.cfm_facade.get_preferred_mic():
89            FAILED_TEST_LIST.append('No preferred mic')
90
91        if not self.cfm_facade.get_preferred_speaker():
92            FAILED_TEST_LIST.append('No preferred speaker')
93
94        if not self.cfm_facade.get_preferred_camera():
95            FAILED_TEST_LIST.append('No preferred camera')
96
97
98    def _diagnostics_sanity_test(self):
99        """Runs hotrod diagnostics and checks status.
100
101        @raise error.TestFail if diagnostic checks fail.
102        """
103        self.cfm_facade.wait_for_telemetry_commands()
104
105        if self.cfm_facade.is_diagnostic_run_in_progress():
106            raise error.TestFail('Diagnostics should not be running.')
107
108        self.cfm_facade.run_diagnostics()
109
110        if not self.cfm_facade.is_diagnostic_run_in_progress():
111            raise error.TestFail('Diagnostics should be running.')
112
113        diag_results = self.cfm_facade.get_last_diagnostics_results()
114
115        if diag_results['status'] not in 'success':
116            logging.debug(diag_results['childrens'])
117            FAILED_TEST_LIST.append('Diagnostics failed')
118
119
120    def run_once(self):
121        """Runs the test."""
122        self.cfm_facade.wait_for_hangouts_telemetry_commands()
123        self._hangouts_sanity_test()
124        self._peripherals_sanity_test()
125        self._diagnostics_sanity_test()
126
127        if FAILED_TEST_LIST:
128            raise error.TestFail('Test failed because of following reasons: %s'
129                                 % ', '.join(map(str, FAILED_TEST_LIST)))
130