[PATCH libinput 1/2] test: inhibit nasty keys and switches during test runs
Peter Hutterer
peter.hutterer at who-t.net
Thu Feb 1 07:36:36 UTC 2018
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 at who-t.net>
---
meson.build | 7 ++++++-
test/litest.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/meson.build b/meson.build
index 3a14681c..5b8317a4 100644
--- a/meson.build
+++ b/meson.build
@@ -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',
diff --git a/test/litest.c b/test/litest.c
index d4874d43..befb486a 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -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);
--
2.14.3
More information about the wayland-devel
mailing list