1# copyright (c) 2015 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 logging, threading
6import time
7
8from autotest_lib.server import test
9from autotest_lib.client.common_lib import error
10
11_CHROME_PATH = '/opt/google/chrome/chrome'
12_LONG_TIMEOUT = 120
13_DO_NOT_RUN_ON_TYPE = ['CHROMEBOX', 'CHROMEBIT', 'OTHER']
14_DO_NOT_RUN_ON_BOARD = ['monroe']
15_SLEEP_BEFORE_SUSPEND_SEC = 5
16
17class platform_InternalDisplay(test.test):
18    version = 1
19
20    def run_suspend(self):
21        """Suspend i.e. powerd_dbus_suspend and wait
22
23        @returns boot_id for the following resume
24
25        """
26        boot_id = self.host.get_boot_id()
27        thread = threading.Thread(target = self.host.suspend)
28        thread.start()
29        self.host.test_wait_for_sleep(_LONG_TIMEOUT)
30        return boot_id
31
32    def run_once(self,host):
33
34        self.host = host
35
36        board_type = self.host.get_board_type()
37        if board_type in _DO_NOT_RUN_ON_TYPE:
38            raise error.TestNAError('DUT is %s type. Test Skipped' %board_type)
39
40        board = self.host.get_board().split(':')[-1]
41        logging.info(board)
42        if board in _DO_NOT_RUN_ON_BOARD:
43            raise error.TestNAError(
44                'Monroe does not have internal display. Test Skipped')
45
46        self.host.reboot()
47        if self.host.has_internal_display() is not 'internal_display':
48            raise error.TestFail('Internal display is missing after reboot.')
49
50        time.sleep(_SLEEP_BEFORE_SUSPEND_SEC)
51        boot_id = self.run_suspend()
52        logging.info('DUT suspended')
53        self.host.test_wait_for_resume(boot_id, _LONG_TIMEOUT)
54        logging.info('DUT resumed')
55        if self.host.has_internal_display() is not 'internal_display':
56            raise error.TestFail(
57                'Internal display is missing after suspend & resume.')
58
59