From patchwork Thu Feb 3 04:21:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 539723 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B01A9C433EF for ; Thu, 3 Feb 2022 04:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241568AbiBCEWs (ORCPT ); Wed, 2 Feb 2022 23:22:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbiBCEWs (ORCPT ); Wed, 2 Feb 2022 23:22:48 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06650C061714 for ; Wed, 2 Feb 2022 20:22:48 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id x3so1146821pll.3 for ; Wed, 02 Feb 2022 20:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CTz+Zb3nuM0Ml5tqTW0KFgwUKo8tuquiqWfmc9a7zWM=; b=GP7Xu0PPrPVuUDoCu+EauxaWMOXtKM+TuM1rdENtdoJhyaPJTnJC/y/OX54YXi6Iv4 kOlzrWbeHD4GSnUNtVaXMcRoROYP+JKIIAP9ln4pYOm3SnjQPcbaYtm8/2r41kCdS8VD Xa/lGe+pyKERhfftv6AU8iCmOZ1iwaMnVkj708r0jktX6xV3gKBPKyLGJu/CLOAM7HRu 2ywnUaLlhD9250TD5T09dAg9a204EU434nlrY0K0jbWF6PTxFiXs5ktlIt+mWyVj4bqN PjQDdTY+8OPKkcEgT0OqmrMhOD6hNfqDlvAZzFiJZH+aGbpBK11Dc/a1HBYzEFswC5zy v4WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=CTz+Zb3nuM0Ml5tqTW0KFgwUKo8tuquiqWfmc9a7zWM=; b=vutjPzQ3ecVNkqQ4FctF8M2tfHlZrQ7W29HbugBHaMgibY8OAPk8B0oNK4OcwolTOE RqedANABc1vMGpamQptAFrIiK+0Dpsjk+sp857+aktvuwTZOA3kJO/9vZhYPI1OHjX1G koWH9AFtRPmQN0dF9sEiv5cqInz+A3jQ4BrstUX8++XiFpSj663SHz4lyQPV+8j9ru/J 3g1MXzYixi1v38ZRILWfu7GpnBeOf6I1mdVJD2AlGjBFzOGJgVonsG0/8WjUU0Fphp8M RDND9npZdEdlSOsgE1wLWq1usqQAxZiCylnNTark+AHpO+0gFdBMcTWIeWjOytjTM+1b 7dlA== X-Gm-Message-State: AOAM532KsjM+ZoN4YsIPxuHMQ99vU3BHD3urnkJ8D9rWkFE+uMzrCMRf G3zUjT3qvww6WSX4mD33ACo= X-Google-Smtp-Source: ABdhPJxDzWOsRyxe5mSn3a/UD/9d3xuAuJSzJ2mUKRREPvxopLXuNZHxlSaDPRdLr3K3IPX05frTcg== X-Received: by 2002:a17:903:92:: with SMTP id o18mr33494314pld.62.1643862167534; Wed, 02 Feb 2022 20:22:47 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:46 -0800 (PST) Sender: "joel.stan@gmail.com" From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Cc: Andrew Jeffery , Zev Weiss , openbmc@lists.ozlabs.org Subject: [libgpiod PATCH 1/7] tools: Clean up scandir memory allocations Date: Thu, 3 Feb 2022 14:51:28 +1030 Message-Id: <20220203042134.68425-2-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The code copied from gpiofind didn't free the memory from scandir. Signed-off-by: Joel Stanley --- tools/tools-common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/tools-common.c b/tools/tools-common.c index 0dc3d52668d7..c83e68a2c1e4 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -190,12 +190,17 @@ struct gpiod_chip *chip_by_line_name(const char *name) die_perror("unable to open %s", entries[i]->d_name); } + free(entries[i]); offset = gpiod_chip_find_line(chip, name); - if (offset >= 0) + if (offset >= 0) { + free(entries); return chip; + } + gpiod_chip_unref(chip); } + free(entries); return NULL; } From patchwork Thu Feb 3 04:21:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 540193 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C802C433EF for ; Thu, 3 Feb 2022 04:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245287AbiBCEWv (ORCPT ); Wed, 2 Feb 2022 23:22:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbiBCEWv (ORCPT ); Wed, 2 Feb 2022 23:22:51 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76CB9C061714 for ; Wed, 2 Feb 2022 20:22:51 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id y5-20020a17090aca8500b001b8127e3d3aso1664198pjt.3 for ; Wed, 02 Feb 2022 20:22:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SnBAgxMF4MgLnVIaS9TWikI68gd/15PA6woV2819bEg=; b=NXeNBpuY04a8npxta5oEQmVE5smwM8KltFF6I5MAvm2qP2jA7mwH1Gb15SNX/W3+A8 czroPPf8HU9oUnK63ir0BFzuwoHArOebq+P0ow02ooMft6h2SL4OA9R9JC7sIM/OKFGn aMxpq4/hla5w8old/tZAY80Na7mdwQH+pxErTd/LraQZnTyJKLrORL83e7snhtavrFF5 em0ZgvqAuE7oaamVPZ1L4kVUhs2tPd9AdwYLm6BLwZVJRJ/OVG8clDPyHeQK90ea7GCX zbyvKFMLps1AwtUjeDjK36GvqJxOufhv4bocOqUnOAlhd9eJVYj1RCmcgpF+tiBpWjDt jJ1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=SnBAgxMF4MgLnVIaS9TWikI68gd/15PA6woV2819bEg=; b=T1pVWtLHV6vKIuk5FO1UFdeJ0Rw/LTuBJGC2sq+cBQjVNAo94t9sjLwaZan2dTFIvP 3yRQ8luLysAfyRmbD5I5jH+sV7690IunrgcNwjiZ7f3v+sKZ2BtQrWV39xDVLIzAi1Gv dL5acLKvkukglKUKRkVPBFkMAc4CpYAOq6uQdovJIr0CPi9s9lid/gdu5B5Z57zrRotW Y9xyvzr2Sr90gBitY6Ma20dSLP8k3LqZpEx+LUjG7sI//3jrf73R3iqdrkMoTPnA4Z40 +FEcFvjam1zGNrwaWo0HhQsYHRVQnher1hrXahyUZ5YMPb7K8o00aqXD34WeYpjoXauA Oe6w== X-Gm-Message-State: AOAM533BDe7HBT7Tj8USis9V6So07PJHX2xyxELtazcAwvqZ/m3oWMvi E2H5uIUZn7ThJ4GUYGg14DFUMytaUDs= X-Google-Smtp-Source: ABdhPJxBUONJKszju+J0cZEdM//IG/OI20cjBPN1UeWhb2xMSAkZxBNCBdYvYpWI+K3DiX7532Bmaw== X-Received: by 2002:a17:90a:f485:: with SMTP id bx5mr11813812pjb.46.1643862170963; Wed, 02 Feb 2022 20:22:50 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:50 -0800 (PST) Sender: "joel.stan@gmail.com" From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Cc: Andrew Jeffery , Zev Weiss , openbmc@lists.ozlabs.org Subject: [libgpiod PATCH 2/7] tools: Add line name to offset lookup helper Date: Thu, 3 Feb 2022 14:51:29 +1030 Message-Id: <20220203042134.68425-3-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org line_names_to_offsets to be used by tools that support --by-name. Signed-off-by: Joel Stanley --- tools/tools-common.c | 22 ++++++++++++++++++++++ tools/tools-common.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/tools/tools-common.c b/tools/tools-common.c index c83e68a2c1e4..958933ed6d51 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -204,3 +204,25 @@ struct gpiod_chip *chip_by_line_name(const char *name) return NULL; } +int line_names_to_offsets(struct gpiod_chip *chip, char **lines, + unsigned int *offsets, int num_lines) +{ + int i; + + for (i = 0; i < num_lines; i++) { + const char *line_name = lines[i]; + int offset; + + offset = gpiod_chip_find_line(chip, line_name); + + if (offset < 0) { + die("chip '%s' does not contain line '%s'", + gpiod_chip_get_name(chip), + line_name); + } + + offsets[i] = offset; + } + + return 0; +} diff --git a/tools/tools-common.h b/tools/tools-common.h index 5ed37dc05885..7affea436a60 100644 --- a/tools/tools-common.h +++ b/tools/tools-common.h @@ -32,5 +32,7 @@ int chip_dir_filter(const struct dirent *entry); struct gpiod_chip *chip_open_by_name(const char *name); struct gpiod_chip *chip_open_lookup(const char *device); struct gpiod_chip *chip_by_line_name(const char *name); +int line_names_to_offsets(struct gpiod_chip *chip, char **lines, + unsigned int *offsets, int num_lines); #endif /* __GPIOD_TOOLS_COMMON_H__ */ From patchwork Thu Feb 3 04:21:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 539722 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD478C433F5 for ; Thu, 3 Feb 2022 04:22:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349274AbiBCEWz (ORCPT ); Wed, 2 Feb 2022 23:22:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbiBCEWy (ORCPT ); Wed, 2 Feb 2022 23:22:54 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD52CC061714 for ; Wed, 2 Feb 2022 20:22:54 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id my12-20020a17090b4c8c00b001b528ba1cd7so1693844pjb.1 for ; Wed, 02 Feb 2022 20:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5PVlIDuR32Yssny9V5o6RCbIPPLetL5jRcPV3axjBDM=; b=FadtJ/iFl9d1vXIsllvJHcQ+98hjYr/bfpo6nTZ7eZtoKfljaum6vBsyQAl/sgraaZ 6kzgx7Y1tN2gCRdM7x9yaqb8etk8fKN+g56y01l9hf5pGW6czQ3T4bPmWDprqPxl0vqg Z37aH4Nm5L6Iy4cOUClrl8NFp8RzsaCAeiQUTHqPqtdXF/esXUADKYDbBzeYiQwXHj5b vBICaihYReDmX0cJ3c5IW5bJUFS8dzDXSqYZ/TVYNxFRGXFpP8QLox6uaoDPsTo9qtBm 44uPxuL88TJVqxWFE/yP6T4F3zb6gvpgANWI4Wy8eAIXQDPtHgh0zsqNaIRVuFDYKkbR QQLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5PVlIDuR32Yssny9V5o6RCbIPPLetL5jRcPV3axjBDM=; b=6TTr0rba7E/N8TENQcHqsXGEP/JdKms+tFYrZBuSggGFC1Uz1LGoBqnq4yg66pA9Ad b9Ky2VMVx/1BgTA5iBO3FpQa+UJZPnJnYBFau1oc8ZEO56o+e6b9pqgDHCMsYa7UoGpj l8ylNExHNafVeF23O25VyetjsyeQgIVq9irGDD9MXcB+ZohDg0Ws/5n7jDVWNX4Z8so3 ydB6fiR5XF1LMQbRxkgwjPNGIW1hERe0xdOHPZkt2M8N8tUIKmcrUno3G3SWuBwYh4WV xHWb73BrXHn7zNGTDH1S7sHBe9FhEalZ+NNLpt+pVNujbZlYsmiM5ZHfEwKmUxbjAvPe aNYQ== X-Gm-Message-State: AOAM533PJLt5fkdHvhBHC69cngRNQO2Pmhey6OH0ZZGRa+VLlco2fVc+ aIM0NLQFp1AR5tnCNiHyYhE= X-Google-Smtp-Source: ABdhPJzDyzOntRgxfZGjzfpNTZ4f1rNfATMaJydTkCGP7iQ/Vwud2/C3WFRnBoKj99iiR9Ih3/bXSA== X-Received: by 2002:a17:90b:3803:: with SMTP id mq3mr11608899pjb.95.1643862174155; Wed, 02 Feb 2022 20:22:54 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:53 -0800 (PST) Sender: "joel.stan@gmail.com" From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Cc: Andrew Jeffery , Zev Weiss , openbmc@lists.ozlabs.org Subject: [libgpiod PATCH 3/7] tools: Add value support to line name lookup Date: Thu, 3 Feb 2022 14:51:30 +1030 Message-Id: <20220203042134.68425-4-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add support for pasring the values as well as the name in line_names_to_offsets. Signed-off-by: Joel Stanley --- tools/tools-common.c | 51 ++++++++++++++++++++++++++++++++++++++++++-- tools/tools-common.h | 4 +++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/tools/tools-common.c b/tools/tools-common.c index 958933ed6d51..586577566790 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -204,15 +204,57 @@ struct gpiod_chip *chip_by_line_name(const char *name) return NULL; } +char *split_line(const char *line_pair) +{ + char *name_end; + size_t name_len; + char *line_name; + + name_end = strchr(line_pair, '='); + if (!name_end) + die("invalid name/value '%s'", line_pair); + + name_len = name_end - line_pair; + + if (name_len > 32) + die("line name exceeds maximum length"); + + line_name = calloc(1, name_len + 1); + strncpy(line_name, line_pair, name_len); + + return line_name; +} + int line_names_to_offsets(struct gpiod_chip *chip, char **lines, - unsigned int *offsets, int num_lines) + unsigned int *offsets, + int *values, + int num_lines) { int i; for (i = 0; i < num_lines; i++) { - const char *line_name = lines[i]; + char *line_name; + int value; int offset; + if (values) { + const char *line_pair = lines[i]; + char *name_end; + int rv; + + line_name = split_line(line_pair); + name_end = strchr(line_pair, '='); + + rv = sscanf(name_end, "=%d", &value); + if (rv != 1) + die("invalid offset<->value mapping: %s", line_pair); + + if (value != 0 && value != 1) + die("value must be 0 or 1: %s", line_pair); + } else { + line_name = lines[i]; + } + offset = gpiod_chip_find_line(chip, line_name); if (offset < 0) { @@ -222,6 +264,11 @@ int line_names_to_offsets(struct gpiod_chip *chip, char **lines, } offsets[i] = offset; + + if (values) { + values[i] = value; + free(line_name); + } } return 0; diff --git a/tools/tools-common.h b/tools/tools-common.h index 7affea436a60..723999011733 100644 --- a/tools/tools-common.h +++ b/tools/tools-common.h @@ -33,6 +33,8 @@ struct gpiod_chip *chip_open_by_name(const char *name); struct gpiod_chip *chip_open_lookup(const char *device); struct gpiod_chip *chip_by_line_name(const char *name); int line_names_to_offsets(struct gpiod_chip *chip, char **lines, - unsigned int *offsets, int num_lines); + unsigned int *offsets, int *values, + int num_lines); +char *split_line(const char *line_pair); #endif /* __GPIOD_TOOLS_COMMON_H__ */ From patchwork Thu Feb 3 04:21:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 540192 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C37C9C433EF for ; Thu, 3 Feb 2022 04:22:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349285AbiBCEW6 (ORCPT ); Wed, 2 Feb 2022 23:22:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbiBCEW5 (ORCPT ); Wed, 2 Feb 2022 23:22:57 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDE04C061714 for ; Wed, 2 Feb 2022 20:22:57 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id h20-20020a17090adb9400b001b518bf99ffso8866426pjv.1 for ; Wed, 02 Feb 2022 20:22:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WtaAuNcUopoXBRdxvTZnjT3vtlEQbvUUGCW1xR+yS2o=; b=B90XMvr0DtNnqk/V7XkGXlRd3comtBJfKavES2DBwMG/aB3Qknk6rO9oQ/mL4+d0o5 fQB1eM1XPApumU1/LEG+Q8V7UtwWp3aFCtwpd1+0xw/Zn3Tx1+cVtpzTccfnR/C/X7ZR Z3bgO88LLIObp/Kon9vL1OkauKJ/sOUEYzrosSLXQU8TBiFoN1179meDBoyloQ5ELvE5 WJtq3mEWbRh5IuGC0552Jxq6SjxSN27RDcJ19EjBxWuKKWdz4qcMpwhaWlK/2mhXiiUC WFIFqC//Zm460Nj2ZaSST/yU0WM0DGeqtvUg0NCjbXf9x6Q7WdgeJe4U5NU9TXMYJVVA /YbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=WtaAuNcUopoXBRdxvTZnjT3vtlEQbvUUGCW1xR+yS2o=; b=abP3+Fu41b5ZKd3evBF2XdQU5UuMXR1g4xjtavFxuUWpikl5v8yBb3z+ykKZwiO98V qFaY6WAKBewwapqL3CNwAQv5vSuLVcv+A78DlseXsuHumD8mxlHr3BQxXRFGjJ00bYrc okewVUpthS6PBVGK14i5AIxVF8FsYoDGtyezV1q1y3xYiMuORLdhLBXVbzm2crhe0/kG eIOjfkuPXJZVbsYangr8yBELcThO0PgKlA7+NDGrXkmdWnrXSSG9p9bwmhRaZkFfUCko iKS8SV3J5O+eYbeZTGdnkA1Cpylnco5lSKfZAki3r/MVyPK5/7WYTvPWuLYRCtN3o9m3 XrKQ== X-Gm-Message-State: AOAM533WLKvC0lazXBQ0QyPttHU2Yct3o3fZC/ASEdDEP68Aa6K3IlIR TELFvk2pEtdtoYTeMGr/93c= X-Google-Smtp-Source: ABdhPJyokYw2y2eVbQCJXQygo7XRqXrFFte1IP83fHh69z7HweMZUNAD5mbq3Ga7SQWljoZYaPNpeA== X-Received: by 2002:a17:902:6942:: with SMTP id k2mr33125240plt.133.1643862177366; Wed, 02 Feb 2022 20:22:57 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:56 -0800 (PST) Sender: "joel.stan@gmail.com" From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Cc: Andrew Jeffery , Zev Weiss , openbmc@lists.ozlabs.org Subject: [libgpiod PATCH 4/7] tools: gpioget: Add by-name support Date: Thu, 3 Feb 2022 14:51:31 +1030 Message-Id: <20220203042134.68425-5-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Allow users to get the values of gpios by passing the gpio name. The gpipchip is not specified, instead it is discovered using the same method as gpiofind. $ gpioget --by-name switch-state 1 $ gpioget --by-name led-fault led-identify led-attention 1 0 1 Signed-off-by: Joel Stanley --- tools/gpioget.c | 57 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/tools/gpioget.c b/tools/gpioget.c index 51cecb6a18a9..9d2c82b0d64b 100644 --- a/tools/gpioget.c +++ b/tools/gpioget.c @@ -15,15 +15,18 @@ static const struct option longopts[] = { { "active-low", no_argument, NULL, 'l' }, { "dir-as-is", no_argument, NULL, 'n' }, { "bias", required_argument, NULL, 'B' }, + { "by-name", no_argument, NULL, 'N' }, { GETOPT_NULL_LONGOPT }, }; -static const char *const shortopts = "+hvlnB:"; +static const char *const shortopts = "+hvlnB:N"; static void print_help(void) { printf("Usage: %s [OPTIONS] ...\n", get_progname()); + printf(" %s [OPTIONS] -L ...\n", + get_progname()); printf("\n"); printf("Read line value(s) from a GPIO chip\n"); printf("\n"); @@ -34,6 +37,7 @@ static void print_help(void) printf(" -n, --dir-as-is:\tdon't force-reconfigure line direction\n"); printf(" -B, --bias=[as-is|disable|pull-down|pull-up] (defaults to 'as-is'):\n"); printf(" set the line bias\n"); + printf(" -N, --by-name:\tget line by name. All lines must be from the same gpiochip\n"); printf("\n"); print_bias_help(); } @@ -46,7 +50,8 @@ int main(int argc, char **argv) unsigned int *offsets, i, num_lines; struct gpiod_line_bulk *lines; struct gpiod_chip *chip; - char *device, *end; + bool by_name = false; + char *end; for (;;) { optc = getopt_long(argc, argv, shortopts, longopts, &opti); @@ -69,6 +74,9 @@ int main(int argc, char **argv) case 'B': flags |= bias_flags(optarg); break; + case 'N': + by_name = true; + break; case '?': die("try %s --help", get_progname()); default: @@ -79,30 +87,47 @@ int main(int argc, char **argv) argc -= optind; argv += optind; - if (argc < 1) - die("gpiochip must be specified"); + if (by_name) { + if (argc < 1) + die("at least one line name must be specified"); + + /* line0 line1 ... lineN */ + num_lines = argc; - if (argc < 2) - die("at least one GPIO line offset must be specified"); + chip = chip_by_line_name(argv[0]); + if (!chip) + die("unable to find gpiochip"); + } else { + /* gpiochip offset0 offset1 ... offsetN */ + if (argc < 1) + die("gpiochip must be specified"); - device = argv[0]; - num_lines = argc - 1; + if (argc < 2) + die("at least one GPIO line offset must be specified"); + + chip = chip_open_lookup(argv[0]); + if (!chip) + die_perror("unable to open %s", argv[0]); + + argv++; + num_lines = argc - 1; + } values = malloc(sizeof(*values) * num_lines); offsets = malloc(sizeof(*offsets) * num_lines); if (!values || !offsets) die("out of memory"); - for (i = 0; i < num_lines; i++) { - offsets[i] = strtoul(argv[i + 1], &end, 10); - if (*end != '\0' || offsets[i] > INT_MAX) - die("invalid GPIO offset: %s", argv[i + 1]); + if (by_name) { + line_names_to_offsets(chip, argv, offsets, NULL, num_lines); + } else { + for (i = 0; i < num_lines; i++) { + offsets[i] = strtoul(argv[i], &end, 10); + if (*end != '\0' || offsets[i] > INT_MAX) + die("invalid GPIO offset: %s", argv[i]); + } } - chip = chip_open_lookup(device); - if (!chip) - die_perror("unable to open %s", device); - lines = gpiod_chip_get_lines(chip, offsets, num_lines); if (!lines) die_perror("unable to retrieve GPIO lines from chip"); From patchwork Thu Feb 3 04:21:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 539721 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BED08C433F5 for ; Thu, 3 Feb 2022 04:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349286AbiBCEXB (ORCPT ); Wed, 2 Feb 2022 23:23:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbiBCEXB (ORCPT ); Wed, 2 Feb 2022 23:23:01 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55127C061714 for ; Wed, 2 Feb 2022 20:23:01 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id d187so1151784pfa.10 for ; Wed, 02 Feb 2022 20:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pph8jDBQpM0nxeaoZ8APOI6SBLcJBTZ+vZr5mm8mwYw=; b=dy4/IL2fmcddqVj+HMDh28HQGkNx+1YYb+3yfo5caI1eM879OYAGX6t+xtDgAz4QGy qd8kr12ecwrgKAHICYYdfUow15HSFP10vrHimb+68E0EMr/KNRO8/PS36xRBWQ1Tkyer jKAy/UAngweagi1Bm3bCtJPwb+vW2tl6JkSPC3uMF2yflZYZgFKhfrlLNaKVGIkc6XpD t6K0b9C9n4i049e0/op1ZG7bXqjLvpjniHs3/oS692DrvzhQjKeCA4zmRsgDZiRdIFQZ ax6gqPE/KqCyIiGkQyOpsObHdzZdSihj8jQGOljogyJLZiMzgWyIvfagcPubjOP3iE/+ bXPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=pph8jDBQpM0nxeaoZ8APOI6SBLcJBTZ+vZr5mm8mwYw=; b=Da3CaoUxp5eB5aZKCHkxQ1df0vXOWLYvntd54zpSC8jLDLsY0/GFy7sIhSyYpckHLv OPtZpGIpjoi5V+CphwTzU+VzGHFe5G88qLMDheQ02wDQk6Y6RyjUATC+wJxPeRHltBs2 0rQX1deBrpQ4dtlvnjcjw8Hcf+4qmmvWhVtSPsj6xIc1bDw70uLy6oW4ATPR8nbpaT3b Ig0mVgeOwysCb+4vKcZj8Fbf6bPAusIV4gNn+JB9Aj/P3vHPvcanx7p3IDQ9uu9kwfxt Al1xldCIaSX6VsGpmbFhnQKYvUesbIUXUGiwK9nj3xUpIjOl7tPSSP4YBFDyF6OkkcLP 8b8A== X-Gm-Message-State: AOAM533RDCTIJC0TozwxrJVGAmh3K6IgLNxcm4mzkb8v9PQxoDzKvd1w qWp9KAUUENbXUpZHd3mZCqY= X-Google-Smtp-Source: ABdhPJwE91EI5exa8JWlsP2lShtbaHr73UJJKci59z7TjJ8EcfGXt+YaUmcUDFmquhY7aKQXCGhYsw== X-Received: by 2002:a05:6a00:1891:: with SMTP id x17mr32728622pfh.73.1643862180769; Wed, 02 Feb 2022 20:23:00 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:22:59 -0800 (PST) Sender: "joel.stan@gmail.com" From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Cc: Andrew Jeffery , Zev Weiss , openbmc@lists.ozlabs.org Subject: [libgpiod PATCH 5/7] tools: gpioset: Add by-name support Date: Thu, 3 Feb 2022 14:51:32 +1030 Message-Id: <20220203042134.68425-6-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Allow users to set the values of gpios by passing the gpio name. The gpipchip is not specified, instead it is discovered using the same method as gpiofind. $ gpioset --mode=wait --by-name cfam-reset=1 Signed-off-by: Joel Stanley --- tools/gpioset.c | 68 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/tools/gpioset.c b/tools/gpioset.c index 7882b53bab41..fe3e1c246c89 100644 --- a/tools/gpioset.c +++ b/tools/gpioset.c @@ -23,15 +23,18 @@ static const struct option longopts[] = { { "sec", required_argument, NULL, 's' }, { "usec", required_argument, NULL, 'u' }, { "background", no_argument, NULL, 'b' }, + { "by-name", no_argument, NULL, 'N' }, { GETOPT_NULL_LONGOPT }, }; -static const char *const shortopts = "+hvlB:D:m:s:u:b"; +static const char *const shortopts = "+hvlB:D:m:s:u:bN"; static void print_help(void) { printf("Usage: %s [OPTIONS] = = ...\n", get_progname()); + printf(" %s [OPTIONS] -L ...\n", + get_progname()); printf("\n"); printf("Set GPIO line values of a GPIO chip and maintain the state until the process exits\n"); printf("\n"); @@ -48,6 +51,7 @@ static void print_help(void) printf(" -s, --sec=SEC:\tspecify the number of seconds to wait (only valid for --mode=time)\n"); printf(" -u, --usec=USEC:\tspecify the number of microseconds to wait (only valid for --mode=time)\n"); printf(" -b, --background:\tafter setting values: detach from the controlling terminal\n"); + printf(" -N, --by-name:\tset line by name. All lines must be from the same gpiochip\n"); printf("\n"); print_bias_help(); printf("\n"); @@ -195,7 +199,8 @@ int main(int argc, char **argv) struct gpiod_line_bulk *lines; struct callback_data cbdata; struct gpiod_chip *chip; - char *device, *end; + bool by_name = false; + char *end; memset(&cbdata, 0, sizeof(cbdata)); @@ -239,6 +244,9 @@ int main(int argc, char **argv) case 'b': cbdata.daemonize = true; break; + case 'N': + by_name = true; + break; case '?': die("try %s --help", get_progname()); default: @@ -257,37 +265,57 @@ int main(int argc, char **argv) cbdata.daemonize) die("can't daemonize in this mode"); - if (argc < 1) - die("gpiochip must be specified"); + if (by_name) { + char *line_name; + + if (argc < 1) + die("at least one line name must be specified"); + + line_name = split_line(argv[0]); + chip = chip_by_line_name(line_name); + if (!chip) + die("unable to find '%s' on a gpiochip", line_name); + + free(line_name); - if (argc < 2) - die("at least one GPIO line offset to value mapping must be specified"); + num_lines = argc; + } else { + if (argc < 1) + die("gpiochip must be specified"); - device = argv[0]; + if (argc < 2) + die("at least one GPIO line offset to value mapping must be specified"); - num_lines = argc - 1; + + chip = chip_open_lookup(argv[0]); + if (!chip) + die_perror("unable to open %s", argv[0]); + + num_lines = argc - 1; + argv++; + } offsets = malloc(sizeof(*offsets) * num_lines); values = malloc(sizeof(*values) * num_lines); if (!values || !offsets) die("out of memory"); - for (i = 0; i < num_lines; i++) { - rv = sscanf(argv[i + 1], "%u=%d", &offsets[i], &values[i]); - if (rv != 2) - die("invalid offset<->value mapping: %s", argv[i + 1]); + if (by_name) { + line_names_to_offsets(chip, argv, offsets, values, num_lines); + } else { + for (i = 0; i < num_lines; i++) { + rv = sscanf(argv[i], "%u=%d", &offsets[i], &values[i]); + if (rv != 2) + die("invalid offset<->value mapping: %s", argv[i + 1]); - if (values[i] != 0 && values[i] != 1) - die("value must be 0 or 1: %s", argv[i + 1]); + if (values[i] != 0 && values[i] != 1) + die("value must be 0 or 1: %s", argv[i]); - if (offsets[i] > INT_MAX) - die("invalid offset: %s", argv[i + 1]); + if (offsets[i] > INT_MAX) + die("invalid offset: %s", argv[i]); + } } - chip = chip_open_lookup(device); - if (!chip) - die_perror("unable to open %s", device); - lines = gpiod_chip_get_lines(chip, offsets, num_lines); if (!lines) die_perror("unable to retrieve GPIO lines from chip"); From patchwork Thu Feb 3 04:21:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 540191 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32CC5C433EF for ; Thu, 3 Feb 2022 04:23:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349287AbiBCEXF (ORCPT ); Wed, 2 Feb 2022 23:23:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbiBCEXE (ORCPT ); Wed, 2 Feb 2022 23:23:04 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74B8DC061714 for ; Wed, 2 Feb 2022 20:23:04 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id z14-20020a17090ab10e00b001b6175d4040so8900778pjq.0 for ; Wed, 02 Feb 2022 20:23:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EbHkElAxdxg7UeMWDYrSHAO+RpshB1hCDYOyLTuzLF8=; b=ji2Crxf29WymASA7SKUltPrwgBoYTSuYTAADN3qxQn8ZN6ViOuU7W2bz9XZsK3sbPw r4xd1UQ/LeW5qYjA/x1jjRyuOvSnvH++Zl2Y9aSySWLunUYvR2qqMuBkgg8B1l6gBLLI dpvjGeY7QffRc1aEqW81pH15562o5MxrQ1TCCjFbJG08kpvpc1aafjS53xir4En+zy+t vCXQoRxQeBkgQ7M2h75qYxNRMTymJigHLBr+8sr5F8vnQi7qMQnzBSuRf1JNDH/3bKW+ pNi7XdUQB6ayo72gxw+NLMKP4Ei3cCUT9JXBP/Dt1hWpFM63W6O+YekDe+nCJPRVio0S +MMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=EbHkElAxdxg7UeMWDYrSHAO+RpshB1hCDYOyLTuzLF8=; b=rd/7csPzrfKgbxAo45RGGiMb2bqbt1cZwL3xSXGwcGNdsuf0HD+wQXsh4Gj9/4Xw0y zgCxn2yeztt0g5AUWkpSspMN20tOTD00pC8q/d1qdvsGGQxO2NFuM0lojD53DmGlbT5Z QEmNNnoQMIJgOr0Ns2dkkZHzKQ/mHed9hbpqIwB/aNLg5CxHT1Zh8vQmii+psC9ezXOL OEa1UbCxteDe+MANrciCwTrr/cJntmUUG9ob1oXQEgy2Gt+4KQjTAubfNX2P21bceKM8 qpvBUijWoX6/MrUi+rxybiX1Ve/vo4DvLCPtxi3Pm3mLG0+uHvzaTDcSiuNPOhU3+vl0 yM0g== X-Gm-Message-State: AOAM530zYjT6xA4MgUUlIPYaNSOs2GQcjV6RiEwDB1z+2HXWvEb11gb5 d7eaWYWQO6HXRJwJTIOR8cE= X-Google-Smtp-Source: ABdhPJzOoDrfzluWROAW59ZI8pGI551htVXlaz9j3xa9P2KCEJiIh5pFGwtavtaFXrECAUfozSkuoA== X-Received: by 2002:a17:903:18d:: with SMTP id z13mr33767848plg.113.1643862183946; Wed, 02 Feb 2022 20:23:03 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:23:03 -0800 (PST) Sender: "joel.stan@gmail.com" From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Cc: Andrew Jeffery , Zev Weiss , openbmc@lists.ozlabs.org Subject: [libgpiod PATCH 6/7] gpio-tools-test: Add gpioset --by-name tests Date: Thu, 3 Feb 2022 14:51:33 +1030 Message-Id: <20220203042134.68425-7-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Signed-off-by: Joel Stanley --- tools/gpio-tools-test.bats | 111 +++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/tools/gpio-tools-test.bats b/tools/gpio-tools-test.bats index a5b97e1f98ee..a90c695fbc0f 100755 --- a/tools/gpio-tools-test.bats +++ b/tools/gpio-tools-test.bats @@ -670,6 +670,117 @@ teardown() { output_regex_match ".*unable to request lines.*" } +@test "gpioset: invalid value (by name)" { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name gpio-mockup-A-0=foobar + + test "$status" -eq "1" + output_regex_match ".*invalid offset<->value mapping: gpio-mockup-A-0=foobar.*" +} + +@test "gpioset: invalid line syntax by name, missing =" { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name gpio-mockup-A-0foobar + + test "$status" -eq "1" + output_regex_match ".*invalid name/value 'gpio-mockup-A-0foobar'*" +} + +@test "gpioset: invalid line syntax by name, leading =" { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name =gpio-mockup-A-0foobar + + test "$status" -eq "1" + output_regex_match ".*unable to find '' on a gpiochip*" +} + +@test "gpioset: missing value (by name)" { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name gpio-mockup-A-0= + + test "$status" -eq "1" + output_regex_match ".*invalid offset<->value mapping: gpio-mockup-A-0=*" +} + +@test "gpioset: invalid line name (from different gpiochip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name \ + gpio-mockup-A-0=1 \ + gpio-mockup-A-2=0 \ + gpio-mockup-B-3=1 + + test "$status" -eq "1" + output_regex_match ".*does not contain line 'gpio-mockup-B-3'.*" +} + +@test "gpiogst: invalid line name (non existant line on a chip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name \ + gpio-mockup-A-0=1 \ + missing=0 + + test "$status" -eq "1" + output_regex_match ".*does not contain line 'missing'.*" +} + +@test "gpioset: invalid line name (non existant line, no chip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioset --by-name missing=1 + + test "$status" -eq "1" + output_regex_match ".*unable to find 'missing' on a gpiochip*" +} + +@test "gpioset: set lines by name and wait for SIGTERM" { + gpio_mockup_probe named-lines 2 2 8 + + coproc_run_tool gpioset --mode=signal --by-name \ + gpio-mockup-C-3=1 \ + gpio-mockup-C-6=1 \ + gpio-mockup-C-7=0 + + gpio_mockup_check_value 2 3 1 + gpio_mockup_check_value 2 6 1 + gpio_mockup_check_value 2 7 0 + + coproc_tool_kill + coproc_tool_wait + + test "$status" -eq "0" +} + +@test "gpioset: set lines by name using short option and wait for SIGTERM" { + gpio_mockup_probe named-lines 2 2 8 + + coproc_run_tool gpioset --mode=signal -N \ + gpio-mockup-C-3=1 \ + gpio-mockup-C-6=1 \ + gpio-mockup-C-7=0 + + gpio_mockup_check_value 2 3 1 + gpio_mockup_check_value 2 6 1 + gpio_mockup_check_value 2 7 0 + + coproc_tool_kill + coproc_tool_wait + + test "$status" -eq "0" +} + +@test "gpioset: no arguments (by name)" { + run_tool gpioset --by-name + + test "$status" -eq "1" + output_regex_match ".*at least one line name must be specified" +} + # # gpiomon test cases # From patchwork Thu Feb 3 04:21:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 539720 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32109C433EF for ; Thu, 3 Feb 2022 04:23:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233605AbiBCEXI (ORCPT ); Wed, 2 Feb 2022 23:23:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235298AbiBCEXH (ORCPT ); Wed, 2 Feb 2022 23:23:07 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBBF6C06173B for ; Wed, 2 Feb 2022 20:23:07 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id cq9-20020a17090af98900b001b8262fe2d5so3235349pjb.0 for ; Wed, 02 Feb 2022 20:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N0qE6gevIlt5TZkcv2OZGPBrY66lgxFvcf9i3jBRUkY=; b=aN0raUAZo+oeseYZz27rcN64NYcG+L6yp0uoPK4vMhQN+eJ355BogSpIO1mzEF4Ni6 rDoY9TzMDTHLS73j3m+crNB9tMQVopJnFSEDmsBL4JJ+aZyu+cwxRYu01HEulZlu4PDz ICk96aSGhfNCtpw1BMMRoyoarHASsrtoU3bk0CM04rGFtd8EA5IN2T94NE7EI2eII9OT Ka0WiF4LEzJqYEnkbdKDwHSGbKFxNCUNUC9vgui3D3LlxJLHAo8/Hsu2m6XU3GIFnPcY O6YsKntlgniJmMyy/Rzk/FyzOs51nRdrBOR8UmMuQtlQUrfuVCGcPq/34vPPLzKRuG2w +M3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=N0qE6gevIlt5TZkcv2OZGPBrY66lgxFvcf9i3jBRUkY=; b=Wswm5SvHKFAArr7gG1rsp2d8d6rX57+eYjNOW8AZS14Y4CP2fQVGsSMta2XNaQIxZV zZsnS45CqskMa1PDnFNfTXSLHz2KsCzbDbarG4zXIt2zHxH0KPWzoE8o/b6QJm23gUca 0lwsQybWZiPc6tMLgEdpFoTS+xZGcArDFTmnA6s68YavzfEQPva6YnSoZgp+xheHQn9g ThR2aItPJfXyhflkZtqaiMf4NNXYPikQDFQ4RqCinMDsIAl9u3Z+sYXBc2bnZNsPNdCZ it20GaQNBat00ekcHA6sLRe8MnxqxktXo4xSm4+Q8g/7k5rPOYk9OvHT2j96Rfyg+PSt oN7g== X-Gm-Message-State: AOAM532kCkBmiblV0tJ4aaDBveXpeszAqO2Odskk4q7PuZlNO+GlhTLE SJDO5WsIl2Ll0u0JXMm/mto= X-Google-Smtp-Source: ABdhPJz3EqLpyIF+ZZogMi9RyQMN7PEAmqnQjL4QV3g8bvqn3J7HCotzT0qVMpLUmhHcFI+qU/EVcA== X-Received: by 2002:a17:903:124e:: with SMTP id u14mr34604544plh.57.1643862187258; Wed, 02 Feb 2022 20:23:07 -0800 (PST) Received: from voyager.lan ([45.124.203.14]) by smtp.gmail.com with ESMTPSA id mp22sm7814137pjb.28.2022.02.02.20.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 20:23:06 -0800 (PST) Sender: "joel.stan@gmail.com" From: Joel Stanley To: Bartosz Golaszewski , linux-gpio@vger.kernel.org Cc: Andrew Jeffery , Zev Weiss , openbmc@lists.ozlabs.org Subject: [libgpiod PATCH 7/7] gpio-tools-test: Add gpioget --by-name tests Date: Thu, 3 Feb 2022 14:51:34 +1030 Message-Id: <20220203042134.68425-8-joel@jms.id.au> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203042134.68425-1-joel@jms.id.au> References: <20220203042134.68425-1-joel@jms.id.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Signed-off-by: Joel Stanley --- tools/gpio-tools-test.bats | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tools/gpio-tools-test.bats b/tools/gpio-tools-test.bats index a90c695fbc0f..068ade357a35 100755 --- a/tools/gpio-tools-test.bats +++ b/tools/gpio-tools-test.bats @@ -391,6 +391,79 @@ teardown() { output_regex_match ".*invalid bias.*" } +@test "gpioget: invalid line name (from different gpiochip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioget --by-name \ + gpio-mockup-A-0 \ + gpio-mockup-A-2 \ + gpio-mockup-B-3 + + test "$status" -eq "1" + output_regex_match ".*does not contain line 'gpio-mockup-B-3'.*" +} + +@test "gpioget: invalid line name (non existant line on a chip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioget --by-name \ + gpio-mockup-A-0 \ + missing + + test "$status" -eq "1" + output_regex_match ".*does not contain line 'missing'.*" +} + +@test "gpioget: invalid line name (non existant line, no chip) " { + gpio_mockup_probe named-lines 8 8 8 + + run_tool gpioget --by-name missing + + test "$status" -eq "1" + output_regex_match ".*unable to find gpiochip.*" +} + +@test "gpioget: read some lines by name" { + gpio_mockup_probe named-lines 8 8 8 + + gpio_mockup_set_pull 1 1 1 + gpio_mockup_set_pull 1 4 1 + gpio_mockup_set_pull 1 6 1 + + run_tool gpioget --by-name \ + gpio-mockup-B-0 \ + gpio-mockup-B-1 \ + gpio-mockup-B-4 \ + gpio-mockup-B-6 + + test "$status" -eq "0" + test "$output" = "0 1 1 1" +} + +@test "gpioget: no arguments (by name)" { + run_tool gpioget --by-name + + test "$status" -eq "1" + output_regex_match ".*at least one line name must be specified" +} + +@test "gpioget: read some lines by name using short option" { + gpio_mockup_probe named-lines 8 8 8 + + gpio_mockup_set_pull 1 1 1 + gpio_mockup_set_pull 1 4 1 + gpio_mockup_set_pull 1 6 1 + + run_tool gpioget -N \ + gpio-mockup-B-0 \ + gpio-mockup-B-1 \ + gpio-mockup-B-4 \ + gpio-mockup-B-6 + + test "$status" -eq "0" + test "$output" = "0 1 1 1" +} + # # gpioset test cases #