test: install per-test device quirks files
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 24 May 2018 05:36:22 +0000 (15:36 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Fri, 8 Jun 2018 04:33:35 +0000 (14:33 +1000)
These will replace the custom udev rules we currently have in place.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
meson.build
test/litest-int.h
test/litest.c

index b8735cede5d9e2cae831d66a817bdb1aa890d8bd..5e4db287ecc57fda80dc9bc890ba2febddbc2394 100644 (file)
@@ -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 = [
index 6384e4dafb5e505b691aaa8e592b26d02a21b1e8..1cdae7304b780365770597f8568691ed7caf21df 100644 (file)
@@ -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 {
index 9d711098f023feab91002cc71442e3833e2a0f3e..13f0a4faacad762f108271def6db3e376cf85933 100644 (file)
@@ -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);
 
@@ -1177,6 +1183,86 @@ 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[PATH_MAX] = "/run/litest-XXXXXX";
+       char **quirks, **q;
+
+       litest_assert_notnull(mkdtemp(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 safe_strdup(dirname);
+}
+
 static inline void
 mkdir_p(const char *dir)
 {