This file is indexed.

/usr/lib/python3/dist-packages/unity8/shell/tests/test_upstart.py is in unity8-autopilot 8.12+16.04.20160401-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Unity Autopilot Test Suite
# Copyright (C) 2013, 2014, 2015 Canonical
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""Tests for upstart integration."""

import os
import stat
import signal
import subprocess
import time

import fixtures
import ubuntuuitoolkit
from autopilot.matchers import Eventually
from autopilot.introspection import get_proxy_object_for_existing_process
from testtools.matchers import Equals, MismatchError
from ubuntuuitoolkit import ubuntu_scenarios

from unity8 import get_binary_path
from unity8.shell.tests import UnityTestCase

import logging

logger = logging.getLogger(__name__)


class UpstartIntegrationTests(UnityTestCase):

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios()

    def _get_status(self):
        pid, status = os.waitpid(
            self.process.pid, os.WUNTRACED | os.WCONTINUED | os.WNOHANG)
        logger.debug(
            "Got status: {0}; stopped: {1}; continued: {2}".format(
                status, os.WIFSTOPPED(status), os.WIFCONTINUED(status)))
        return status

    def _launch_unity(self):
        self.patch_environment("QT_LOAD_TESTABILITY", "1")

        try:
            host_socket = os.getenv("MIR_SOCKET", "/run/mir_socket")
            if stat.S_ISSOCK(os.stat(host_socket).st_mode):
                self.patch_environment("MIR_SERVER_HOST_SOCKET",
                                       host_socket)
                socket = os.path.join(os.getenv("XDG_RUNTIME_DIR", "/tmp"),
                                      "mir_socket")
                self.patch_environment("MIR_SERVER_FILE", socket)
        except OSError:
            pass

        self.process = subprocess.Popen(
            [get_binary_path()] + self.unity_geometry_args)

        def ensure_stopped():
            self.process.terminate()
            for i in range(10):
                try:
                    self._get_status()
                except OSError:
                    break
                else:
                    time.sleep(1)
            try:
                self._get_status()
            except OSError:
                pass
            else:
                self.process.kill()

            self.process.wait()

        self.addCleanup(ensure_stopped)

    def _set_proxy(self):
        proxy_base = ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
        super()._set_proxy(
            get_proxy_object_for_existing_process(
                pid=self.process.pid,
                emulator_base=proxy_base))

    def test_no_sigstop(self):
        self.useFixture(
            fixtures.EnvironmentVariable(
                'UNITY_MIR_EMITS_SIGSTOP', newvalue=None))
        self._launch_unity()

        try:
            self.assertThat(
                lambda: os.WIFSTOPPED(self._get_status()),
                Eventually(Equals(True)))
        except MismatchError:
            pass
        else:
            self.process.send_signal(signal.SIGCONT)
            self.fail('Unity8 raised SIGSTOP')

        self._set_proxy()

        logger.debug("Unity started, waiting for it to be ready.")
        self.wait_for_unity()
        logger.debug("Unity loaded and ready.")

    def test_expect_sigstop(self):
        self.useFixture(
            fixtures.EnvironmentVariable('UNITY_MIR_EMITS_SIGSTOP', '1'))
        self._launch_unity()
        self.assertThat(
            lambda: os.WIFSTOPPED(self._get_status()),
            Eventually(Equals(True)), "Unity8 should raise SIGSTOP when ready")

        self.process.send_signal(signal.SIGCONT)
        self.assertThat(
            lambda: os.WIFCONTINUED(self._get_status()),
            Eventually(Equals(True)), "Unity8 should have resumed")

        logger.debug("Unity started, waiting for it to be ready.")
        self._set_proxy()
        self.wait_for_unity()
        logger.debug("Unity loaded and ready.")