on xenial help sign in
Add upstart integration tests.
e246ab5Michał Sawicz
tests/autopilot/unity8/shell/tests/test_upstart.pynew file+80
@@ -0,0 +1,80 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity Autopilot Test Suite
4+# Copyright (C) 2013 Canonical
5+#
6+# This program is free software: you can redistribute it and/or modify
7+# it under the terms of the GNU General Public License as published by
8+# the Free Software Foundation, either version 3 of the License, or
9+# (at your option) any later version.
10+#
11+# This program is distributed in the hope that it will be useful,
12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+# GNU General Public License for more details.
15+#
16+# You should have received a copy of the GNU General Public License
17+# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+#
19+
20+"""Tests for upstart integration."""
21+
22+import os
23+import signal
24+import subprocess
25+
26+from testtools.matchers._basic import Equals
27+from autopilot.matchers import Eventually
28+from autopilot.introspection import get_proxy_object_for_existing_process
29+
30+from unity8 import get_binary_path
31+from unity8.shell.emulators import UnityEmulatorBase
32+from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
33+
34+import logging
35+
36+logger = logging.getLogger(__name__)
37+
38+
39+class UpstartIntegrationTests(UnityTestCase):
40+
41+ scenarios = _get_device_emulation_scenarios()
42+
43+ def _get_status(self):
44+ pid, status = os.waitpid(self.process.pid, os.WUNTRACED | os.WCONTINUED | os.WNOHANG)
45+ logger.debug("Got status: {0}; stopped: {1}; continued: {2}"\
46+ .format(status, os.WIFSTOPPED(status), os.WIFCONTINUED(status)))
47+ return status
48+
49+ def _launch_unity(self):
50+ self.patch_environment("QT_LOAD_TESTABILITY", "1")
51+ self.process = subprocess.Popen([get_binary_path()] + self.unity_geometry_args)
52+ self.addCleanup(lambda: self.process.kill())
53+
54+ def _set_proxy(self):
55+ super(UpstartIntegrationTests, self)._set_proxy(get_proxy_object_for_existing_process(
56+ pid=self.process.pid,
57+ emulator_base=UnityEmulatorBase,
58+ ))
59+
60+ def test_no_sigstop(self):
61+ self.patch_environment("UPSTART_JOB", "foo")
62+ self._launch_unity()
63+ self._set_proxy()
64+
65+ logger.debug("Unity started, waiting for it to be ready.")
66+ self.assertUnityReady()
67+ logger.debug("Unity loaded and ready.")
68+
69+ def test_expect_sigstop(self):
70+ self.patch_environment("UPSTART_JOB", "unity8")
71+ self._launch_unity()
72+ self.assertThat(lambda: os.WIFSTOPPED(self._get_status()), Eventually(Equals(True)), "Unity8 should raise SIGSTOP when ready")
73+
74+ self.process.send_signal(signal.SIGCONT)
75+ self.assertThat(lambda: os.WIFCONTINUED(self._get_status()), Eventually(Equals(True)), "Unity8 should have resumed")
76+
77+ logger.debug("Unity started, waiting for it to be ready.")
78+ self._set_proxy()
79+ self.assertUnityReady()
80+ logger.debug("Unity loaded and ready.")