tools: return 77 if gtk_init() fails in the debug-gui
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 26 Jun 2019 05:38:43 +0000 (15:38 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 26 Jun 2019 11:09:22 +0000 (21:09 +1000)
And when that happens, skip the tests because what's happening here is that
you're running tests as root, but your X server doesn't allow root to connect.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
tools/libinput-debug-gui.c
tools/test-tool-option-parsing.py

index 04f4873..629a5cf 100644 (file)
@@ -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);
 
index 594154e..bdfe99b 100755 (executable)
@@ -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)