mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-28 02:40:07 +01:00
test: inhibit nasty keys and switches during test runs
Having the system suspend or shutdown halfway through a test run is a tad annoying. So let's talk to logind and tell it to inhibit the various keys we're testing. https://bugs.freedesktop.org/show_bug.cgi?id=104720 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
39fa810b58
commit
7175cafe78
2 changed files with 63 additions and 1 deletions
|
|
@ -521,6 +521,10 @@ if get_option('tests')
|
|||
dep_libunwind = dependency('libunwind', required : false)
|
||||
config_h.set10('HAVE_LIBUNWIND', dep_libunwind.found())
|
||||
|
||||
# for inhibit support during test run
|
||||
dep_libsystemd = dependency('libsystemd', required : false)
|
||||
config_h.set10('HAVE_LIBSYSTEMD', dep_libsystemd.found())
|
||||
|
||||
lib_litest_sources = [
|
||||
'test/litest.h',
|
||||
'test/litest-int.h',
|
||||
|
|
@ -609,7 +613,8 @@ if get_option('tests')
|
|||
dep_udev,
|
||||
dep_libevdev,
|
||||
dep_dl,
|
||||
dep_lm
|
||||
dep_lm,
|
||||
dep_libsystemd,
|
||||
]
|
||||
|
||||
configure_file(input : 'udev/80-libinput-test-device.rules',
|
||||
|
|
|
|||
|
|
@ -48,6 +48,9 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <libudev.h>
|
||||
#if HAVE_LIBSYSTEMD
|
||||
#include <systemd/sd-bus.h>
|
||||
#endif
|
||||
|
||||
#include "litest.h"
|
||||
#include "litest-int.h"
|
||||
|
|
@ -942,10 +945,60 @@ litest_fork_subtests(struct list *tests, int max_forks)
|
|||
return failed;
|
||||
}
|
||||
|
||||
static inline int
|
||||
inhibit(void)
|
||||
{
|
||||
int lock_fd = -1;
|
||||
#if HAVE_LIBSYSTEMD
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
sd_bus_message *m = NULL;
|
||||
sd_bus *bus = NULL;
|
||||
int rc;
|
||||
|
||||
rc = sd_bus_open_system(&bus);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "Warning: inhibit failed: %s\n", strerror(-rc));
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = sd_bus_call_method(bus,
|
||||
"org.freedesktop.login1",
|
||||
"/org/freedesktop/login1",
|
||||
"org.freedesktop.login1.Manager",
|
||||
"Inhibit",
|
||||
&error,
|
||||
&m,
|
||||
"ssss",
|
||||
"handle-lid-switch:handle-power-key:handle-suspend-key:handle-hibernate-key",
|
||||
"libinput test-suite runner",
|
||||
"testing in progress",
|
||||
"block");
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Warning: inhibit failed: %s\n", error.message);
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = sd_bus_message_read(m, "h", &lock_fd);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Warning: inhibit failed: %s\n", strerror(-rc));
|
||||
goto out;
|
||||
}
|
||||
|
||||
lock_fd = dup(lock_fd);
|
||||
out:
|
||||
sd_bus_error_free(&error);
|
||||
sd_bus_message_unref(m);
|
||||
sd_bus_close(bus);
|
||||
sd_bus_unref(bus);
|
||||
#endif
|
||||
return lock_fd;
|
||||
}
|
||||
|
||||
static inline int
|
||||
litest_run(int argc, char **argv)
|
||||
{
|
||||
int failed = 0;
|
||||
int inhibit_lock_fd;
|
||||
|
||||
list_init(&created_files_list);
|
||||
|
||||
|
|
@ -962,11 +1015,15 @@ litest_run(int argc, char **argv)
|
|||
|
||||
litest_setup_sighandler(SIGINT);
|
||||
|
||||
inhibit_lock_fd = inhibit();
|
||||
|
||||
if (jobs == 1)
|
||||
failed = litest_run_suite(&all_tests, 1, 1, STDERR_FILENO);
|
||||
else
|
||||
failed = litest_fork_subtests(&all_tests, jobs);
|
||||
|
||||
close(inhibit_lock_fd);
|
||||
|
||||
litest_free_test_list(&all_tests);
|
||||
|
||||
litest_remove_udev_rules(&created_files_list);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue