Commit 5ca1862b authored by Peter Hutterer's avatar Peter Hutterer

test: add a libinput-test runner for 'deviceless' tests

These are tests that don't need *any* uinput devices at all. Mark them
accordingly and create a new binary that only runs those tests. This way we
can run some of the test suite even in containers where we're restricted.

Better have 10% tested than none, I guess.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 07a0d04f
Pipeline #1747 failed with stages
in 15 minutes and 15 seconds
......@@ -861,6 +861,14 @@ if get_option('tests')
libinput_test_runner,
timeout : 1200)
libinput_test_deviceless = executable('libinput-test-deviceless',
libinput_test_runner_sources,
include_directories : [includes_src, includes_include],
dependencies : deps_litest,
c_args : [ def_LT_VERSION, '-DDISABLE_DEVICE_TESTS=1' ],
install : false)
test('libinput-test-deviceless', libinput_test_deviceless)
valgrind_env = environment()
valgrind_env.set('CK_FORK', 'no')
valgrind_env.set('USING_VALGRIND', '1')
......
......@@ -89,7 +89,7 @@ struct list created_files_list; /* list of all files to remove at the end of
static void litest_init_udev_rules(struct list *created_files_list);
static void litest_remove_udev_rules(struct list *created_files_list);
static char *litest_install_quirks(struct list *created_files_list);
static inline char *litest_install_quirks(struct list *created_files_list);
/* defined for the litest selftest */
#ifndef LITEST_DISABLE_BACKTRACE_LOGGING
......@@ -335,6 +335,7 @@ struct test {
void *teardown;
struct range range;
bool deviceless;
};
struct suite {
......@@ -440,6 +441,32 @@ litest_add_tcase_no_device(struct suite *suite,
list_insert(&suite->tests, &t->node);
}
static void
litest_add_tcase_deviceless(struct suite *suite,
void *func,
const char *funcname,
const struct range *range)
{
struct test *t;
const char *test_name = funcname;
if (filter_device &&
fnmatch(filter_device, test_name, 0) != 0)
return;
t = zalloc(sizeof(*t));
t->deviceless = true;
t->name = safe_strdup(test_name);
t->devname = safe_strdup("deviceless");
t->func = func;
if (range)
t->range = *range;
t->setup = NULL;
t->teardown = NULL;
list_insert(&suite->tests, &t->node);
}
static struct suite *
get_suite(const char *name)
{
......@@ -470,8 +497,8 @@ litest_add_tcase(const char *suite_name,
struct suite *suite;
bool added = false;
litest_assert(required >= LITEST_DISABLE_DEVICE);
litest_assert(excluded >= LITEST_DISABLE_DEVICE);
litest_assert(required >= LITEST_DEVICELESS);
litest_assert(excluded >= LITEST_DEVICELESS);
if (filter_test &&
fnmatch(filter_test, funcname, 0) != 0)
......@@ -483,7 +510,11 @@ litest_add_tcase(const char *suite_name,
suite = get_suite(suite_name);
if (required == LITEST_DISABLE_DEVICE &&
if (required == LITEST_DEVICELESS &&
excluded == LITEST_DEVICELESS) {
litest_add_tcase_deviceless(suite, func, funcname, range);
added = true;
} else if (required == LITEST_DISABLE_DEVICE &&
excluded == LITEST_DISABLE_DEVICE) {
litest_add_tcase_no_device(suite, func, funcname, range);
added = true;
......@@ -557,6 +588,19 @@ _litest_add_ranged_no_device(const char *name,
range);
}
void
_litest_add_deviceless(const char *name,
const char *funcname,
void *func)
{
_litest_add_ranged(name,
funcname,
func,
LITEST_DEVICELESS,
LITEST_DEVICELESS,
NULL);
}
void
_litest_add(const char *name,
const char *funcname,
......@@ -842,6 +886,16 @@ litest_run_suite(struct list *tests, int which, int max, int error_fd)
TCase *tc;
char *sname, *tname;
#if DISABLE_DEVICE_TESTS
/* We run deviceless tests as part of the normal
* test suite runner, just in case. Filtering
* all the other ones out just for the case where
* we can't run the full runner.
*/
if (!t->deviceless)
continue;
#endif
count = (count + 1) % max;
if (max != 1 && (count % max) != which)
continue;
......@@ -975,6 +1029,7 @@ static inline int
inhibit(void)
{
int lock_fd = -1;
#if !DISABLE_DEVICE_TESTS
#if HAVE_LIBSYSTEMD
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *m = NULL;
......@@ -1016,6 +1071,7 @@ out:
sd_bus_message_unref(m);
sd_bus_close(bus);
sd_bus_unref(bus);
#endif
#endif
return lock_fd;
}
......@@ -1038,9 +1094,12 @@ litest_run(int argc, char **argv)
if (getenv("LITEST_VERBOSE"))
verbose = 1;
#if DISABLE_DEVICE_TESTS
quirks_dir = safe_strdup(LIBINPUT_DATA_SRCDIR);
#else
litest_init_udev_rules(&created_files_list);
quirks_dir = litest_install_quirks(&created_files_list);
#endif
setenv("LIBINPUT_DATA_DIR", quirks_dir, 1);
free(quirks_dir);
......@@ -1301,7 +1360,7 @@ mkdir_p(const char *dir)
free(path);
}
static void
static inline void
litest_init_udev_rules(struct list *created_files)
{
mkdir_p(UDEV_RULES_D);
......@@ -1312,7 +1371,7 @@ litest_init_udev_rules(struct list *created_files)
litest_reload_udev_rules();
}
static void
static inline void
litest_remove_udev_rules(struct list *created_files_list)
{
struct created_file *f, *tmp;
......@@ -3873,14 +3932,11 @@ setup_tests(void)
}
}
int
main(int argc, char **argv)
static int
check_device_access(void)
{
const struct rlimit corelimit = { 0, 0 };
enum litest_mode mode;
int tty_mode = -1;
int failed_tests;
#if !DISABLE_DEVICE_TESTS
/* You don't get to skip the deviceless tests */
if (getenv("SKIP_LIBINPUT_TEST_SUITE_RUNNER"))
return 77;
......@@ -3897,6 +3953,44 @@ main(int argc, char **argv)
"uinput device is missing, skipping tests.\n");
return 77;
}
#endif /* DISABLE_DEVICE_TESTS */
return 0;
}
static int
disable_tty(void)
{
int tty_mode = -1;
#if !DISABLE_DEVICE_TESTS
/* If we're running 'normally' on the VT, disable the keyboard to
* avoid messing up our host. But if we're inside gdb or running
* without forking, leave it as-is.
*/
if (jobs > 1 &&
!in_debugger &&
getenv("CK_FORK") == NULL &&
isatty(STDIN_FILENO) &&
ioctl(STDIN_FILENO, KDGKBMODE, &tty_mode) == 0)
ioctl(STDIN_FILENO, KDSKBMODE, K_OFF);
#endif /* DISABLE_DEVICE_TESTS */
return tty_mode;
}
int
main(int argc, char **argv)
{
const struct rlimit corelimit = { 0, 0 };
enum litest_mode mode;
int tty_mode = -1;
int failed_tests;
int rc;
rc = check_device_access();
if (rc != 0)
return rc;
litest_init_test_devices();
......@@ -3923,16 +4017,7 @@ main(int argc, char **argv)
if (setrlimit(RLIMIT_CORE, &corelimit) != 0)
perror("WARNING: Core dumps not disabled. Reason");
/* If we're running 'normally' on the VT, disable the keyboard to
* avoid messing up our host. But if we're inside gdb or running
* without forking, leave it as-is.
*/
if (jobs > 1 &&
!in_debugger &&
getenv("CK_FORK") == NULL &&
isatty(STDIN_FILENO) &&
ioctl(STDIN_FILENO, KDGKBMODE, &tty_mode) == 0)
ioctl(STDIN_FILENO, KDSKBMODE, K_OFF);
tty_mode = disable_tty();
failed_tests = litest_run(argc, argv);
......
......@@ -291,6 +291,7 @@ enum litest_device_type {
};
enum litest_device_feature {
LITEST_DEVICELESS = -2,
LITEST_DISABLE_DEVICE = -1,
LITEST_ANY = 0,
LITEST_TOUCHPAD = 1 << 0,
......@@ -417,6 +418,9 @@ void litest_set_log_handler_bug(struct libinput *libinput);
_litest_add_no_device(name_, #func_, func_)
#define litest_add_ranged_no_device(name_, func_, ...) \
_litest_add_ranged_no_device(name_, #func_, func_, __VA_ARGS__)
#define litest_add_deviceless(name_, func_) \
_litest_add_deviceless(name_, #func_, func_)
void
_litest_add(const char *name,
const char *funcname,
......@@ -450,6 +454,10 @@ _litest_add_ranged_no_device(const char *name,
const char *funcname,
void *func,
const struct range *range);
void
_litest_add_deviceless(const char *name,
const char *funcname,
void *func);
struct litest_device *
litest_create_device(enum litest_device_type which);
......
......@@ -204,9 +204,9 @@ TEST_COLLECTION(log)
{
struct range axes = { ABS_X, ABS_Y + 1};
litest_add_no_device("log:defaults", log_default_priority);
litest_add_no_device("log:logging", log_handler_invoked);
litest_add_no_device("log:logging", log_handler_NULL);
litest_add_deviceless("log:defaults", log_default_priority);
litest_add_deviceless("log:logging", log_handler_invoked);
litest_add_deviceless("log:logging", log_handler_NULL);
litest_add_no_device("log:logging", log_priority);
litest_add_ranged("log:warnings", log_axisrange_warning, LITEST_TOUCH, LITEST_ANY, &axes);
......
......@@ -1768,41 +1768,41 @@ TEST_COLLECTION(misc)
litest_add_for_device("events:conversion", event_conversion_tablet, LITEST_WACOM_CINTIQ);
litest_add_for_device("events:conversion", event_conversion_tablet_pad, LITEST_WACOM_INTUOS5_PAD);
litest_add_for_device("events:conversion", event_conversion_switch, LITEST_LID_SWITCH);
litest_add_no_device("misc:bitfield_helpers", bitfield_helpers);
litest_add_deviceless("misc:bitfield_helpers", bitfield_helpers);
litest_add_no_device("context:refcount", context_ref_counting);
litest_add_no_device("config:status string", config_status_string);
litest_add_deviceless("context:refcount", context_ref_counting);
litest_add_deviceless("config:status string", config_status_string);
litest_add_for_device("timer:offset-warning", timer_offset_bug_warning, LITEST_SYNAPTICS_TOUCHPAD);
litest_add_no_device("timer:flush", timer_flush);
litest_add_no_device("misc:matrix", matrix_helpers);
litest_add_no_device("misc:ratelimit", ratelimit_helpers);
litest_add_no_device("misc:parser", dpi_parser);
litest_add_no_device("misc:parser", wheel_click_parser);
litest_add_no_device("misc:parser", wheel_click_count_parser);
litest_add_no_device("misc:parser", trackpoint_accel_parser);
litest_add_no_device("misc:parser", dimension_prop_parser);
litest_add_no_device("misc:parser", reliability_prop_parser);
litest_add_no_device("misc:parser", calibration_prop_parser);
litest_add_no_device("misc:parser", range_prop_parser);
litest_add_no_device("misc:parser", palm_pressure_parser);
litest_add_no_device("misc:parser", safe_atoi_test);
litest_add_no_device("misc:parser", safe_atoi_base_16_test);
litest_add_no_device("misc:parser", safe_atoi_base_8_test);
litest_add_no_device("misc:parser", safe_atou_test);
litest_add_no_device("misc:parser", safe_atou_base_16_test);
litest_add_no_device("misc:parser", safe_atou_base_8_test);
litest_add_no_device("misc:parser", safe_atod_test);
litest_add_no_device("misc:parser", strsplit_test);
litest_add_no_device("misc:parser", kvsplit_double_test);
litest_add_no_device("misc:parser", strjoin_test);
litest_add_no_device("misc:time", time_conversion);
litest_add_deviceless("misc:matrix", matrix_helpers);
litest_add_deviceless("misc:ratelimit", ratelimit_helpers);
litest_add_deviceless("misc:parser", dpi_parser);
litest_add_deviceless("misc:parser", wheel_click_parser);
litest_add_deviceless("misc:parser", wheel_click_count_parser);
litest_add_deviceless("misc:parser", trackpoint_accel_parser);
litest_add_deviceless("misc:parser", dimension_prop_parser);
litest_add_deviceless("misc:parser", reliability_prop_parser);
litest_add_deviceless("misc:parser", calibration_prop_parser);
litest_add_deviceless("misc:parser", range_prop_parser);
litest_add_deviceless("misc:parser", palm_pressure_parser);
litest_add_deviceless("misc:parser", safe_atoi_test);
litest_add_deviceless("misc:parser", safe_atoi_base_16_test);
litest_add_deviceless("misc:parser", safe_atoi_base_8_test);
litest_add_deviceless("misc:parser", safe_atou_test);
litest_add_deviceless("misc:parser", safe_atou_base_16_test);
litest_add_deviceless("misc:parser", safe_atou_base_8_test);
litest_add_deviceless("misc:parser", safe_atod_test);
litest_add_deviceless("misc:parser", strsplit_test);
litest_add_deviceless("misc:parser", kvsplit_double_test);
litest_add_deviceless("misc:parser", strjoin_test);
litest_add_deviceless("misc:time", time_conversion);
litest_add_no_device("misc:fd", fd_no_event_leak);
litest_add_no_device("misc:library_version", library_version);
litest_add_deviceless("misc:library_version", library_version);
litest_add_no_device("misc:list", list_test_insert);
litest_add_no_device("misc:list", list_test_append);
litest_add_deviceless("misc:list", list_test_insert);
litest_add_deviceless("misc:list", list_test_append);
}
......@@ -974,40 +974,40 @@ END_TEST
TEST_COLLECTION(quirks)
{
litest_add_no_device("quirks:datadir", quirks_invalid_dir);
litest_add_no_device("quirks:datadir", quirks_empty_dir);
litest_add_no_device("quirks:structure", quirks_section_empty);
litest_add_no_device("quirks:structure", quirks_section_double);
litest_add_no_device("quirks:structure", quirks_section_missing_match);
litest_add_no_device("quirks:structure", quirks_section_missing_attr);
litest_add_no_device("quirks:structure", quirks_section_match_after_attr);
litest_add_no_device("quirks:structure", quirks_section_duplicate_match);
litest_add_no_device("quirks:structure", quirks_section_duplicate_attr);
litest_add_no_device("quirks:parsing", quirks_parse_error_section);
litest_add_no_device("quirks:parsing", quirks_parse_error_trailing_whitespace);
litest_add_no_device("quirks:parsing", quirks_parse_error_unknown_match);
litest_add_no_device("quirks:parsing", quirks_parse_error_unknown_attr);
litest_add_no_device("quirks:parsing", quirks_parse_error_unknown_model);
litest_add_no_device("quirks:parsing", quirks_parse_error_model_not_one);
litest_add_no_device("quirks:parsing", quirks_parse_comment_inline);
litest_add_no_device("quirks:parsing", quirks_parse_comment_empty);
litest_add_no_device("quirks:parsing", quirks_parse_bustype);
litest_add_no_device("quirks:parsing", quirks_parse_bustype_invalid);
litest_add_no_device("quirks:parsing", quirks_parse_vendor);
litest_add_no_device("quirks:parsing", quirks_parse_vendor_invalid);
litest_add_no_device("quirks:parsing", quirks_parse_product);
litest_add_no_device("quirks:parsing", quirks_parse_product_invalid);
litest_add_no_device("quirks:parsing", quirks_parse_version);
litest_add_no_device("quirks:parsing", quirks_parse_version_invalid);
litest_add_no_device("quirks:parsing", quirks_parse_name);
litest_add_no_device("quirks:parsing", quirks_parse_name_invalid);
litest_add_no_device("quirks:parsing", quirks_parse_udev);
litest_add_no_device("quirks:parsing", quirks_parse_udev_invalid);
litest_add_no_device("quirks:parsing", quirks_parse_dmi);
litest_add_no_device("quirks:parsing", quirks_parse_dmi_invalid);
litest_add_deviceless("quirks:datadir", quirks_invalid_dir);
litest_add_deviceless("quirks:datadir", quirks_empty_dir);
litest_add_deviceless("quirks:structure", quirks_section_empty);
litest_add_deviceless("quirks:structure", quirks_section_double);
litest_add_deviceless("quirks:structure", quirks_section_missing_match);
litest_add_deviceless("quirks:structure", quirks_section_missing_attr);
litest_add_deviceless("quirks:structure", quirks_section_match_after_attr);
litest_add_deviceless("quirks:structure", quirks_section_duplicate_match);
litest_add_deviceless("quirks:structure", quirks_section_duplicate_attr);
litest_add_deviceless("quirks:parsing", quirks_parse_error_section);
litest_add_deviceless("quirks:parsing", quirks_parse_error_trailing_whitespace);
litest_add_deviceless("quirks:parsing", quirks_parse_error_unknown_match);
litest_add_deviceless("quirks:parsing", quirks_parse_error_unknown_attr);
litest_add_deviceless("quirks:parsing", quirks_parse_error_unknown_model);
litest_add_deviceless("quirks:parsing", quirks_parse_error_model_not_one);
litest_add_deviceless("quirks:parsing", quirks_parse_comment_inline);
litest_add_deviceless("quirks:parsing", quirks_parse_comment_empty);
litest_add_deviceless("quirks:parsing", quirks_parse_bustype);
litest_add_deviceless("quirks:parsing", quirks_parse_bustype_invalid);
litest_add_deviceless("quirks:parsing", quirks_parse_vendor);
litest_add_deviceless("quirks:parsing", quirks_parse_vendor_invalid);
litest_add_deviceless("quirks:parsing", quirks_parse_product);
litest_add_deviceless("quirks:parsing", quirks_parse_product_invalid);
litest_add_deviceless("quirks:parsing", quirks_parse_version);
litest_add_deviceless("quirks:parsing", quirks_parse_version_invalid);
litest_add_deviceless("quirks:parsing", quirks_parse_name);
litest_add_deviceless("quirks:parsing", quirks_parse_name_invalid);
litest_add_deviceless("quirks:parsing", quirks_parse_udev);
litest_add_deviceless("quirks:parsing", quirks_parse_udev_invalid);
litest_add_deviceless("quirks:parsing", quirks_parse_dmi);
litest_add_deviceless("quirks:parsing", quirks_parse_dmi_invalid);
litest_add_for_device("quirks:model", quirks_model_one, LITEST_MOUSE);
litest_add_for_device("quirks:model", quirks_model_zero, LITEST_MOUSE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment