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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAF28C433EF for ; Fri, 8 Oct 2021 08:18:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5EB060F41 for ; Fri, 8 Oct 2021 08:18:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234152AbhJHIUT (ORCPT ); Fri, 8 Oct 2021 04:20:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233907AbhJHITq (ORCPT ); Fri, 8 Oct 2021 04:19:46 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F916C06176F for ; Fri, 8 Oct 2021 01:17:51 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id r18so27185652wrg.6 for ; Fri, 08 Oct 2021 01:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1XGPFAB413i4NSgL53tMC4PneOe4C16/1HV5Loq6Wys=; b=KN/7LWDaRYRSsJOmXpGlR61T+vUiSUgUV52J1zbB49eVbU21A0nWargFNSciJ9vCOH uVR/PeTvJ0uS+FFJARPLH91JUDhUqlDuHUMtc9GKbpn3UwD9SfesZbaP88UorrjJfyxJ Nu7kbwdoQ7EbSbZceFBZ32UnMe668+SjpFW7UgHSmdm1oXNWXVWZWzO9GrbLLFmEEahH qEwRmnjKm/LXJtDGef6vwOTT5P1z5sWpaArnLZWAHNl8EWOdcSX263AhNi6ryetFwfTu B8MSTArntaAZj2vIk6ytWeF+D1fWJXTrPLWanRrkWb8DZzBt8RUaVRVJhBktWhdmNhkI Eciw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1XGPFAB413i4NSgL53tMC4PneOe4C16/1HV5Loq6Wys=; b=rgkFtEE0BrAgcLigh5M+4eHfas7MFRmgJOFg8cRzxKnCPlNlR/MKYo90PJ3zs+HxbE rtQoZQIf4z/1MtWgMWIbieAWDHIwEdku+nENisf6pVxkjfYamn1tOp2q5d1EKWumfSil wod+Rjj08Vi+GHt0BsO4E+QLT8F/iGYFFxtPB8lgh2gpefl1YAYhqqvWj/cno8phCtrB UV13hxZWueE51zd2jL6G01EU+ZuTDSsJd8RvTLlwlYdlwOX2NPi+Tb/u4ej12Em3kGED PLnvcKO9JZIp7X1LfGY1zBd7i5+gNJmyMFTTSejdO1ncI9qOhdTUlAldjMcjgIHns41p Bmpg== X-Gm-Message-State: AOAM530GJoEnZwyPk6EkLpZoQF1OmlnWPm9jYGCUhXiOwO2KIREdFgYl sC05zP8+09dPGiVvBxeHL8M9gQ== X-Google-Smtp-Source: ABdhPJw6Ksw5oVZRq328sfwc1ILw9WVuVxkYEHtEisDv8IU8/GDy3BEBPH1PdtI9N4f8NovuBJ6cBg== X-Received: by 2002:adf:a319:: with SMTP id c25mr2301868wrb.307.1633681069549; Fri, 08 Oct 2021 01:17:49 -0700 (PDT) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id i3sm1759530wrn.34.2021.10.08.01.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 01:17:49 -0700 (PDT) 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 , Greg Kroah-Hartman , Al Viro , Jack Winch , Viresh Kumar Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v7 7/8] selftests: gpio: add a helper for reading GPIO line names Date: Fri, 8 Oct 2021 10:17:38 +0200 Message-Id: <20211008081739.26807-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211008081739.26807-1-brgl@bgdev.pl> References: <20211008081739.26807-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.30.1