• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 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
6
7from autotest_lib.client.common_lib import error
8from autotest_lib.client.common_lib.cros import arc
9from autotest_lib.client.common_lib.cros import chrome
10from autotest_lib.client.bin import test
11from autotest_lib.client.bin import utils
12from autotest_lib.client.cros import cros_ui
13
14
15TIMEOUT=5
16SLEEP_INTERVAL=1
17
18
19# TODO(pmalani): Change this to actually talk to midis and make
20# sure basic functionality works.
21class cheets_Midis(test.test):
22    """ Test to verify midis daemon starts correctly.
23
24    A simple test which verifies whether:
25    - midis starts up correctly on ARC container start-up.
26    - midis restarts correctly on logging-out.
27    """
28    version = 1
29
30    def _get_midis_pid(self):
31        """ Get the midis daemon pid using pgrep. """
32        cmd = 'pgrep midis'
33        result = utils.run(cmd, ignore_status=True).stdout
34        try:
35            return int(result)
36        except ValueError:
37            logging.error('Error parsing pgrep result: %s', result)
38            return None
39
40    def _poll_for_midis_pid(self):
41        """ Repeatedly calls _get_midis_pid, until we succeed or timeout. """
42        try:
43            return utils.poll_for_condition(condition=self._get_midis_pid,
44                                            timeout=TIMEOUT,
45                                            sleep_interval=SLEEP_INTERVAL)
46        except utils.TimeoutError:
47            logging.error('Timed out waiting for midis')
48            return None
49
50    def run_once(self):
51        """ Restart Chrome with ARC and check that midis also restarts. """
52
53        old_midis_pid = None
54        session = None
55        with chrome.Chrome(
56            arc_mode=arc.arc_common.ARC_MODE_ENABLED,
57            dont_override_profile=False) as cr:
58            session = cros_ui.get_chrome_session_ident()
59            old_midis_pid = self._poll_for_midis_pid()
60
61        if old_midis_pid == None:
62            raise error.TestFail('midis not running in Chrome OS.')
63
64        cros_ui.wait_for_chrome_ready(session)
65        new_midis_pid = self._poll_for_midis_pid()
66        if new_midis_pid == None:
67            raise error.TestFail('midis not running after Chrome shut down.')
68
69        if new_midis_pid == old_midis_pid:
70            raise error.TestFail('midis didn\'t restart.')
71        logging.info('Restarted midis with pid %d.', new_midis_pid)
72