[gnome-settings-daemon] tests: Run under X.org with dummy driver



commit 2df109a6a460b1a17813e544c3c0a85b4aaf4baf
Author: Martin Pitt <martinpitt gnome org>
Date:   Tue Jan 22 08:09:34 2013 +0100

    tests: Run under X.org with dummy driver
    
    Run a private X.org instance with the dummy driver for the tests. The dummy
    driver supports basic XRandR, but no DPMS, which is good enough at least for
    testing most of "power", "keyboard", "multimedia", and others. This is
    necessary until Xvfb supports XRandR, which was proposed in
    <http://lists.x.org/archives/xorg-devel/2013-January/035114.html>.
    
    This makes the tests insensitive against input events from the real X.org which
    happen during the tests, and also allows us to run the tests in headless CI
    server environments.
    
    Some distros like Fedora install Xorg as suid root, so copy the binary into our
    temporary workdir to drop the suid bit and run it as user.

 tests/gsdtestcase.py  |   53 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xorg-dummy.conf |    4 +++
 2 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/tests/gsdtestcase.py b/tests/gsdtestcase.py
index 1e4ae2a..e98b036 100644
--- a/tests/gsdtestcase.py
+++ b/tests/gsdtestcase.py
@@ -56,6 +56,11 @@ class GSDTestCase(dbusmock.DBusTestCase):
         os.environ['LC_MESSAGES'] = 'C'
         klass.workdir = tempfile.mkdtemp(prefix='gsd-power-test')
 
+        # start X.org server with dummy driver; this is needed until Xvfb
+        # supports XRandR:
+        # http://lists.x.org/archives/xorg-devel/2013-January/035114.html
+        klass.start_xorg()
+
         # tell dconf and friends to use our config/runtime directories
         os.environ['XDG_CONFIG_HOME'] = os.path.join(klass.workdir, 'config')
         os.environ['XDG_DATA_HOME'] = os.path.join(klass.workdir, 'data')
@@ -84,6 +89,7 @@ class GSDTestCase(dbusmock.DBusTestCase):
         klass.p_notify.wait()
         klass.stop_session()
         dbusmock.DBusTestCase.tearDownClass()
+        klass.stop_xorg()
         shutil.rmtree(klass.workdir)
 
     def run(self, result=None):
@@ -183,6 +189,53 @@ class GSDTestCase(dbusmock.DBusTestCase):
         self.logind.wait()
 
     @classmethod
+    def start_xorg(klass):
+        '''start X.org server with dummy driver'''
+
+        conf = os.path.join(os.path.dirname(__file__), 'xorg-dummy.conf')
+
+        # some distros like Fedora install Xorg as suid root; copy it into our
+        # workdir to drop the suid bit and run it as user
+        which = subprocess.Popen(['which', 'Xorg'], stdout=subprocess.PIPE)
+        out = which.communicate()[0].strip()
+        if which.returncode != 0 or not out:
+            sys.stderr.write('ERROR: Xorg not installed\n')
+            sys.exit(1)
+        xorg = os.path.join(klass.workdir, 'Xorg')
+        shutil.copy(out, xorg)
+
+        # You can rename the log file to *.log if you want to see it on test
+        # case failures
+        log = os.path.join(klass.workdir, 'Xorg.out')
+        klass.xorg = subprocess.Popen([xorg, '-config', conf, '-logfile', log, ':99'],
+                                      stderr=subprocess.PIPE)
+        os.environ['DISPLAY'] = ':99'
+
+        # wait until the server is ready
+        timeout = 50
+        while timeout > 0:
+            time.sleep(0.1)
+            timeout -= 1
+            if klass.xorg.poll():
+                # ended prematurely
+                timeout = -1
+                break
+            if subprocess.call(['xprop', '-root'], stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE) == 0:
+                break
+        if timeout <= 0:
+            with open(log) as f:
+                sys.stderr.write('Cannot start X.org with dummy driver.  Log:\n%s\n--------' % f.read())
+            sys.exit(1)
+
+    @classmethod
+    def stop_xorg(klass):
+        '''stop X.org server with dummy driver'''
+
+        klass.xorg.terminate()
+        klass.xorg.wait()
+
+    @classmethod
     def reset_idle_timer(klass):
         '''trigger activity to reset idle timer'''
 
diff --git a/tests/xorg-dummy.conf b/tests/xorg-dummy.conf
new file mode 100644
index 0000000..0fc6188
--- /dev/null
+++ b/tests/xorg-dummy.conf
@@ -0,0 +1,4 @@
+Section "Device"
+	Identifier "test"
+	Driver "dummy"
+EndSection



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]