[PATCH libinput 06/10] test: install per-test device quirks files

Peter Hutterer peter.hutterer at who-t.net
Mon May 28 08:08:32 UTC 2018


These will replace the custom udev rules we currently have in place.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 meson.build       |  3 ++
 test/litest-int.h |  1 +
 test/litest.c     | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+)

diff --git a/meson.build b/meson.build
index 817ffd76..8966aefb 100644
--- a/meson.build
+++ b/meson.build
@@ -216,6 +216,9 @@ quirks_data = [
 	'data/50-system-system76.quirks',
 ]
 
+config_h.set_quoted('LIBINPUT_DATA_FILES', ':'.join(quirks_data))
+config_h.set_quoted('LIBINPUT_DATA_SRCDIR', join_paths(meson.source_root(), 'data'))
+
 install_data(quirks_data, install_dir : libinput_data_path)
 
 src_libquirks = [
diff --git a/test/litest-int.h b/test/litest-int.h
index 6384e4da..1cdae730 100644
--- a/test/litest-int.h
+++ b/test/litest-int.h
@@ -70,6 +70,7 @@ struct litest_test_device {
        struct litest_device_interface *interface;
 
        const char *udev_rule;
+       const char *quirk_file;
 };
 
 struct litest_device_interface {
diff --git a/test/litest.c b/test/litest.c
index 97039ce2..8a4b5335 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -87,6 +87,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);
 
 /* defined for the litest selftest */
 #ifndef LITEST_DISABLE_BACKTRACE_LOGGING
@@ -999,6 +1000,7 @@ litest_run(int argc, char **argv)
 {
 	int failed = 0;
 	int inhibit_lock_fd;
+	char *quirks_dir;
 
 	list_init(&created_files_list);
 
@@ -1012,6 +1014,10 @@ litest_run(int argc, char **argv)
 		verbose = 1;
 
 	litest_init_udev_rules(&created_files_list);
+	quirks_dir = litest_install_quirks(&created_files_list);
+
+	setenv("LIBINPUT_DATA_DIR", quirks_dir, 1);
+	free(quirks_dir);
 
 	litest_setup_sighandler(SIGINT);
 
@@ -1175,6 +1181,88 @@ litest_install_model_quirks(struct list *created_files_list)
 	list_insert(created_files_list, &file->link);
 }
 
+static char *
+litest_init_device_quirk_file(const char *data_dir,
+			      struct litest_test_device *dev)
+{
+	int fd;
+	FILE *f;
+	char path[PATH_MAX];
+	static int count;
+
+	if (!dev->quirk_file)
+		return NULL;
+
+	snprintf(path, sizeof(path),
+		 "%s/99-%03d-%s.quirks",
+		 data_dir,
+		 ++count,
+		 dev->shortname);
+	fd = open(path, O_CREAT|O_WRONLY, 0644);
+	litest_assert_int_ne(fd, -1);
+	f = fdopen(fd, "w");
+	litest_assert_notnull(f);
+	litest_assert_int_ge(fputs(dev->quirk_file, f), 0);
+	fclose(f);
+
+	return safe_strdup(path);
+}
+
+
+static char *
+litest_install_quirks(struct list *created_files_list)
+{
+	struct litest_test_device **dev = devices;
+	struct created_file *file;
+	char *dirname;
+	char **quirks, **q;
+
+	dirname = safe_strdup("/run/litest-XXXXXX");
+	dirname = mkdtemp(dirname);
+	litest_assert(dirname);
+	litest_assert_int_ne(chmod(dirname, 0755), -1);
+
+	quirks = strv_from_string(LIBINPUT_DATA_FILES, ":");
+	litest_assert(quirks);
+
+	q = quirks;
+	while (*q) {
+		char *filename;
+		char dest[PATH_MAX];
+		char src[PATH_MAX];
+
+		litest_assert(strneq(*q, "data/", 5));
+		filename = &(*q)[5];
+
+		snprintf(src, sizeof(src), "%s/%s", LIBINPUT_DATA_SRCDIR, filename);
+		snprintf(dest, sizeof(dest), "%s/%s", dirname, filename);
+		file = litest_copy_file(dest, src, NULL);
+		list_append(created_files_list, &file->link);
+		q++;
+	}
+	strv_free(quirks);
+
+	/* Now add the per-device special config files */
+
+	while (*dev) {
+		char *path;
+
+		path = litest_init_device_quirk_file(dirname, *dev);
+		if (path) {
+			struct created_file *file = zalloc(sizeof(*file));
+			file->path = path;
+			list_insert(created_files_list, &file->link);
+		}
+		dev++;
+	}
+
+	file = zalloc(sizeof *file);
+	file->path = safe_strdup(dirname);
+	list_append(created_files_list, &file->link);
+
+	return dirname;
+}
+
 static inline void
 mkdir_p(const char *dir)
 {
-- 
2.14.3



More information about the wayland-devel mailing list