diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c index 04f48731..629a5cf6 100644 --- a/tools/libinput-debug-gui.c +++ b/tools/libinput-debug-gui.c @@ -1492,7 +1492,8 @@ main(int argc, char **argv) const char *seat_or_device = "seat0"; bool verbose = false; - gtk_init(&argc, &argv); + if (!gtk_init_check(&argc, &argv)) + return 77; g_unix_signal_add(SIGINT, signal_handler, NULL); diff --git a/tools/test-tool-option-parsing.py b/tools/test-tool-option-parsing.py index 594154e0..bdfe99b2 100755 --- a/tools/test-tool-option-parsing.py +++ b/tools/test-tool-option-parsing.py @@ -32,28 +32,33 @@ import subprocess import time +def _disable_coredump(): + resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) + + +def run_command(args): + with subprocess.Popen(args, preexec_fn=_disable_coredump, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p: + try: + p.wait(0.7) + except subprocess.TimeoutExpired: + p.send_signal(3) # SIGQUIT + stdout, stderr = p.communicate(timeout=2) + if p.returncode == -3: + p.returncode = 0 + return p.returncode, stdout.decode('UTF-8'), stderr.decode('UTF-8') + + class TestLibinputTool(unittest.TestCase): libinput_tool = 'libinput' subtool = None - def _disable_coredump(self): - resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) - def run_command(self, args): args = [self.libinput_tool] + args if self.subtool is not None: args.insert(1, self.subtool) - with subprocess.Popen(args, preexec_fn=self._disable_coredump, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p: - try: - p.wait(0.7) - except subprocess.TimeoutExpired: - p.send_signal(3) # SIGQUIT - stdout, stderr = p.communicate(timeout=2) - if p.returncode == -3: - p.returncode = 0 - return p.returncode, stdout.decode('UTF-8'), stderr.decode('UTF-8') + return run_command(args) def run_command_success(self, args): rc, stdout, stderr = self.run_command(args) @@ -214,6 +219,12 @@ class TestDebugGUI(TestToolWithOptions, TestLibinputTool): if not os.getenv('DISPLAY') and not os.getenv('WAYLAND_DISPLAY'): raise unittest.SkipTest() + # 77 means gtk_init() failed, which is probably because you can't + # connect to the display server. + rc, _, _ = run_command([TestLibinputTool.libinput_tool, cls.subtool, '--help']) + if rc == 77: + raise unittest.SkipTest() + def test_verbose_quiet(self): rc, stdout, stderr = self.run_command(['--verbose']) self.assertEqual(rc, 0)