20 """Tests for upstart integration."""
29 from testtools.matchers
import Equals, MismatchError
30 from autopilot.matchers
import Eventually
31 from autopilot.introspection
import get_proxy_object_for_existing_process
33 from unity8
import get_binary_path
39 logger = logging.getLogger(__name__)
42 class UpstartIntegrationTests(UnityTestCase):
44 scenarios = _get_device_emulation_scenarios()
46 def _get_status(self):
47 pid, status = os.waitpid(
48 self.process.pid, os.WUNTRACED | os.WCONTINUED | os.WNOHANG)
50 "Got status: {0}; stopped: {1}; continued: {2}".format(
51 status, os.WIFSTOPPED(status), os.WIFCONTINUED(status)))
54 def _launch_unity(self):
55 self.patch_environment(
"QT_LOAD_TESTABILITY",
"1")
58 host_socket = os.getenv(
"MIR_SOCKET",
"/run/mir_socket")
59 if stat.S_ISSOCK(os.stat(host_socket).st_mode):
60 self.patch_environment(
"MIR_SERVER_HOST_SOCKET",
62 socket = os.path.join(os.getenv(
"XDG_RUNTIME_DIR",
"/tmp"),
64 self.patch_environment(
"MIR_SERVER_FILE", socket)
68 self.process = subprocess.Popen(
69 [get_binary_path()] + self.unity_geometry_args)
72 self.process.terminate()
89 self.addCleanup(ensure_stopped)
93 get_proxy_object_for_existing_process(
95 emulator_base=UnityEmulatorBase,))
97 def test_no_sigstop(self):
99 fixtures.EnvironmentVariable(
100 'UNITY_MIR_EMITS_SIGSTOP', newvalue=
None))
105 lambda: os.WIFSTOPPED(self._get_status()),
106 Eventually(Equals(
True)))
107 except MismatchError:
110 self.process.send_signal(signal.SIGCONT)
111 self.fail(
'Unity8 raised SIGSTOP')
115 logger.debug(
"Unity started, waiting for it to be ready.")
116 self.wait_for_unity()
117 logger.debug(
"Unity loaded and ready.")
119 def test_expect_sigstop(self):
121 fixtures.EnvironmentVariable(
'UNITY_MIR_EMITS_SIGSTOP',
'1'))
124 lambda: os.WIFSTOPPED(self._get_status()),
125 Eventually(Equals(
True)),
"Unity8 should raise SIGSTOP when ready")
127 self.process.send_signal(signal.SIGCONT)
129 lambda: os.WIFCONTINUED(self._get_status()),
130 Eventually(Equals(
True)),
"Unity8 should have resumed")
132 logger.debug(
"Unity started, waiting for it to be ready.")
134 self.wait_for_unity()
135 logger.debug(
"Unity loaded and ready.")