Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1606422pxb; Thu, 4 Mar 2021 16:09:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWHijsLrr5o5uwad5vw1mr9/HAuDvYqD0ufu0PLWwuR0XnQaKKfvbTfoVjpk1QNoN8ozCV X-Received: by 2002:a6b:ec08:: with SMTP id c8mr5454649ioh.55.1614902998569; Thu, 04 Mar 2021 16:09:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614902998; cv=none; d=google.com; s=arc-20160816; b=pe2tXAamti5suqh+6IrdAGtBWI2LKNfpz1njYXMsEdQPK7LBGDKdb/vDj1H4jizkNQ thpiy4dHUN2kzPKsQ6lVH61PBjfFWaR+PB2Bwa4vuGyx1KuxuZ6PLelblMONZmuaeRoC 8SRNiVfXP+z9Q+XiX9HCP3h/oKX96/ryODssu5tZHVbKOpsGvlN9M13uJdaozLht0j4e IqQTETxZLHMtZgTLZC3gYE2Rpymok687y+Ue6Hbjxft0JBNjNDzpr5NF1+lhWcN4BJ5H d9RlJalsX1Rl1tNjNRsM8YjoAJaV+Mih299lVgkbfRB279gNfmC3hbOxgIo3sMT33mc7 x6GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jvONDvt0z0lDvIPYURd0mL7FvKxWbTnZ85Tag2PzNjQ=; b=tS4JtGL24FXtMxdbVHohs2frdBQMwH95oyrRWo0/ND+WL2JP6jlPkIBFfuMp3t7ngl Ixp9/hKe9T7qU93ikwo1dGQ6yjSGbwG8lHwYNSCK8UmUP5WAPZHa1PB+/25Aq3+VolAp eUbTh0UdHaD1OhbUl1W1+3c3S81TLXwnwN61d+DkjI3P1ZYVyuA9/08lNka+CnKJBiV5 umvxQCccEcEddv8ZrgfZqhXA9FzDVE/xXD2a9nNACoyB2boz3GhgcxZLcgnl7wtMFsL7 jem4ivRWQVHgISEHqraktLoPbieE1cvLxiSjg0e6g8j2w3lhfIXsDwV8+ybvz4fVg9mQ dpGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=cRP+06aq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k18si741620jam.96.2021.03.04.16.09.45; Thu, 04 Mar 2021 16:09:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=cRP+06aq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238642AbhCDKcH (ORCPT + 99 others); Thu, 4 Mar 2021 05:32:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238579AbhCDKbr (ORCPT ); Thu, 4 Mar 2021 05:31:47 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9142C061794 for ; Thu, 4 Mar 2021 02:30:16 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id w7so7533236wmb.5 for ; Thu, 04 Mar 2021 02:30:16 -0800 (PST) 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=jvONDvt0z0lDvIPYURd0mL7FvKxWbTnZ85Tag2PzNjQ=; b=cRP+06aq2xL14nQrl4MaDz4ppkm/L6hnQOKerm3lS92Pz/iQEdmyY0XGzMkz7Lgs6x B/BblaeXYey4aqFUVWohfJbHr4FmTL/RMZIHGc5Q4p6kdouMnuxuf/x54py6JcUNVFXx jgqw0HE8/fajgRpyMTSbj9DjfR7syL7F3dODxiVwX5oeHGUs6nGtmt1q280TNqDd8Cps MYq7yFh5OkPSvBCi6n++HK7ShXsnYo+RzLTWliTL86sEcnM0JmQiTqgMroGtAvONAuTY sAKky2BsZn4haLIxKtyCGzaSb+4jFK4Ff+1E/XXI/WzjrARDFWEpQ0PLv4SASmJ4QMjs LlEw== 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=jvONDvt0z0lDvIPYURd0mL7FvKxWbTnZ85Tag2PzNjQ=; b=Avfs6vs3Dt1XpZvvwN8cuoKQhHSaRtxLzbaeAA6j6MOoZD11fQL0diM+AfHWHmnKkR aq270q7dH4l1skAsB4WJYGo7Uhyd+AqHUgv+tyG2fYmyPYX8p0uZV/OupgTDsEkx3uJ3 uU+5EkQaQErhedY/cx/WWG2lzLLPI1kD20uhMFHtAJhdJW/TZkMkQFiU6XX9pBPrqMYP SjDy+J6nJrq10usJnXGkuxjq3X1irCbcO1qkjdzoQKOKlaqxQKztH5EzsLcu8OTUnUdW fDrMDbHEfKFK8jSvyJ+Qi1R15gqfqZAQA2vKpd/jZwlgngN+K7BiZYZIw1VffKtMu0NX +E3g== X-Gm-Message-State: AOAM5309A8sDnVcuI7JKdu5Ww8rW4pYnVXwcq5RSj8B94WcOFFUTGNHQ Bcjezb/Gv3BiC8ZgAquJwhxRtw== X-Received: by 2002:a1c:c20a:: with SMTP id s10mr3203464wmf.144.1614853815558; Thu, 04 Mar 2021 02:30:15 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id f7sm35501854wre.78.2021.03.04.02.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 02:30:15 -0800 (PST) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig , Shuah Khan , Linus Walleij , Andy Shevchenko , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Geert Uytterhoeven , Kent Gibson , Jonathan Corbet Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 11/12] selftests: gpio: add a helper for reading GPIO line names Date: Thu, 4 Mar 2021 11:24:51 +0100 Message-Id: <20210304102452.21726-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20210304102452.21726-1-brgl@bgdev.pl> References: <20210304102452.21726-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski Add a simple program that allows to read GPIO line names from the character device. This will be used in gpio-sim selftests. Signed-off-by: Bartosz Golaszewski --- tools/testing/selftests/gpio/.gitignore | 1 + tools/testing/selftests/gpio/Makefile | 2 +- tools/testing/selftests/gpio/gpio-line-name.c | 55 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/gpio/gpio-line-name.c diff --git a/tools/testing/selftests/gpio/.gitignore b/tools/testing/selftests/gpio/.gitignore index 4ea4f58dab1a..ededb077a3a6 100644 --- a/tools/testing/selftests/gpio/.gitignore +++ b/tools/testing/selftests/gpio/.gitignore @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only gpio-mockup-cdev gpio-chip-info +gpio-line-name diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile index 84b48547f94c..d7d8f1985d99 100644 --- a/tools/testing/selftests/gpio/Makefile +++ b/tools/testing/selftests/gpio/Makefile @@ -2,6 +2,6 @@ TEST_PROGS := gpio-mockup.sh TEST_FILES := gpio-mockup-sysfs.sh -TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info +TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name include ../lib.mk diff --git a/tools/testing/selftests/gpio/gpio-line-name.c b/tools/testing/selftests/gpio/gpio-line-name.c new file mode 100644 index 000000000000..a52e75bc37ba --- /dev/null +++ b/tools/testing/selftests/gpio/gpio-line-name.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * GPIO character device helper for reading line names. + * + * Copyright (C) 2021 Bartosz Golaszewski + */ + +#include +#include +#include +#include +#include +#include +#include + +static void print_usage(void) +{ + printf("usage:\n"); + printf(" gpio-line-name \n"); +} + +int main(int argc, char **argv) +{ + struct gpio_v2_line_info info; + int fd, ret; + char *endp; + + if (argc != 3) { + print_usage(); + return EXIT_FAILURE; + } + + fd = open(argv[1], O_RDWR); + if (fd < 0) { + perror("unable to open the GPIO chip"); + return EXIT_FAILURE; + } + + memset(&info, 0, sizeof(info)); + info.offset = strtoul(argv[2], &endp, 10); + if (*endp != '\0') { + print_usage(); + return EXIT_FAILURE; + } + + ret = ioctl(fd, GPIO_V2_GET_LINEINFO_IOCTL, &info); + if (ret) { + perror("line info ioctl failed"); + return EXIT_FAILURE; + } + + printf("%s\n", info.name); + + return EXIT_SUCCESS; +} -- 2.29.1