summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2018-03-02 18:00:31 +0100
committerBastien Nocera <hadess@hadess.net>2018-03-02 19:07:56 +0100
commite072a23d34a5e8fde780e8feefcfca73ed4bb0c7 (patch)
treed18956a2fbf9a81b11323433af506842ba49dbca /tests
parentbea6b7dff9e008d6de3a0a68aeb986bb53494fb8 (diff)
downloadgnome-settings-daemon-e072a23d34a5e8fde780e8feefcfca73ed4bb0c7.tar.gz
tests: Simplify launching Xvfb
Instead of having 2 loops looking for a free display number, we now have a single one, making the code more comprehensible.
Diffstat (limited to 'tests')
-rw-r--r--tests/gsdtestcase.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/tests/gsdtestcase.py b/tests/gsdtestcase.py
index 48659b72..5c8d7350 100644
--- a/tests/gsdtestcase.py
+++ b/tests/gsdtestcase.py
@@ -189,7 +189,11 @@ class GSDTestCase(dbusmock.DBusTestCase):
# Return the display num, -1 on hard failure, 0 on failure but to try again
@staticmethod
def launch_xorg_with_display_num(klass, xorg, display_num):
- xorg_log_write = open(os.path.join(klass.workdir, 'xorg.log'), 'wb')
+ if os.path.isfile('/tmp/.X%d-lock' % display_num):
+ # Already a lock file for this display_num
+ return 0
+
+ xorg_log_write = open(os.path.join(klass.workdir, 'xorg-%d.log' % display_num), 'wb')
# Composite extension won't load unless at least 24bpp is set
klass.xorg = subprocess.Popen([xorg, ':%d' % display_num, "-screen", "0", "1280x1024x24", "+extension", "GLX"],
@@ -225,18 +229,12 @@ class GSDTestCase(dbusmock.DBusTestCase):
def launch_xorg(klass, xorg):
display_num = 99
- while os.path.isfile('/tmp/.X%d-lock' % display_num) and display_num >= 0:
- display_num = display_num - 1
-
- if display_num == 0:
- return 0
-
ret = klass.launch_xorg_with_display_num(klass, xorg, display_num)
- while ret == 0:
+ while ret == 0 and display_num > 0:
display_num = display_num - 1
ret = klass.launch_xorg_with_display_num(klass, xorg, display_num)
- if ret == -1:
+ if ret == -1 or ret == 0:
sys.stderr.write('Cannot start Xvfb.\n--------')
return 0