mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-08 20:38:08 +02:00
tools: return 77 if gtk_init() fails in the debug-gui
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>
This commit is contained in:
parent
523c82abb5
commit
6a489b0636
2 changed files with 26 additions and 14 deletions
|
|
@ -1492,7 +1492,8 @@ main(int argc, char **argv)
|
||||||
const char *seat_or_device = "seat0";
|
const char *seat_or_device = "seat0";
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
if (!gtk_init_check(&argc, &argv))
|
||||||
|
return 77;
|
||||||
|
|
||||||
g_unix_signal_add(SIGINT, signal_handler, NULL);
|
g_unix_signal_add(SIGINT, signal_handler, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,28 +32,33 @@ import subprocess
|
||||||
import time
|
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):
|
class TestLibinputTool(unittest.TestCase):
|
||||||
libinput_tool = 'libinput'
|
libinput_tool = 'libinput'
|
||||||
subtool = None
|
subtool = None
|
||||||
|
|
||||||
def _disable_coredump(self):
|
|
||||||
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
|
|
||||||
|
|
||||||
def run_command(self, args):
|
def run_command(self, args):
|
||||||
args = [self.libinput_tool] + args
|
args = [self.libinput_tool] + args
|
||||||
if self.subtool is not None:
|
if self.subtool is not None:
|
||||||
args.insert(1, self.subtool)
|
args.insert(1, self.subtool)
|
||||||
|
|
||||||
with subprocess.Popen(args, preexec_fn=self._disable_coredump,
|
return run_command(args)
|
||||||
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')
|
|
||||||
|
|
||||||
def run_command_success(self, args):
|
def run_command_success(self, args):
|
||||||
rc, stdout, stderr = self.run_command(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'):
|
if not os.getenv('DISPLAY') and not os.getenv('WAYLAND_DISPLAY'):
|
||||||
raise unittest.SkipTest()
|
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):
|
def test_verbose_quiet(self):
|
||||||
rc, stdout, stderr = self.run_command(['--verbose'])
|
rc, stdout, stderr = self.run_command(['--verbose'])
|
||||||
self.assertEqual(rc, 0)
|
self.assertEqual(rc, 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue