From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97CF1C4321A for ; Fri, 28 Jun 2019 09:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 75E7A205ED for ; Fri, 28 Jun 2019 09:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726506AbfF1Jpg (ORCPT ); Fri, 28 Jun 2019 05:45:36 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:44537 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726470AbfF1Jpf (ORCPT ); Fri, 28 Jun 2019 05:45:35 -0400 X-Originating-IP: 83.155.44.161 Received: from classic (mon69-7-83-155-44-161.fbx.proxad.net [83.155.44.161]) (Authenticated sender: hadess@hadess.net) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 593F12001E for ; Fri, 28 Jun 2019 09:45:33 +0000 (UTC) Message-ID: <069082521fe694247f44c0a80ce9b87ef756bf8e.camel@hadess.net> Subject: [PATCH v3] keytable: Add keymap test From: Bastien Nocera To: linux-media@vger.kernel.org Date: Fri, 28 Jun 2019 11:45:29 +0200 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.2 (3.32.2-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This new test will try to parse all the ".toml" files in the directory path passed to it, error'ing out on the first parsing problem. Run as "make check" in the keytable directory. Signed-off-by: Bastien Nocera --- Changes since v2: - Added SoB Changes since v1: - Fix patch formatting At least 4 keymaps look broken in the current git: it913x_v2.toml pinnacle310e.toml hisi_poplar.toml imon_mce.toml Let me know if you want patches to remove the duplicate entries from those. utils/keytable/Makefile.am | 6 ++++ utils/keytable/test_keymaps.c | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 utils/keytable/test_keymaps.c diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am index 148b9446..086d53c2 100644 --- a/utils/keytable/Makefile.am +++ b/utils/keytable/Makefile.am @@ -1,9 +1,12 @@ bin_PROGRAMS = ir-keytable +noinst_PROGRAMS = test-keymaps man_MANS = ir-keytable.1 rc_keymap.5 sysconf_DATA = rc_maps.cfg keytablesystem_DATA = $(srcdir)/rc_keymaps/* udevrules_DATA = 70-infrared.rules +test_keymaps_SOURCES = toml.c toml.h test_keymaps.c + ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h toml.c toml.h if WITH_BPF @@ -21,6 +24,9 @@ endif EXTRA_DIST = 70-infrared.rules rc_keymaps rc_keymaps_userspace gen_keytables.pl ir-keytable.1 rc_maps.cfg rc_keymap.5 # custom target +check: test-keymaps + $(builddir)/test-keymaps $(srcdir)/rc_keymaps/ + install-data-local: $(install_sh) -d "$(DESTDIR)$(keytableuserdir)" diff --git a/utils/keytable/test_keymaps.c b/utils/keytable/test_keymaps.c new file mode 100644 index 00000000..23084331 --- /dev/null +++ b/utils/keytable/test_keymaps.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include + +#include "toml.h" + +static int +has_suffix(const char *str, const char *suffix) +{ + if (strlen(str) < strlen(suffix)) + return 0; + if (strncmp(str + strlen(str) - strlen(suffix), suffix, strlen(suffix)) == 0) + return 1; + return 0; +} + +int main (int argc, char **argv) +{ + DIR *dir; + struct dirent *entry; + + if (argc != 2) { + fprintf(stderr, "Usage: %s KEYMAPS-DIRECTORY\n", argv[0]); + return 1; + } + + dir = opendir(argv[1]); + if (!dir) { + perror("Could not open directory"); + return 1; + } + + while ((entry = readdir(dir)) != NULL) { + struct toml_table_t *root; + FILE *fin; + char buf[200]; + char path[2048]; + + if (!has_suffix(entry->d_name, ".toml")) { + /* Skipping file */ + continue; + } + + memset(path, 0, sizeof(path)); + strcpy(path, argv[1]); + strcpy(path + strlen(argv[1]), "/"); + strcpy(path + strlen(argv[1]) + 1, entry->d_name); + strcpy(path + strlen(argv[1]) + 1 + strlen(entry->d_name), "\0"); + + fin = fopen(path, "r"); + if (!fin) { + fprintf(stderr, "Could not open file %s: %s", path, strerror(errno)); + return 1; + } + + root = toml_parse_file(fin, buf, sizeof(buf)); + fclose(fin); + if (!root) { + fprintf(stderr, "Failed to parse %s: %s\n", path, buf); + return 1; + } + toml_free(root); + } + + return 0; +}