Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3135961pxf; Mon, 15 Mar 2021 02:16:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5NqEwu2vKnHjjreN8hZat1TTZUAYMiD1J280VROoYV1jB9j6DGawKfgORNCTB8o460hKo X-Received: by 2002:a05:6402:3089:: with SMTP id de9mr29198493edb.10.1615799792005; Mon, 15 Mar 2021 02:16:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615799792; cv=none; d=google.com; s=arc-20160816; b=U7Q9Gfwg4XKHCRdVYxADZrXFpqKQmnIIZJ8h0MD4itbUxouALQ3rLf/cJRIcAQ/A9f VRG2EAFKV2OUI8Q5UTiNQrTI0rjv26y4O4sRiOs6CvjRwfn3hcbLVXj//5r0wum5s5JG KqWE1Ot9I6tyJdrR/qFAgYxOKLN+BkXGX8hRbrPDWLzQjAts/AMMEOjTj8o/xVuaxpw3 KLIZkAr2CyHSqvbTGX6Obt5ppWzH2pU2pUSfXLH5Fi3xr8x11u3Os9BfSijaI2BBQnju B5kmcXQxcNXP5+OD8iWl/pPGiI1NL7KrvirmtmSG5f2G15BohTSfh/9to733d8kUWUdh yBQg== 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=dRcQM8tGux3x7pZPyJ5Bh3crA9EoJU0QA79n6uNLXsw=; b=NirTASSTqaJNdZOIbmax4CPa28tVBcv4d/fNfo/sdVoayOojtvPiX5MjA6beMefd4p F9Cob5TipcaRgBQ3OfB1eUp1KgMYNSDxWnt7iwY8/jdmqVBqQ+KHgkzNpEOBD3EdNtG8 3L5aKDXY6h9c+WI2rBUI3ZJPoWfA5G3zGD6iZL9vHuTb1qw36Le/qQ4tQJzXCyWNOZyd CojZcKxgDcISxD3wVRkJ/kSPIb+8C5kfyCZ4VnwxPil13vd90W6X62EgGtu0RIAG9/Kt wRqyImz3Upm+cz7TH6gQpzkiwtmCYr8L4ufh6BIWMYnh5h7cKxKDbsmQZXjn1Zmc3gf5 upjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=gYsKrCca; 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 i20si10172130edq.582.2021.03.15.02.16.09; Mon, 15 Mar 2021 02:16:31 -0700 (PDT) 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=gYsKrCca; 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 S229854AbhCOJOr (ORCPT + 99 others); Mon, 15 Mar 2021 05:14:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229702AbhCOJOW (ORCPT ); Mon, 15 Mar 2021 05:14:22 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1088C061574 for ; Mon, 15 Mar 2021 02:14:21 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id c76-20020a1c9a4f0000b029010c94499aedso19773200wme.0 for ; Mon, 15 Mar 2021 02:14:21 -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=dRcQM8tGux3x7pZPyJ5Bh3crA9EoJU0QA79n6uNLXsw=; b=gYsKrCcaw/qvETnVouWSLanaWMhH+vPFQXssPLv6y0occ71b9vKM9BkzDSbeCvQayG EnTC6xXfAHQNInNry+8Rb25rEK5LOoMxHM13++PeIIGz+fFYsa7tq/TcJghDulwx5ulO KT8PsnBE/agvEWK0+csZPKIa5123CJgBctZL4lYPdy4xFsAnIOX3/W0CVtsLqFkb46kw hafziEWpy3jA5MzwJ4dEKSR/0G88KvtfSFEHfn6pv/3J8uy7BOH/zZdw/8ThURAkA03w pHMl0Pnlvg9QCa0pS1Z5rGj/UtsQArkdW7h8SL9ggq9W94FPVTsdefi6uEA5ny3E2StT YkTw== 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=nbLEbsYs2fDiu0p8Xi5NokY6h8MEUaUfh6Lx0ovT3OqXcr73TB5U2uf077D6WsMKZW exJVerJ0Kl6WQzXppOTfBNAre5/Y1eOTLjXQxdmamj+7RYzu1Q/KWc+Og9KxKRs5uwU+ PhdB70AotfQoFjJSjW3Ek75KX9kQR11fhtYhrYiN5U7/Ip8qRJ806smgMCq69U+ZUzT2 J7d7k3V5XAotJ6IbUAGhcdbPpX6hRycxCkZCXMg9jJ8dUew9MmIj4xxOyNyWJMTykg2c q6PR+GFZT63FEGFgruTqxQjEqjVbZE6Tb6WRo+eCzEFDt+WZ7a2FPvJ97yVw1uF3gf0u 1ACA== X-Gm-Message-State: AOAM530G+raPqS/UuVzBHaK9Yefx2TF0QqsjiJzomvUziW8fTcCHPOMc I5dHq9+ETAODS/8hGEi9Zr60Eg== X-Received: by 2002:a1c:4382:: with SMTP id q124mr25341077wma.16.1615799660557; Mon, 15 Mar 2021 02:14:20 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-149-6.w2-15.abo.wanadoo.fr. [2.15.231.6]) by smtp.gmail.com with ESMTPSA id z3sm17978822wrw.96.2021.03.15.02.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 02:14:20 -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 Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 10/11] selftests: gpio: add a helper for reading GPIO line names Date: Mon, 15 Mar 2021 10:13:59 +0100 Message-Id: <20210315091400.13772-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210315091400.13772-1-brgl@bgdev.pl> References: <20210315091400.13772-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.30.1