Categories
Uncategorized

Linux Input Testing and Debugging

The Linux input layer has made a lot of progress in recent years.  When writing a new input driver (such as keyboard, trackball, etc), it is useful to be able to monitor input events using a test application.  This article describes two ways to accomplish this using kernel input debugging, and the evtest utility.

kernel input debugging

The Linux kernel includes some support for printing input events as debug messages.  To use, set the following in the kernel config:

CONFIG_INPUT_EVBUG=y

Because the print messages are at the KERN_DEBUG level (7), we typically need to change the debug level:

echo 8 > /proc/sys/kernel/printk

At this point, you will see messages like the following on the console:

evbug.c: Event. Dev: gpio-keys/input0, Type: 1, Code: 108, Value: 1
evbug.c: Event. Dev: gpio-keys/input0, Type: 0, Code: 0, Value: 0
evbug.c: Event. Dev: gpio-keys/input0, Type: 1, Code: 103, Value: 1
evbug.c: Event. Dev: gpio-keys/input0, Type: 1, Code: 106, Value: 1
evbug.c: Event. Dev: gpio-keys/input0, Type: 0, Code: 0, Value: 0
evbug.c: Event. Dev: gpio-keys/input0, Type: 1, Code: 103, Value: 0
evbug.c: Event. Dev: gpio-keys/input0, Type: 0, Code: 0, Value: 0
evbug.c: Event. Dev: gpio-keys/input0, Type: 1, Code: 103, Value: 1
evbug.c: Event. Dev: gpio-keys/input0, Type: 0, Code: 0, Value: 0
evbug.c: Event. Dev: <NULL>, Type: 1, Code: 6, Value: 1
evbug.c: Event. Dev: <NULL>, Type: 0, Code: 0, Value: 0
evbug.c: Event. Dev: <NULL>, Type: 1, Code: 6, Value: 0
evbug.c: Event. Dev: <NULL>, Type: 0, Code: 0, Value: 0
evbug.c: Event. Dev: <NULL>, Type: 1, Code: 6, Value: 1
evbug.c: Event. Dev: <NULL>, Type: 0, Code: 0, Value: 0
evbug.c: Event. Dev: <NULL>, Type: 1, Code: 6, Value: 0
evbug.c: Event. Dev: <NULL>, Type: 0, Code: 0, Value: 0

evtest

The linux-input project (http://linuxconsole.sourceforge.net/input/input.html) includes a neat little tool named evtest that is very handy for testing input devices.  If you are using OpenEmbedded, simply:

bitbake linux-input

If you are not using OpenEmbedded, you can glean enough details about how to get and build the this package from the OE recipe:

http://gitweb.openembedded.net/?p=org.openembedded.dev.git;a=blob;f=packages/linux-input/linux-input_cvs.bb

Install the resulting package on your device.   To use, run evtest with a /dev/input/eventx argument:

root@machine1:~$ evtest /dev/input/event0
Input driver version is 1.0.0
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio-keys"
Supported events:
  Event type 0 (Sync)
  Event type 1 (Key)
    Event code 103 (Up)
    Event code 105 (Left)
    Event code 106 (Right)
    Event code 108 (Down)
    Event code 116 (Power)
Testing ... (interrupt to exit)
Event: time 1009.433605, type 1 (Key), code 108 (Down), value 0
Event: time 1009.433737, -------------- Report Sync ------------
Event: time 1010.735605, type 1 (Key), code 108 (Down), value 1
Event: time 1010.735740, -------------- Report Sync ------------
Event: time 1011.075586, type 1 (Key), code 106 (Right), value 1
Event: time 1011.075720, -------------- Report Sync ------------
Event: time 1011.103379, type 1 (Key), code 108 (Down), value 0
Event: time 1011.103550, -------------- Report Sync ------------
Event: time 1011.333924, type 1 (Key), code 108 (Down), value 1
Event: time 1011.334058, -------------- Report Sync ------------
Event: time 1011.339880, type 1 (Key), code 106 (Right), value 0

Notice that evtest lists the keymap when it is initially run which is very handy, and then lists key events as they occur.  The key descriptions are also included with events so you don’t have to manually decode the keycodes.

1 reply on “Linux Input Testing and Debugging”

[…] 1758 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 1759 /* If the last button state is pressed, release it now! */ 1760 if (sd->params.qx3.button) { 1761 /* The camera latch will hold the pressed state until we reset 1762 the latch, so we do not reset sd->params.qx3.button now, to 1763 avoid a false keypress being reported the next sd_start */ 1764 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); 1765 input_sync(gspca_dev->input_dev); 1766 } 1767 #endif You can try to catch KEY_CAMERA input event using the evtest utility as described http://bec-systems.com/site/209/linu…-and-debugging. […]

Comments are closed.