From patchwork Mon Mar 18 16:10:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1057920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="N+LHeCLv"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44NLkQ6XHbz9sBr for ; Tue, 19 Mar 2019 03:10:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727215AbfCRQKU (ORCPT ); Mon, 18 Mar 2019 12:10:20 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35772 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726897AbfCRQKT (ORCPT ); Mon, 18 Mar 2019 12:10:19 -0400 Received: by mail-wm1-f67.google.com with SMTP id 81so6159459wme.0 for ; Mon, 18 Mar 2019 09:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KdqDkYrTDEqN9vakI2bBqUBOD/OCU+61ucnMbJPmp4s=; b=N+LHeCLvXXVLDq3QVUXFths8PToZVQnBJsqmoTIeVVwMLWSU/ReZW73eL+W8t2/KdA YUzTh2sV4BqmqTWuEX3wd6zInCm/RJhA435WM4/Mq14hQ7dn2zuBK4n62BJru9ddYEcF cOrUbUCqpNLjs3+Yi9SvMMYS/Ndg88RdRNbAgYaqRdkn47Q1+JUIeTj5jgeY2eMvH7sq Fwv32UGEIqxhPQGvvFFN5N1fm0xDNz3wnYx8vyGH5N2SumcmoEY8EWRBsHY4SwDYGVof b2UqwnJynpLcGH2yhmxG7qd4WjmzkS6/lWQJwAbya1lt3LTIOIfspwZViJ5ARHy2OgWF M9gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KdqDkYrTDEqN9vakI2bBqUBOD/OCU+61ucnMbJPmp4s=; b=iO6bqxaRwayK+O5f1IBlxmJU3/fPleWyePgIMKyHpTzxw/MRxNs5NQdWhY3sPhFUy7 h5//11XuZa51/7chf0vMyfFqE8KsD3W47nBVIHWS6b3r1WiUDl9Q5FfndZKYE6ia4S64 nmEC2TP7v7t1VdCEIIkOH/nyFOg7jZxDAbfBTPk9XxX+4g5s9Ox+LWKhOEtEI5Mn8l8n aG61B1YoKKpddtVw53rVH1EJEFkqZo5QQcaz/piaqBpNb3kV2y/A0el2Y5yuUuK0tBed IT49pWvL8Gkra8ZsBGjHshDUN9XsvsSXao1VnOEurxbcOD8zVU8I10NQt/b/vMkeJBgI NoQA== X-Gm-Message-State: APjAAAXsbxj6USwoDMCadygsdJGbj/8HiCzr+dLLOhypP/r4ksr0muGX 38QuC+DgXwvLY1BQHLwqcVmUqA== X-Google-Smtp-Source: APXvYqzx06ePcagAcr9Z7Xncd47JChA9F/DdiKee3uAbTTkj0s7hWsRO9NewdsbavhZsMvBb+bkoSA== X-Received: by 2002:a1c:f102:: with SMTP id p2mr12232304wmh.36.1552925418239; Mon, 18 Mar 2019 09:10:18 -0700 (PDT) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id q2sm23803401wrd.46.2019.03.18.09.10.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 09:10:17 -0700 (PDT) From: Bartosz Golaszewski To: Anders Roxell Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH v2 1/2] tests: enable installing tests to bindir Date: Mon, 18 Mar 2019 17:10:13 +0100 Message-Id: <20190318161014.4660-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190318161014.4660-1-brgl@bgdev.pl> References: <20190318161014.4660-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Anders Roxell Add an enable option to configure that allows to install the testing binary to /bindir. Signed-off-by: Anders Roxell [Bartosz: trimmed the patch to fit the new approach] Signed-off-by: Bartosz Golaszewski --- configure.ac | 7 +++++++ tests/Makefile.am | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/configure.ac b/configure.ac index 4adff7b..8a9b81d 100644 --- a/configure.ac +++ b/configure.ac @@ -107,6 +107,13 @@ then AC_CHECK_HEADERS([sys/signalfd.h], [], [HEADER_NOT_FOUND_TOOLS([sys/signalfd.h])]) fi +AC_ARG_ENABLE([install-tests], + [AC_HELP_STRING([--enable-install-tests], + [enable install tests [default=no]])], + [if test "x$enableval" = xyes; then with_install_tests=true; with_tests=true; fi], + [with_install_tests=false]) +AM_CONDITIONAL([WITH_INSTALL_TESTS], [test "x$with_install_tests" = xtrue]) + AC_ARG_ENABLE([tests], [AC_HELP_STRING([--enable-tests], [enable libgpiod tests [default=no]])], diff --git a/tests/Makefile.am b/tests/Makefile.am index a6593b9..4d1e6d5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,7 +11,11 @@ AM_CFLAGS += -Wall -Wextra -g $(KMOD_CFLAGS) $(UDEV_CFLAGS) AM_LDFLAGS = -pthread LDADD = $(top_builddir)/lib/libgpiod.la $(KMOD_LIBS) $(UDEV_LIBS) +if WITH_INSTALL_TESTS +bin_PROGRAMS = gpiod-test +else check_PROGRAMS = gpiod-test +endif gpiod_test_SOURCES = gpiod-test.c \ gpiod-test.h \ From patchwork Mon Mar 18 16:10:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1057921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="0wWK60/a"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44NLkR4qB7z9sBV for ; Tue, 19 Mar 2019 03:10:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726897AbfCRQKV (ORCPT ); Mon, 18 Mar 2019 12:10:21 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35058 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727142AbfCRQKV (ORCPT ); Mon, 18 Mar 2019 12:10:21 -0400 Received: by mail-wr1-f68.google.com with SMTP id w1so11773519wrp.2 for ; Mon, 18 Mar 2019 09:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AM4QydSaZ1suQWU21WrzS6xQ9vpLBDbKHDYMzNQZo7s=; b=0wWK60/ac9evTF4ljmdewjvGrJinX+5r88z0CuvZAGzet6Es6UPctwBlF6TXDhRKMK 2vmmW0MoA6xhyMb/5tkTmui1V4WjAzkmXyPXXAQwDqJtYT6fAO/b6ukefH19GlveG3Ud 6EndxDmCOA0l+Oap/pBIjQELLqw8Hd6QeGk5G8h8w2xoI2L4IxciCixTSR8A7xadmekL Aut1/FoshGAO0vCV1TSC/Iy/FmNcJTHYUe72Z3zcWfvVd0tvFSC5rtqYpupYap7G6NAb rV8DO7CX2Dp0ZP4adnNH+tw6JJ+PedP9vpUlfJ4gChGuFIyQhyiayvWQY6ueHw/iY8E1 d1bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AM4QydSaZ1suQWU21WrzS6xQ9vpLBDbKHDYMzNQZo7s=; b=RxpqMqbnFh1kjfDBE1OHnPt4u3saO9o0iyo8Wf00lQixf76VFE91bZ/A8Q/dA9BR3Q miYQNroovFRIe3BX8+9bF39CVgXNfjHfy3LaG0CU1p66nFjY9HhYqQ3jR1BdODwkZ4re ipcXJZRRHxnsl+nMBaVN87vaLKVBhfDU/VZN9UD+LhxlzUDdwFDS1DYl/WWtJvbbgRmF AlYC+0vA+j6InUNEGIERSddOwLSPbUeqkFicf4AJlSf+cXxsykV2ZbVnsqXrMRacLTay Hfz6f25ebMR9yEvlI2D8zebz7H4qsFchNvCzs9SRjTBpn6NG4xWeI2tdaySkXAxvLh7K Orkg== X-Gm-Message-State: APjAAAWdrtv0HiAbCl5c5JJJfbKMfvQr+AoMyLfEe29fx3E+SEu0Qg3F Ikwo324A3sjp9DdDaDKZqShWZg== X-Google-Smtp-Source: APXvYqzUuU7dDjlqYFNumZ+72PvuO5G239PpGhhj8UL5IB68PuCdvksvDvsReJeJKgYIBYLn7HyQRg== X-Received: by 2002:adf:b651:: with SMTP id i17mr11981629wre.108.1552925419236; Mon, 18 Mar 2019 09:10:19 -0700 (PDT) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id q2sm23803401wrd.46.2019.03.18.09.10.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 09:10:18 -0700 (PDT) From: Bartosz Golaszewski To: Anders Roxell Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [libgpiod][PATCH v2 2/2] tests: look for gpio-tools in more places Date: Mon, 18 Mar 2019 17:10:14 +0100 Message-Id: <20190318161014.4660-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190318161014.4660-1-brgl@bgdev.pl> References: <20190318161014.4660-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Currently we only support running the test cases for gpio-tools from the top-level source directory. Some users want to install the test executable and run the tests from other locations (/bin, /usr/bin or custom path). This patch makes the test suite look in the source tree path first, then check the directory in which the program resides and last iterate over all directories in $PATH. We only do that once at the beginning and then reuse the path later. Cc: Anders Roxell Signed-off-by: Bartosz Golaszewski --- tests/gpiod-test.c | 75 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index 4c51f4a..9cb9072 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -86,6 +86,7 @@ static struct { pid_t main_pid; int pipesize; char *pipebuf; + char *toolpath; } globals; enum { @@ -447,18 +448,6 @@ static void gpiotool_proc_dup_fds(int in_fd, int out_fd, int err_fd) } } -static char *gpiotool_proc_get_path(const char *tool) -{ - char *path, *progpath, *progdir; - - progpath = xstrdup(program_invocation_name); - progdir = dirname(progpath); - path = xappend(NULL, "%s/../../tools/%s", progdir, tool); - free(progpath); - - return path; -} - static NORETURN void gpiotool_proc_exec(const char *path, va_list va) { size_t num_args; @@ -545,10 +534,12 @@ void test_tool_run(char *tool, ...) event_lock(); if (globals.test_ctx.event.running) die("refusing to fork when the event thread is running"); + if (!globals.toolpath) + die("asked to run tests for gpio-tools, but the executables were not found"); gpiotool_proc_make_pipes(in_fds, out_fds, err_fds); - path = gpiotool_proc_get_path(tool); + path = xappend(NULL, "%s/%s", globals.toolpath, tool); rv = access(path, R_OK | X_OK); if (rv) die_perr("unable to execute '%s'", path); @@ -768,6 +759,63 @@ static void check_gpio_mockup(void) msg("gpio-mockup ok"); } +static void check_tool_path(void) +{ + /* + * Let's check gpiodetect only and assume all the other tools are in + * the same directory. + */ + static const char *const tool = "gpiodetect"; + + char *progpath, *progdir, *toolpath, *pathenv, *tok; + + /* First check if we're running the from the top source directory. */ + progpath = xstrdup(program_invocation_name); + progdir = dirname(progpath); + + toolpath = xappend(NULL, "%s/../../tools/%s", progdir, tool); + if (access(toolpath, R_OK | X_OK) == 0) { + free(progpath); + goto out; + } + free(toolpath); + + /* Is the tool in the same directory maybe? */ + toolpath = xappend(NULL, "%s/%s", progdir, tool); + free(progpath); + if (access(toolpath, R_OK | X_OK) == 0) + goto out; + free(toolpath); + + /* Next iterate over directories in $PATH. */ + pathenv = getenv("PATH"); + if (!pathenv) + return; + + progpath = xstrdup(pathenv); + tok = strtok(progpath, ":"); + while (tok) { + toolpath = xappend(NULL, "%s/%s", tok, tool); + if (access(toolpath, R_OK) == 0) { + free(progpath); + goto out; + } + + free(toolpath); + tok = strtok(NULL, ":"); + } + + free(progpath); + toolpath = NULL; + +out: + if (toolpath) { + toolpath = dirname(toolpath); + msg("using gpio-tools from '%s'", toolpath); + globals.toolpath = toolpath; + } +} + static void load_module(struct _test_chip_descr *descr) { unsigned int i; @@ -1001,6 +1049,7 @@ int main(int argc TEST_UNUSED, char **argv TEST_UNUSED) check_kernel(); check_gpio_mockup(); + check_tool_path(); msg("running tests");