From patchwork Mon Jul 8 10:03:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastien Nocera X-Patchwork-Id: 11034795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 56D9F112C for ; Mon, 8 Jul 2019 10:03:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3627627FE4 for ; Mon, 8 Jul 2019 10:03:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27FC12851B; Mon, 8 Jul 2019 10:03:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD39327FE4 for ; Mon, 8 Jul 2019 10:03:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729272AbfGHKDL (ORCPT ); Mon, 8 Jul 2019 06:03:11 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:48677 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728596AbfGHKDL (ORCPT ); Mon, 8 Jul 2019 06:03:11 -0400 Received: from classic.redhat.com (mon69-7-83-155-44-161.fbx.proxad.net [83.155.44.161]) (Authenticated sender: hadess@hadess.net) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 5E201100010 for ; Mon, 8 Jul 2019 10:03:10 +0000 (UTC) From: Bastien Nocera To: linux-media@vger.kernel.org Subject: [PATCH v4] keytable: Add keymap test Date: Mon, 8 Jul 2019 12:03:09 +0200 Message-Id: <20190708100309.26630-1-hadess@hadess.net> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This new test will try to parse all the ".toml" files in the directory path passed to it, error'ing out if there were parsing problems. Run as "make check" in the keytable directory. Signed-off-by: Bastien Nocera --- utils/keytable/Makefile.am | 6 +++ utils/keytable/check_keymaps.c | 67 ++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 utils/keytable/check_keymaps.c diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am index 148b9446..eb296475 100644 --- a/utils/keytable/Makefile.am +++ b/utils/keytable/Makefile.am @@ -1,9 +1,12 @@ bin_PROGRAMS = ir-keytable +noinst_PROGRAMS = check-keymaps man_MANS = ir-keytable.1 rc_keymap.5 sysconf_DATA = rc_maps.cfg keytablesystem_DATA = $(srcdir)/rc_keymaps/* udevrules_DATA = 70-infrared.rules +check_keymaps_SOURCES = toml.c toml.h check_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: check-keymaps + $(builddir)/check-keymaps $(srcdir)/rc_keymaps/ + install-data-local: $(install_sh) -d "$(DESTDIR)$(keytableuserdir)" diff --git a/utils/keytable/check_keymaps.c b/utils/keytable/check_keymaps.c new file mode 100644 index 00000000..eb8e3e8f --- /dev/null +++ b/utils/keytable/check_keymaps.c @@ -0,0 +1,67 @@ +#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; + int ret = 0; + + 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; + } + + snprintf(path, sizeof(path), "%s/%s", argv[1], entry->d_name); + path[sizeof(path) - 1] = '\0'; + + fin = fopen(path, "r"); + if (!fin) { + fprintf(stderr, "Could not open file %s: %s", path, strerror(errno)); + ret = 1; + continue; + } + + root = toml_parse_file(fin, buf, sizeof(buf)); + fclose(fin); + if (!root) { + fprintf(stderr, "Failed to parse %s: %s\n", path, buf); + ret = 1; + } + toml_free(root); + } + + return ret; +}