Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-07-21 12:30:40 +10:00
|
|
|
#include <assert.h>
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
#include <check.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
#include <poll.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <unistd.h>
|
2014-06-03 07:51:37 +10:00
|
|
|
#include "linux/input.h"
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
#include <sys/ptrace.h>
|
|
|
|
|
#include <sys/timerfd.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
|
|
#include "litest.h"
|
|
|
|
|
#include "litest-int.h"
|
|
|
|
|
#include "libinput-util.h"
|
|
|
|
|
|
|
|
|
|
static int in_debugger = -1;
|
2014-06-18 19:51:19 +10:00
|
|
|
static int verbose = 0;
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
|
|
|
|
|
struct test {
|
|
|
|
|
struct list node;
|
|
|
|
|
char *name;
|
|
|
|
|
TCase *tc;
|
|
|
|
|
enum litest_device_type devices;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct suite {
|
|
|
|
|
struct list node;
|
|
|
|
|
struct list tests;
|
|
|
|
|
char *name;
|
|
|
|
|
Suite *suite;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct litest_device *current_device;
|
|
|
|
|
|
|
|
|
|
struct litest_device *litest_current_device(void) {
|
|
|
|
|
return current_device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void litest_set_current_device(struct litest_device *device) {
|
|
|
|
|
current_device = device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void litest_generic_device_teardown(void)
|
|
|
|
|
{
|
|
|
|
|
litest_delete_device(current_device);
|
|
|
|
|
current_device = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern struct litest_test_device litest_keyboard_device;
|
|
|
|
|
extern struct litest_test_device litest_synaptics_clickpad_device;
|
2014-03-24 15:25:32 +10:00
|
|
|
extern struct litest_test_device litest_synaptics_touchpad_device;
|
2014-06-11 08:59:11 +10:00
|
|
|
extern struct litest_test_device litest_synaptics_t440_device;
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
extern struct litest_test_device litest_trackpoint_device;
|
|
|
|
|
extern struct litest_test_device litest_bcm5974_device;
|
2014-01-21 15:18:09 +10:00
|
|
|
extern struct litest_test_device litest_mouse_device;
|
2014-01-22 09:58:43 +10:00
|
|
|
extern struct litest_test_device litest_wacom_touch_device;
|
2014-07-24 13:18:56 +10:00
|
|
|
extern struct litest_test_device litest_alps_device;
|
2014-08-21 11:08:29 +10:00
|
|
|
extern struct litest_test_device litest_generic_singletouch_device;
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
|
|
|
|
|
struct litest_test_device* devices[] = {
|
|
|
|
|
&litest_synaptics_clickpad_device,
|
2014-03-24 15:25:32 +10:00
|
|
|
&litest_synaptics_touchpad_device,
|
2014-06-11 08:59:11 +10:00
|
|
|
&litest_synaptics_t440_device,
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
&litest_keyboard_device,
|
|
|
|
|
&litest_trackpoint_device,
|
|
|
|
|
&litest_bcm5974_device,
|
2014-01-21 15:18:09 +10:00
|
|
|
&litest_mouse_device,
|
2014-01-22 09:58:43 +10:00
|
|
|
&litest_wacom_touch_device,
|
2014-07-24 13:18:56 +10:00
|
|
|
&litest_alps_device,
|
2014-08-21 11:08:29 +10:00
|
|
|
&litest_generic_singletouch_device,
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct list all_tests;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
litest_add_tcase_for_device(struct suite *suite,
|
|
|
|
|
void *func,
|
|
|
|
|
const struct litest_test_device *dev)
|
|
|
|
|
{
|
|
|
|
|
struct test *t;
|
|
|
|
|
const char *test_name = dev->shortname;
|
|
|
|
|
|
|
|
|
|
list_for_each(t, &suite->tests, node) {
|
|
|
|
|
if (strcmp(t->name, test_name) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
tcase_add_test(t->tc, func);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t = zalloc(sizeof(*t));
|
|
|
|
|
t->name = strdup(test_name);
|
|
|
|
|
t->tc = tcase_create(test_name);
|
|
|
|
|
list_insert(&suite->tests, &t->node);
|
2014-03-31 09:38:49 +10:00
|
|
|
tcase_add_checked_fixture(t->tc, dev->setup,
|
|
|
|
|
dev->teardown ? dev->teardown : litest_generic_device_teardown);
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
tcase_add_test(t->tc, func);
|
|
|
|
|
suite_add_tcase(suite->suite, t->tc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
litest_add_tcase_no_device(struct suite *suite, void *func)
|
|
|
|
|
{
|
|
|
|
|
struct test *t;
|
|
|
|
|
const char *test_name = "no device";
|
|
|
|
|
|
|
|
|
|
list_for_each(t, &suite->tests, node) {
|
|
|
|
|
if (strcmp(t->name, test_name) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
tcase_add_test(t->tc, func);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t = zalloc(sizeof(*t));
|
|
|
|
|
t->name = strdup(test_name);
|
|
|
|
|
t->tc = tcase_create(test_name);
|
|
|
|
|
list_insert(&suite->tests, &t->node);
|
|
|
|
|
tcase_add_test(t->tc, func);
|
|
|
|
|
suite_add_tcase(suite->suite, t->tc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
litest_add_tcase(struct suite *suite, void *func,
|
|
|
|
|
enum litest_device_feature required,
|
|
|
|
|
enum litest_device_feature excluded)
|
|
|
|
|
{
|
|
|
|
|
struct litest_test_device **dev = devices;
|
|
|
|
|
|
2014-08-04 12:49:59 +10:00
|
|
|
assert(required >= LITEST_DISABLE_DEVICE);
|
|
|
|
|
assert(excluded >= LITEST_DISABLE_DEVICE);
|
|
|
|
|
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
if (required == LITEST_DISABLE_DEVICE &&
|
|
|
|
|
excluded == LITEST_DISABLE_DEVICE) {
|
|
|
|
|
litest_add_tcase_no_device(suite, func);
|
|
|
|
|
} else if (required != LITEST_ANY || excluded != LITEST_ANY) {
|
|
|
|
|
while (*dev) {
|
|
|
|
|
if (((*dev)->features & required) == required &&
|
|
|
|
|
((*dev)->features & excluded) == 0)
|
|
|
|
|
litest_add_tcase_for_device(suite, func, *dev);
|
|
|
|
|
dev++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
while (*dev) {
|
|
|
|
|
litest_add_tcase_for_device(suite, func, *dev);
|
|
|
|
|
dev++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_add_no_device(const char *name, void *func)
|
|
|
|
|
{
|
|
|
|
|
litest_add(name, func, LITEST_DISABLE_DEVICE, LITEST_DISABLE_DEVICE);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 00:01:10 +02:00
|
|
|
static struct suite *
|
|
|
|
|
get_suite(const char *name)
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
{
|
|
|
|
|
struct suite *s;
|
|
|
|
|
|
|
|
|
|
if (all_tests.next == NULL && all_tests.prev == NULL)
|
|
|
|
|
list_init(&all_tests);
|
|
|
|
|
|
|
|
|
|
list_for_each(s, &all_tests, node) {
|
2014-07-14 00:01:10 +02:00
|
|
|
if (strcmp(s->name, name) == 0)
|
|
|
|
|
return s;
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s = zalloc(sizeof(*s));
|
|
|
|
|
s->name = strdup(name);
|
|
|
|
|
s->suite = suite_create(s->name);
|
|
|
|
|
|
|
|
|
|
list_init(&s->tests);
|
|
|
|
|
list_insert(&all_tests, &s->node);
|
2014-07-14 00:01:10 +02:00
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_add(const char *name,
|
|
|
|
|
void *func,
|
|
|
|
|
enum litest_device_feature required,
|
|
|
|
|
enum litest_device_feature excluded)
|
|
|
|
|
{
|
|
|
|
|
litest_add_tcase(get_suite(name), func, required, excluded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_add_for_device(const char *name,
|
|
|
|
|
void *func,
|
|
|
|
|
enum litest_device_type type)
|
|
|
|
|
{
|
|
|
|
|
struct suite *s;
|
|
|
|
|
struct litest_test_device **dev = devices;
|
|
|
|
|
|
2014-08-04 12:49:59 +10:00
|
|
|
assert(type < LITEST_NO_DEVICE);
|
|
|
|
|
|
2014-07-14 00:01:10 +02:00
|
|
|
s = get_suite(name);
|
|
|
|
|
while (*dev) {
|
|
|
|
|
if ((*dev)->type == type) {
|
|
|
|
|
litest_add_tcase_for_device(s, func, *dev);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dev++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_abort_msg("Invalid test device type");
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
}
|
|
|
|
|
|
2014-06-06 09:44:43 +10:00
|
|
|
static int
|
|
|
|
|
is_debugger_attached(void)
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
int rc;
|
|
|
|
|
int pid = fork();
|
|
|
|
|
|
|
|
|
|
if (pid == -1)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (pid == 0) {
|
|
|
|
|
int ppid = getppid();
|
|
|
|
|
if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0) {
|
|
|
|
|
waitpid(ppid, NULL, 0);
|
|
|
|
|
ptrace(PTRACE_CONT, NULL, NULL);
|
|
|
|
|
ptrace(PTRACE_DETACH, ppid, NULL, NULL);
|
|
|
|
|
rc = 0;
|
|
|
|
|
} else {
|
|
|
|
|
rc = 1;
|
|
|
|
|
}
|
|
|
|
|
_exit(rc);
|
|
|
|
|
} else {
|
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
|
rc = WEXITSTATUS(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
litest_list_tests(struct list *tests)
|
|
|
|
|
{
|
|
|
|
|
struct suite *s;
|
|
|
|
|
|
|
|
|
|
list_for_each(s, tests, node) {
|
|
|
|
|
struct test *t;
|
|
|
|
|
printf("%s:\n", s->name);
|
|
|
|
|
list_for_each(t, &s->tests, node) {
|
|
|
|
|
printf(" %s\n", t->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 15:55:15 +10:00
|
|
|
static void
|
2014-06-18 19:51:19 +10:00
|
|
|
litest_log_handler(struct libinput *libinput,
|
|
|
|
|
enum libinput_log_priority pri,
|
2014-06-06 15:55:15 +10:00
|
|
|
const char *format,
|
|
|
|
|
va_list args)
|
|
|
|
|
{
|
|
|
|
|
const char *priority = NULL;
|
|
|
|
|
|
|
|
|
|
switch(pri) {
|
|
|
|
|
case LIBINPUT_LOG_PRIORITY_INFO: priority = "info"; break;
|
|
|
|
|
case LIBINPUT_LOG_PRIORITY_ERROR: priority = "error"; break;
|
|
|
|
|
case LIBINPUT_LOG_PRIORITY_DEBUG: priority = "debug"; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "litest %s: ", priority);
|
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 11:11:05 +10:00
|
|
|
static int
|
|
|
|
|
open_restricted(const char *path, int flags, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
return open(path, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
close_restricted(int fd, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct libinput_interface interface = {
|
|
|
|
|
.open_restricted = open_restricted,
|
|
|
|
|
.close_restricted = close_restricted,
|
|
|
|
|
};
|
|
|
|
|
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
static const struct option opts[] = {
|
|
|
|
|
{ "list", 0, 0, 'l' },
|
2014-06-06 15:55:15 +10:00
|
|
|
{ "verbose", 0, 0, 'v' },
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
{ 0, 0, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
litest_run(int argc, char **argv) {
|
|
|
|
|
struct suite *s, *snext;
|
|
|
|
|
int failed;
|
|
|
|
|
SRunner *sr = NULL;
|
|
|
|
|
|
|
|
|
|
if (in_debugger == -1) {
|
|
|
|
|
in_debugger = is_debugger_attached();
|
|
|
|
|
if (in_debugger)
|
|
|
|
|
setenv("CK_FORK", "no", 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list_for_each(s, &all_tests, node) {
|
|
|
|
|
if (!sr)
|
|
|
|
|
sr = srunner_create(s->suite);
|
|
|
|
|
else
|
|
|
|
|
srunner_add_suite(sr, s->suite);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
int c;
|
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
2014-01-15 23:24:21 +01:00
|
|
|
c = getopt_long(argc, argv, "", opts, &option_index);
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
if (c == -1)
|
|
|
|
|
break;
|
|
|
|
|
switch(c) {
|
|
|
|
|
case 'l':
|
|
|
|
|
litest_list_tests(&all_tests);
|
|
|
|
|
return 0;
|
2014-06-06 15:55:15 +10:00
|
|
|
case 'v':
|
2014-06-18 19:51:19 +10:00
|
|
|
verbose = 1;
|
2014-06-06 15:55:15 +10:00
|
|
|
break;
|
2014-01-15 23:24:21 +01:00
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "usage: %s [--list]\n", argv[0]);
|
|
|
|
|
return 1;
|
|
|
|
|
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 12:40:59 +10:00
|
|
|
srunner_run_all(sr, CK_ENV);
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
failed = srunner_ntests_failed(sr);
|
|
|
|
|
srunner_free(sr);
|
|
|
|
|
|
|
|
|
|
list_for_each_safe(s, snext, &all_tests, node) {
|
|
|
|
|
struct test *t, *tnext;
|
|
|
|
|
|
|
|
|
|
list_for_each_safe(t, tnext, &s->tests, node) {
|
|
|
|
|
free(t->name);
|
|
|
|
|
list_remove(&t->node);
|
|
|
|
|
free(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list_remove(&s->node);
|
|
|
|
|
free(s->name);
|
|
|
|
|
free(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return failed;
|
|
|
|
|
}
|
|
|
|
|
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
static struct input_absinfo *
|
|
|
|
|
merge_absinfo(const struct input_absinfo *orig,
|
|
|
|
|
const struct input_absinfo *override)
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
{
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
struct input_absinfo *abs;
|
2014-07-03 11:00:54 +10:00
|
|
|
unsigned int nelem, i;
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
size_t sz = ABS_MAX + 1;
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
if (!orig)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
abs = calloc(sz, sizeof(*abs));
|
|
|
|
|
ck_assert(abs != NULL);
|
|
|
|
|
|
|
|
|
|
nelem = 0;
|
|
|
|
|
while (orig[nelem].value != -1) {
|
|
|
|
|
abs[nelem] = orig[nelem];
|
|
|
|
|
nelem++;
|
|
|
|
|
ck_assert_int_lt(nelem, sz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* just append, if the same axis is present twice, libevdev will
|
|
|
|
|
only use the last value anyway */
|
|
|
|
|
i = 0;
|
|
|
|
|
while (override && override[i].value != -1) {
|
|
|
|
|
abs[nelem++] = override[i++];
|
|
|
|
|
ck_assert_int_lt(nelem, sz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_lt(nelem, sz);
|
|
|
|
|
abs[nelem].value = -1;
|
|
|
|
|
|
|
|
|
|
return abs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int*
|
|
|
|
|
merge_events(const int *orig, const int *override)
|
|
|
|
|
{
|
|
|
|
|
int *events;
|
2014-07-03 11:00:54 +10:00
|
|
|
unsigned int nelem, i;
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
size_t sz = KEY_MAX * 3;
|
|
|
|
|
|
|
|
|
|
if (!orig)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
events = calloc(sz, sizeof(int));
|
|
|
|
|
ck_assert(events != NULL);
|
|
|
|
|
|
|
|
|
|
nelem = 0;
|
|
|
|
|
while (orig[nelem] != -1) {
|
|
|
|
|
events[nelem] = orig[nelem];
|
|
|
|
|
nelem++;
|
|
|
|
|
ck_assert_int_lt(nelem, sz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* just append, if the same axis is present twice, libevdev will
|
|
|
|
|
* ignore the double definition anyway */
|
|
|
|
|
i = 0;
|
|
|
|
|
while (override && override[i] != -1) {
|
|
|
|
|
events[nelem++] = override[i++];
|
|
|
|
|
ck_assert_int_le(nelem, sz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_lt(nelem, sz);
|
|
|
|
|
events[nelem] = -1;
|
|
|
|
|
|
|
|
|
|
return events;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct litest_device *
|
|
|
|
|
litest_create(enum litest_device_type which,
|
|
|
|
|
const char *name_override,
|
|
|
|
|
struct input_id *id_override,
|
|
|
|
|
const struct input_absinfo *abs_override,
|
|
|
|
|
const int *events_override)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *d = NULL;
|
|
|
|
|
struct litest_test_device **dev;
|
|
|
|
|
const char *name;
|
|
|
|
|
const struct input_id *id;
|
|
|
|
|
struct input_absinfo *abs;
|
|
|
|
|
int *events;
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
|
|
|
|
|
dev = devices;
|
|
|
|
|
while (*dev) {
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
if ((*dev)->type == which)
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
break;
|
|
|
|
|
dev++;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 22:56:01 +01:00
|
|
|
if (!*dev)
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
ck_abort_msg("Invalid device type %d\n", which);
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
|
|
|
|
|
d = zalloc(sizeof(*d));
|
|
|
|
|
ck_assert(d != NULL);
|
|
|
|
|
|
|
|
|
|
/* device has custom create method */
|
|
|
|
|
if ((*dev)->create) {
|
|
|
|
|
(*dev)->create(d);
|
|
|
|
|
if (abs_override || events_override)
|
|
|
|
|
ck_abort_msg("Custom create cannot"
|
|
|
|
|
"be overridden");
|
|
|
|
|
|
|
|
|
|
return d;
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
}
|
|
|
|
|
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
abs = merge_absinfo((*dev)->absinfo, abs_override);
|
|
|
|
|
events = merge_events((*dev)->events, events_override);
|
|
|
|
|
name = name_override ? name_override : (*dev)->name;
|
|
|
|
|
id = id_override ? id_override : (*dev)->id;
|
|
|
|
|
|
|
|
|
|
d->uinput = litest_create_uinput_device_from_description(name,
|
|
|
|
|
id,
|
|
|
|
|
abs,
|
|
|
|
|
events);
|
|
|
|
|
d->interface = (*dev)->interface;
|
|
|
|
|
free(abs);
|
|
|
|
|
free(events);
|
|
|
|
|
|
|
|
|
|
return d;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-22 15:06:34 +01:00
|
|
|
struct libinput *
|
|
|
|
|
litest_create_context(void)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *libinput =
|
|
|
|
|
libinput_path_create_context(&interface, NULL);
|
|
|
|
|
ck_assert_notnull(libinput);
|
2014-06-18 19:51:19 +10:00
|
|
|
|
|
|
|
|
libinput_log_set_handler(libinput, litest_log_handler);
|
|
|
|
|
if (verbose)
|
|
|
|
|
libinput_log_set_priority(libinput, LIBINPUT_LOG_PRIORITY_DEBUG);
|
|
|
|
|
|
2014-02-22 15:06:34 +01:00
|
|
|
return libinput;
|
|
|
|
|
}
|
|
|
|
|
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
struct litest_device *
|
2014-02-22 15:06:34 +01:00
|
|
|
litest_add_device_with_overrides(struct libinput *libinput,
|
|
|
|
|
enum litest_device_type which,
|
|
|
|
|
const char *name_override,
|
|
|
|
|
struct input_id *id_override,
|
|
|
|
|
const struct input_absinfo *abs_override,
|
|
|
|
|
const int *events_override)
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
{
|
|
|
|
|
struct litest_device *d;
|
|
|
|
|
int fd;
|
|
|
|
|
int rc;
|
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
|
|
d = litest_create(which,
|
|
|
|
|
name_override,
|
|
|
|
|
id_override,
|
|
|
|
|
abs_override,
|
|
|
|
|
events_override);
|
|
|
|
|
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
path = libevdev_uinput_get_devnode(d->uinput);
|
|
|
|
|
ck_assert(path != NULL);
|
|
|
|
|
fd = open(path, O_RDWR|O_NONBLOCK);
|
|
|
|
|
ck_assert_int_ne(fd, -1);
|
|
|
|
|
|
|
|
|
|
rc = libevdev_new_from_fd(fd, &d->evdev);
|
|
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
|
2014-02-22 15:06:34 +01:00
|
|
|
d->libinput = libinput;
|
2014-01-29 15:38:48 +10:00
|
|
|
d->libinput_device = libinput_path_add_device(d->libinput, path);
|
|
|
|
|
ck_assert(d->libinput_device != NULL);
|
|
|
|
|
libinput_device_ref(d->libinput_device);
|
|
|
|
|
|
2014-03-31 10:00:16 +10:00
|
|
|
if (d->interface) {
|
|
|
|
|
d->interface->min[ABS_X] = libevdev_get_abs_minimum(d->evdev, ABS_X);
|
|
|
|
|
d->interface->max[ABS_X] = libevdev_get_abs_maximum(d->evdev, ABS_X);
|
|
|
|
|
d->interface->min[ABS_Y] = libevdev_get_abs_minimum(d->evdev, ABS_Y);
|
|
|
|
|
d->interface->max[ABS_Y] = libevdev_get_abs_maximum(d->evdev, ABS_Y);
|
|
|
|
|
}
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-22 15:06:34 +01:00
|
|
|
struct litest_device *
|
|
|
|
|
litest_create_device_with_overrides(enum litest_device_type which,
|
|
|
|
|
const char *name_override,
|
|
|
|
|
struct input_id *id_override,
|
|
|
|
|
const struct input_absinfo *abs_override,
|
|
|
|
|
const int *events_override)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev =
|
|
|
|
|
litest_add_device_with_overrides(litest_create_context(),
|
|
|
|
|
which,
|
|
|
|
|
name_override,
|
|
|
|
|
id_override,
|
|
|
|
|
abs_override,
|
|
|
|
|
events_override);
|
|
|
|
|
dev->owns_context = true;
|
|
|
|
|
return dev;
|
|
|
|
|
}
|
|
|
|
|
|
test: allow partial overriding the test devices
For specific tests we need something that e.g. looks like a touchpad, but has
a different name, a different number of slots, etc. In this case, the
following code will do exactly that:
struct input_absinfo overrides[] = {
{ .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
{ .value = -1 },
};
litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
NULL, NULL, &overrides, NULL);
For general event codes, overrides can only add to the set of events, they
can't remove.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-31 14:54:46 +10:00
|
|
|
struct litest_device *
|
|
|
|
|
litest_create_device(enum litest_device_type which)
|
|
|
|
|
{
|
|
|
|
|
return litest_create_device_with_overrides(which, NULL, NULL, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
int
|
|
|
|
|
litest_handle_events(struct litest_device *d)
|
|
|
|
|
{
|
|
|
|
|
struct pollfd fd;
|
|
|
|
|
|
|
|
|
|
fd.fd = libinput_get_fd(d->libinput);
|
|
|
|
|
fd.events = POLLIN;
|
|
|
|
|
|
|
|
|
|
while (poll(&fd, 1, 1))
|
|
|
|
|
libinput_dispatch(d->libinput);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_delete_device(struct litest_device *d)
|
|
|
|
|
{
|
|
|
|
|
if (!d)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
libinput_device_unref(d->libinput_device);
|
2014-07-14 00:04:14 +02:00
|
|
|
libinput_path_remove_device(d->libinput_device);
|
2014-02-22 15:06:34 +01:00
|
|
|
if (d->owns_context)
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(d->libinput);
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
libevdev_free(d->evdev);
|
|
|
|
|
libevdev_uinput_destroy(d->uinput);
|
2014-07-24 13:18:56 +10:00
|
|
|
free(d->private);
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
memset(d,0, sizeof(*d));
|
|
|
|
|
free(d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_event(struct litest_device *d, unsigned int type,
|
|
|
|
|
unsigned int code, int value)
|
|
|
|
|
{
|
2014-07-14 23:33:51 +02:00
|
|
|
int ret = libevdev_uinput_write_event(d->uinput, type, code, value);
|
|
|
|
|
ck_assert_int_eq(ret, 0);
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
}
|
|
|
|
|
|
2014-07-24 13:18:56 +10:00
|
|
|
int
|
|
|
|
|
litest_auto_assign_value(struct litest_device *d,
|
|
|
|
|
const struct input_event *ev,
|
|
|
|
|
int slot, double x, double y)
|
2014-03-31 10:00:16 +10:00
|
|
|
{
|
|
|
|
|
static int tracking_id;
|
|
|
|
|
int value = ev->value;
|
|
|
|
|
|
|
|
|
|
if (value != LITEST_AUTO_ASSIGN || ev->type != EV_ABS)
|
|
|
|
|
return value;
|
|
|
|
|
|
|
|
|
|
switch (ev->code) {
|
|
|
|
|
case ABS_X:
|
|
|
|
|
case ABS_MT_POSITION_X:
|
|
|
|
|
value = litest_scale(d, ABS_X, x);
|
|
|
|
|
break;
|
|
|
|
|
case ABS_Y:
|
|
|
|
|
case ABS_MT_POSITION_Y:
|
|
|
|
|
value = litest_scale(d, ABS_Y, y);
|
|
|
|
|
break;
|
|
|
|
|
case ABS_MT_TRACKING_ID:
|
|
|
|
|
value = ++tracking_id;
|
|
|
|
|
break;
|
|
|
|
|
case ABS_MT_SLOT:
|
|
|
|
|
value = slot;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 12:30:40 +10:00
|
|
|
static void
|
|
|
|
|
send_btntool(struct litest_device *d)
|
|
|
|
|
{
|
|
|
|
|
litest_event(d, EV_KEY, BTN_TOUCH, d->ntouches_down != 0);
|
|
|
|
|
litest_event(d, EV_KEY, BTN_TOOL_FINGER, d->ntouches_down == 1);
|
|
|
|
|
litest_event(d, EV_KEY, BTN_TOOL_DOUBLETAP, d->ntouches_down == 2);
|
|
|
|
|
litest_event(d, EV_KEY, BTN_TOOL_TRIPLETAP, d->ntouches_down == 3);
|
|
|
|
|
litest_event(d, EV_KEY, BTN_TOOL_QUADTAP, d->ntouches_down == 4);
|
|
|
|
|
litest_event(d, EV_KEY, BTN_TOOL_QUINTTAP, d->ntouches_down == 5);
|
|
|
|
|
}
|
2014-03-31 10:00:16 +10:00
|
|
|
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
void
|
2014-07-18 16:01:10 +10:00
|
|
|
litest_touch_down(struct litest_device *d, unsigned int slot,
|
|
|
|
|
double x, double y)
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
{
|
2014-03-31 10:00:16 +10:00
|
|
|
struct input_event *ev;
|
|
|
|
|
|
2014-07-21 12:30:40 +10:00
|
|
|
assert(++d->ntouches_down > 0);
|
|
|
|
|
|
|
|
|
|
send_btntool(d);
|
|
|
|
|
|
2014-03-31 10:00:16 +10:00
|
|
|
if (d->interface->touch_down) {
|
|
|
|
|
d->interface->touch_down(d, slot, x, y);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ev = d->interface->touch_down_events;
|
|
|
|
|
while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
|
2014-07-24 13:18:56 +10:00
|
|
|
int value = litest_auto_assign_value(d, ev, slot, x, y);
|
2014-03-31 10:00:16 +10:00
|
|
|
litest_event(d, ev->type, ev->code, value);
|
|
|
|
|
ev++;
|
|
|
|
|
}
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_touch_up(struct litest_device *d, unsigned int slot)
|
|
|
|
|
{
|
|
|
|
|
struct input_event *ev;
|
|
|
|
|
struct input_event up[] = {
|
2014-03-31 10:00:16 +10:00
|
|
|
{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = -1 },
|
|
|
|
|
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
|
2014-03-31 10:00:16 +10:00
|
|
|
{ .type = -1, .code = -1 }
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
};
|
|
|
|
|
|
2014-07-21 12:30:40 +10:00
|
|
|
assert(--d->ntouches_down >= 0);
|
|
|
|
|
|
|
|
|
|
send_btntool(d);
|
|
|
|
|
|
2014-03-24 15:25:32 +10:00
|
|
|
if (d->interface->touch_up) {
|
|
|
|
|
d->interface->touch_up(d, slot);
|
2014-03-31 10:00:16 +10:00
|
|
|
return;
|
|
|
|
|
} else if (d->interface->touch_up_events) {
|
|
|
|
|
ev = d->interface->touch_up_events;
|
|
|
|
|
} else
|
|
|
|
|
ev = up;
|
|
|
|
|
|
|
|
|
|
while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
|
2014-07-24 13:18:56 +10:00
|
|
|
int value = litest_auto_assign_value(d, ev, slot, 0, 0);
|
2014-03-31 10:00:16 +10:00
|
|
|
litest_event(d, ev->type, ev->code, value);
|
|
|
|
|
ev++;
|
2014-03-24 15:25:32 +10:00
|
|
|
}
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-07-18 16:01:10 +10:00
|
|
|
litest_touch_move(struct litest_device *d, unsigned int slot,
|
|
|
|
|
double x, double y)
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
{
|
2014-03-31 10:00:16 +10:00
|
|
|
struct input_event *ev;
|
|
|
|
|
|
|
|
|
|
if (d->interface->touch_move) {
|
|
|
|
|
d->interface->touch_move(d, slot, x, y);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ev = d->interface->touch_move_events;
|
|
|
|
|
while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
|
2014-07-24 13:18:56 +10:00
|
|
|
int value = litest_auto_assign_value(d, ev, slot, x, y);
|
2014-03-31 10:00:16 +10:00
|
|
|
litest_event(d, ev->type, ev->code, value);
|
|
|
|
|
ev++;
|
|
|
|
|
}
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_touch_move_to(struct litest_device *d,
|
|
|
|
|
unsigned int slot,
|
2014-07-18 16:01:10 +10:00
|
|
|
double x_from, double y_from,
|
|
|
|
|
double x_to, double y_to,
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
int steps)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < steps - 1; i++)
|
|
|
|
|
litest_touch_move(d, slot,
|
|
|
|
|
x_from + (x_to - x_from)/steps * i,
|
|
|
|
|
y_from + (y_to - y_from)/steps * i);
|
|
|
|
|
litest_touch_move(d, slot, x_to, y_to);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-03-25 22:56:58 +01:00
|
|
|
litest_button_click(struct litest_device *d, unsigned int button, bool is_press)
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
struct input_event *ev;
|
|
|
|
|
struct input_event click[] = {
|
|
|
|
|
{ .type = EV_KEY, .code = button, .value = is_press ? 1 : 0 },
|
|
|
|
|
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ARRAY_FOR_EACH(click, ev)
|
|
|
|
|
litest_event(d, ev->type, ev->code, ev->value);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 22:24:10 +02:00
|
|
|
void
|
|
|
|
|
litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press)
|
|
|
|
|
{
|
|
|
|
|
litest_button_click(d, key, is_press);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-18 16:01:10 +10:00
|
|
|
int
|
|
|
|
|
litest_scale(const struct litest_device *d, unsigned int axis, double val)
|
Add a device test suite
A rather large commit, copied from a similar (almost identical) suite in
libtouchpad and ported for libinput.
The goal here is to make testing for various devices easy, so the litest
("libinput test") wrappers do that. The idea is that each device has some
features, and tests are likely to exercise some features or won't work with
other features.
Each test case takes a list of required features and a list of excluded
features. The test suite will create a new test case for each device in the
suite that matches that set.
For example, the set of required LITEST_TOUCHPAD, excluded LITEST_BUTTON would
run on clickpads only, not on touchpads with buttons.
check supports suites and test cases, both named. We wrap that so that each
named set of cases we add are a test suite, with the set of devices being the
test cases. i.e.
litest_add("foo:bar", some_test_function, LITEST_ANY, LITEST_ANY);
adds a suite named "foo:bar" and test cases for both devices given, with their
shortnames as test case name, resulting in:
"foo:bar", "trackpoint"
"foo:bar", "clickpad"
...
Multiple test functions can be added to a suite. For tests without a device
requirement there is litest_add_no_device_test(...).
The environment variables CK_RUN_SUITE and CK_RUN_CASE can be used to narrow
the set of test cases. The test suite detects when run inside a debugger and
disables fork mode (the default).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 15:02:11 +10:00
|
|
|
{
|
|
|
|
|
int min, max;
|
|
|
|
|
ck_assert_int_ge(val, 0);
|
|
|
|
|
ck_assert_int_le(val, 100);
|
|
|
|
|
ck_assert_int_le(axis, ABS_Y);
|
|
|
|
|
|
|
|
|
|
min = d->interface->min[axis];
|
|
|
|
|
max = d->interface->max[axis];
|
|
|
|
|
return (max - min) * val/100.0 + min;
|
|
|
|
|
}
|
2014-01-22 11:20:50 +10:00
|
|
|
|
2014-08-20 17:15:50 +10:00
|
|
|
void
|
|
|
|
|
litest_wait_for_event(struct libinput *li)
|
|
|
|
|
{
|
|
|
|
|
return litest_wait_for_event_of_type(li, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_wait_for_event_of_type(struct libinput *li, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
enum libinput_event_type types[32] = {LIBINPUT_EVENT_NONE};
|
|
|
|
|
size_t ntypes = 0;
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
|
|
|
|
|
va_start(args, li);
|
|
|
|
|
type = va_arg(args, int);
|
|
|
|
|
while ((int)type != -1) {
|
|
|
|
|
assert(type > 0);
|
|
|
|
|
assert(ntypes < ARRAY_LENGTH(types));
|
|
|
|
|
types[ntypes++] = type;
|
2014-09-01 12:39:38 +10:00
|
|
|
type = va_arg(args, int);
|
2014-08-20 17:15:50 +10:00
|
|
|
}
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
size_t i;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
|
|
|
|
|
while ((type = libinput_next_event_type(li)) == LIBINPUT_EVENT_NONE) {
|
|
|
|
|
msleep(10);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* no event mask means wait for any event */
|
|
|
|
|
if (ntypes == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ntypes; i++) {
|
|
|
|
|
if (type == types[i])
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-22 11:20:50 +10:00
|
|
|
void
|
|
|
|
|
litest_drain_events(struct libinput *li)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
}
|
|
|
|
|
}
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
|
2014-06-06 10:58:11 +10:00
|
|
|
static void
|
|
|
|
|
litest_print_event(struct libinput_event *event)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event_pointer *p;
|
|
|
|
|
struct libinput_device *dev;
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
double x, y;
|
|
|
|
|
|
|
|
|
|
dev = libinput_event_get_device(event);
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"device %s type %d ",
|
|
|
|
|
libinput_device_get_sysname(dev),
|
|
|
|
|
type);
|
|
|
|
|
switch (type) {
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION:
|
|
|
|
|
p = libinput_event_get_pointer_event(event);
|
|
|
|
|
x = libinput_event_pointer_get_dx(p);
|
|
|
|
|
y = libinput_event_pointer_get_dy(p);
|
|
|
|
|
fprintf(stderr, "motion: %.2f/%.2f", x, y);
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
|
|
|
|
|
p = libinput_event_get_pointer_event(event);
|
|
|
|
|
x = libinput_event_pointer_get_absolute_x(p);
|
|
|
|
|
y = libinput_event_pointer_get_absolute_y(p);
|
|
|
|
|
fprintf(stderr, "motion: %.2f/%.2f", x, y);
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_BUTTON:
|
|
|
|
|
p = libinput_event_get_pointer_event(event);
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"button: %d state %d",
|
|
|
|
|
libinput_event_pointer_get_button(p),
|
|
|
|
|
libinput_event_pointer_get_button_state(p));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_assert_empty_queue(struct libinput *li)
|
|
|
|
|
{
|
|
|
|
|
bool empty_queue = true;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
empty_queue = false;
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Unexpected event: ");
|
|
|
|
|
litest_print_event(event);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert(empty_queue);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 10:00:16 +10:00
|
|
|
struct libevdev_uinput *
|
|
|
|
|
litest_create_uinput_device_from_description(const char *name,
|
|
|
|
|
const struct input_id *id,
|
2014-07-15 15:35:20 +10:00
|
|
|
const struct input_absinfo *abs_info,
|
2014-03-31 10:00:16 +10:00
|
|
|
const int *events)
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
{
|
|
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int type, code;
|
2014-07-15 15:35:20 +10:00
|
|
|
int rc, fd;
|
|
|
|
|
const struct input_absinfo *abs;
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
const struct input_absinfo default_abs = {
|
|
|
|
|
.value = 0,
|
|
|
|
|
.minimum = 0,
|
|
|
|
|
.maximum = 0xffff,
|
|
|
|
|
.fuzz = 0,
|
|
|
|
|
.flat = 0,
|
|
|
|
|
.resolution = 100
|
|
|
|
|
};
|
2014-06-24 16:23:12 +02:00
|
|
|
char buf[512];
|
2014-07-15 15:35:20 +10:00
|
|
|
const char *devnode;
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
|
|
|
|
|
dev = libevdev_new();
|
|
|
|
|
ck_assert(dev != NULL);
|
|
|
|
|
|
2014-06-24 16:23:12 +02:00
|
|
|
snprintf(buf, sizeof(buf), "litest %s", name);
|
|
|
|
|
libevdev_set_name(dev, buf);
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
if (id) {
|
|
|
|
|
libevdev_set_id_bustype(dev, id->bustype);
|
|
|
|
|
libevdev_set_id_vendor(dev, id->vendor);
|
|
|
|
|
libevdev_set_id_product(dev, id->product);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-15 15:35:20 +10:00
|
|
|
abs = abs_info;
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
while (abs && abs->value != -1) {
|
|
|
|
|
rc = libevdev_enable_event_code(dev, EV_ABS,
|
|
|
|
|
abs->value, abs);
|
|
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
abs++;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 10:00:16 +10:00
|
|
|
while (events &&
|
|
|
|
|
(type = *events++) != -1 &&
|
|
|
|
|
(code = *events++) != -1) {
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
if (type == INPUT_PROP_MAX) {
|
|
|
|
|
rc = libevdev_enable_property(dev, code);
|
|
|
|
|
} else {
|
|
|
|
|
rc = libevdev_enable_event_code(dev, type, code,
|
|
|
|
|
type == EV_ABS ? &default_abs : NULL);
|
|
|
|
|
}
|
|
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = libevdev_uinput_create_from_device(dev,
|
|
|
|
|
LIBEVDEV_UINPUT_OPEN_MANAGED,
|
|
|
|
|
&uinput);
|
2014-09-17 10:30:45 +10:00
|
|
|
/* workaround for a bug in libevdev pre-1.3
|
|
|
|
|
http://cgit.freedesktop.org/libevdev/commit/?id=debe9b030c8069cdf78307888ef3b65830b25122 */
|
|
|
|
|
if (rc == -EBADF)
|
|
|
|
|
rc = -EACCES;
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
|
2014-07-15 15:35:20 +10:00
|
|
|
/* uinput does not yet support setting the resolution, so we set it
|
|
|
|
|
* afterwards. This is of course racy as hell but the way we
|
|
|
|
|
* _generally_ use this function by the time libinput uses the
|
|
|
|
|
* device, we're finished here */
|
|
|
|
|
|
|
|
|
|
devnode = libevdev_uinput_get_devnode(uinput);
|
|
|
|
|
ck_assert_notnull(devnode);
|
|
|
|
|
fd = open(devnode, O_RDONLY);
|
|
|
|
|
ck_assert_int_gt(fd, -1);
|
|
|
|
|
rc = libevdev_new_from_fd(fd, &dev);
|
|
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
|
|
|
|
|
abs = abs_info;
|
|
|
|
|
while (abs && abs->value != -1) {
|
|
|
|
|
if (abs->resolution != 0) {
|
|
|
|
|
rc = libevdev_kernel_set_abs_info(dev,
|
|
|
|
|
abs->value,
|
|
|
|
|
abs);
|
|
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
}
|
|
|
|
|
abs++;
|
|
|
|
|
}
|
|
|
|
|
close(fd);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
return uinput;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 10:00:16 +10:00
|
|
|
static struct libevdev_uinput *
|
|
|
|
|
litest_create_uinput_abs_device_v(const char *name,
|
|
|
|
|
struct input_id *id,
|
|
|
|
|
const struct input_absinfo *abs,
|
|
|
|
|
va_list args)
|
|
|
|
|
{
|
|
|
|
|
int events[KEY_MAX * 2 + 2]; /* increase this if not sufficient */
|
|
|
|
|
int *event = events;
|
|
|
|
|
int type, code;
|
|
|
|
|
|
|
|
|
|
while ((type = va_arg(args, int)) != -1 &&
|
|
|
|
|
(code = va_arg(args, int)) != -1) {
|
|
|
|
|
*event++ = type;
|
|
|
|
|
*event++ = code;
|
|
|
|
|
ck_assert(event < &events[ARRAY_LENGTH(events) - 2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*event++ = -1;
|
|
|
|
|
*event++ = -1;
|
|
|
|
|
|
|
|
|
|
return litest_create_uinput_device_from_description(name, id,
|
|
|
|
|
abs, events);
|
|
|
|
|
}
|
|
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
struct libevdev_uinput *
|
|
|
|
|
litest_create_uinput_abs_device(const char *name,
|
|
|
|
|
struct input_id *id,
|
|
|
|
|
const struct input_absinfo *abs,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start(args, abs);
|
|
|
|
|
uinput = litest_create_uinput_abs_device_v(name, id, abs, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
return uinput;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct libevdev_uinput *
|
|
|
|
|
litest_create_uinput_device(const char *name, struct input_id *id, ...)
|
|
|
|
|
{
|
|
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start(args, id);
|
|
|
|
|
uinput = litest_create_uinput_abs_device_v(name, id, NULL, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
return uinput;
|
|
|
|
|
}
|