From patchwork Fri Mar 12 09:56:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 399082 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=-13.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 8054CC28E88 for ; Fri, 12 Mar 2021 09:58:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55A5C6510B for ; Fri, 12 Mar 2021 09:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233554AbhCLJ5v (ORCPT ); Fri, 12 Mar 2021 04:57:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233550AbhCLJ5e (ORCPT ); Fri, 12 Mar 2021 04:57:34 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C6CAC061761 for ; Fri, 12 Mar 2021 01:57:33 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id e18so1418432wrt.6 for ; Fri, 12 Mar 2021 01:57:33 -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=dRcQM8tGux3x7pZPyJ5Bh3crA9EoJU0QA79n6uNLXsw=; b=P9SK2h1Lf3ggsrHeYHXLZxMKAGxcxqa8kmwdBQcFTFpdCFejurpew9ucEYA9r+3+KG I1yLXBaxor/bAd5OEvUF55p0cj4FRY8ooSdcIcOKjBiE7H1weFrJU6l50CucuUHuZvFN 7uNzwhONjYWa6HrFd3x8IIz3UF+LR25VunOsEXW095lAVQmdb+OZe9MbLb5vLXKWl001 uximaecjFI49QrgtpC6iNy0F1DpcQFWP3DDEE4nE2tOeIvAKyY1WDyRQD0rvy367tqj+ 9ZyoZS7rti2glssRqg+yOTFm74JBGSd+LyFfAoZJaztX3zaLVJRzNLxqxBOWPpnWLxIx w+3Q== 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=dRcQM8tGux3x7pZPyJ5Bh3crA9EoJU0QA79n6uNLXsw=; b=XrCij8tiKGkKvwjRHQvkQkaYzIhwLiXOCqH1ZrZK6wg+Hmnfo6oBO+xTxI7blbyscv r+7YDMubUnvrvObvC2ZO1kanGj5qlPRou2K61inPK9a8bewWPoG/DhMMN+REmBDSEwwm uJAhAX4L30qgXfzF/fHPfhD84TMQlgPuZ136iXyhQcvby2bsQgfAYFFx+SrhlM+zSdCD WteGb6++F6IcVL7b+XKcVi8U90e6lOAEDiodbqi/4ByVVCDI1ucIilhFRtqeJt31+3ud hox5iQDnXg75WUy2OmoH2NI4ZknSPdnk9GHOgnR3SU7oZxjlawwbarH7QK0optids4iQ F07g== X-Gm-Message-State: AOAM533OSxJHpMgsuW/7pGY8msVwb4WjANXT67YcHBTHs4N+ifRxZSPb LMJWHX+65K+kX8Nj9hnwj6WlEQ== X-Google-Smtp-Source: ABdhPJyw14CY/RuV1jbKSc7VRGh47nMosERJ/hrNsf9NOn3t1iwRZX3tNGrCafcVq2D6FHYcXLtFNQ== X-Received: by 2002:adf:a18a:: with SMTP id u10mr13179976wru.197.1615543052394; Fri, 12 Mar 2021 01:57:32 -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 x13sm7031630wrt.75.2021.03.12.01.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 01:57:32 -0800 (PST) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig , Shuah Khan , Linus Walleij , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Geert Uytterhoeven , Kent Gibson , Jonathan Corbet , Greg Kroah-Hartman Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 10/11] selftests: gpio: add a helper for reading GPIO line names Date: Fri, 12 Mar 2021 10:56:59 +0100 Message-Id: <20210312095700.16277-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210312095700.16277-1-brgl@bgdev.pl> References: <20210312095700.16277-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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; +}