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__)
44 if sys.version_info < (3,):
48 class UpstartIntegrationTests(UnityTestCase):
50 scenarios = _get_device_emulation_scenarios()
52 def _get_status(self):
53 pid, status = os.waitpid(
54 self.process.pid, os.WUNTRACED | os.WCONTINUED | os.WNOHANG)
56 "Got status: {0}; stopped: {1}; continued: {2}".format(
57 status, os.WIFSTOPPED(status), os.WIFCONTINUED(status)))
60 def _launch_unity(self):
61 self.patch_environment(
"QT_LOAD_TESTABILITY",
"1")
64 host_socket = os.getenv(
"MIR_SOCKET",
"/run/mir_socket")
65 if stat.S_ISSOCK(os.stat(host_socket).st_mode):
66 self.patch_environment(
"MIR_SERVER_HOST_SOCKET",
68 socket = os.path.join(os.getenv(
"XDG_RUNTIME_DIR",
"/tmp"),
70 self.patch_environment(
"MIR_SERVER_FILE", socket)
74 self.process = subprocess.Popen(
75 [get_binary_path()] + self.unity_geometry_args)
78 self.process.terminate()
95 self.addCleanup(ensure_stopped)
98 super(UpstartIntegrationTests, self)._set_proxy(
99 get_proxy_object_for_existing_process(
100 pid=self.process.pid,
101 emulator_base=UnityEmulatorBase,))
103 def test_no_sigstop(self):
105 fixtures.EnvironmentVariable(
106 'UNITY_MIR_EMITS_SIGSTOP', newvalue=
None))
111 lambda: os.WIFSTOPPED(self._get_status()),
112 Eventually(Equals(
True)))
113 except MismatchError:
116 self.process.send_signal(signal.SIGCONT)
117 self.fail(
'Unity8 raised SIGSTOP')
121 logger.debug(
"Unity started, waiting for it to be ready.")
122 self.wait_for_unity()
123 logger.debug(
"Unity loaded and ready.")
125 def test_expect_sigstop(self):
127 fixtures.EnvironmentVariable(
'UNITY_MIR_EMITS_SIGSTOP',
'1'))
130 lambda: os.WIFSTOPPED(self._get_status()),
131 Eventually(Equals(
True)),
"Unity8 should raise SIGSTOP when ready")
133 self.process.send_signal(signal.SIGCONT)
135 lambda: os.WIFCONTINUED(self._get_status()),
136 Eventually(Equals(
True)),
"Unity8 should have resumed")
138 logger.debug(
"Unity started, waiting for it to be ready.")
140 self.wait_for_unity()
141 logger.debug(
"Unity loaded and ready.")