[PATCH 1/2] Abort xi2 tests if ActivateDevice() fails

Alan Coopersmith alan.coopersmith at oracle.com
Tue Sep 23 23:19:58 PDT 2014


I was getting segfaults in xi2 tests from trying to copy XKB keyboard
state to NULL pointers with a stack of:

 0  0x00000000006244d2 in XkbPushLockedStateToSlaves (master=0x7b4650,
    evtype=0, key=0) at xkbActions.c:1189
 1  0x00000000004f450a in EnableDevice (dev=0x7b3810, sendevent=0 '\000')
    at devices.c:420
 2  0x00000000004cf2a7 in init_devices () at protocol-common.c:158
 3  0x00000000004cf5ea in init_simple () at protocol-common.c:259
 4  0x00000000004d090f in main (argc=1, argv=0xffff80ffbfffe458)
    at protocol-xiquerydevice.c:338

which turned out to be due to xkbcomp failure, which was logged in the
test logs as:
XKB: Failed to compile keymap
Keyboard initialization failed. This could be a missing or incorrect setup of xkeyboard-config.

but which was overlooked because the ActivateDevice() return code wasn't
checked and the tests went forward assuming the structures were all
correctly initialized.   This catches the failure closer to the point of
failure, to save debugging time.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/xi2/protocol-common.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/test/xi2/protocol-common.c b/test/xi2/protocol-common.c
index 9a429e4..64a5777 100644
--- a/test/xi2/protocol-common.c
+++ b/test/xi2/protocol-common.c
@@ -137,6 +137,7 @@ init_devices(void)
 {
     ClientRec client;
     struct devices local_devices;
+    int ret;
 
     client = init_client(0, NULL);
 
@@ -145,15 +146,20 @@ init_devices(void)
     inputInfo.pointer = local_devices.vcp;
 
     inputInfo.keyboard = local_devices.vck;
-    ActivateDevice(local_devices.vcp, FALSE);
-    ActivateDevice(local_devices.vck, FALSE);
+    ret = ActivateDevice(local_devices.vcp, FALSE);
+    assert(ret == Success);
+    /* This may fail if xkbcomp fails or xkb-config is not found. */
+    ret = ActivateDevice(local_devices.vck, FALSE);
+    assert(ret == Success);
     EnableDevice(local_devices.vcp, FALSE);
     EnableDevice(local_devices.vck, FALSE);
 
     AllocDevicePair(&client, "", &local_devices.mouse, &local_devices.kbd,
                     TestPointerProc, CoreKeyboardProc, FALSE);
-    ActivateDevice(local_devices.mouse, FALSE);
-    ActivateDevice(local_devices.kbd, FALSE);
+    ret = ActivateDevice(local_devices.mouse, FALSE);
+    assert(ret == Success);
+    ret = ActivateDevice(local_devices.kbd, FALSE);
+    assert(ret == Success);
     EnableDevice(local_devices.mouse, FALSE);
     EnableDevice(local_devices.kbd, FALSE);
 
-- 
1.7.9.2



More information about the xorg-devel mailing list