From patchwork Thu Jun 27 15:31:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuang Zhu X-Patchwork-Id: 807959 Received: from ilama.link.melty.land (mail.melty.land [45.77.175.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E0F019750B for ; Thu, 27 Jun 2024 15:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.77.175.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719502278; cv=none; b=p0qR5TQIqkQTkjf8PVaI4/ycX0XIYZ0Mub93BcPWYGg1d2C4pvuMcAXr5SrwY7hk4OLfYUR6x2sqBazLoyrL2j/2e7HidZuG0tPvFN0ZdZodPkqMZAQH/LYHE89HHBRs097jAS3LlcMQ1fqJ0KP04n9JCason9FKr0CkKSlKLwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719502278; c=relaxed/simple; bh=QsshmHM5WxHxWeGPUiVPLP6OWDvuzPGREjmPggvkXzw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=o2QZ1zrWFcsPnDRHHUyo6bj1qJf4OQ/Ncwqa5h/HkzzQr3T156jvJ6G6Z+0vYZk5/f1EiNqoi5Vl7OngcqjgD3Nltw8J/BOjSVLMH0yTQ9EX6TgR4ry9Iu1khgYs21iiiHMZrW7RjEqe9LqrS5k4a708StdCyxFUNW6G4kH1gi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=melty.land; spf=pass smtp.mailfrom=melty.land; dkim=pass (1024-bit key) header.d=melty.land header.i=@melty.land header.b=wjLlEAXg; arc=none smtp.client-ip=45.77.175.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=melty.land Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=melty.land Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=melty.land header.i=@melty.land header.b="wjLlEAXg" Received: from localhost.localdomain (hawthorn.chuang [192.168.174.5]) by ilama.link.melty.land (Postfix) with ESMTPSA id 6AE768BAECB; Thu, 27 Jun 2024 23:31:07 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=melty.land; s=default; t=1719502267; bh=QsshmHM5WxHxWeGPUiVPLP6OWDvuzPGREjmPggvkXzw=; h=From:To:Cc:Subject:Date; b=wjLlEAXgPUubp+JmEspl4S5oT9WKziOaINq51/02BP/j2dTZONkLriZ8crI3dOw0r 38vzbMN89OpTgOgVgtmRD7cYstYpbdm2iXRMypYxZ8k2U39zThFJULbLVqQOnQFKRG 4nXS+ZOqLozNPNjAIKnP6ESvbIZ6RBb8fZy17ca0= From: Chuang Zhu To: linux-gpio@vger.kernel.org Cc: Chuang Zhu Subject: [libgpiod][PATCH v2 1/2] bindings: python: tests: add a test case for line request by name with multiple entries Date: Thu, 27 Jun 2024 23:31:02 +0800 Message-ID: <20240627153103.594107-1-chuang+git@melty.land> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuang Zhu Signed-off-by: Chuang Zhu --- bindings/python/tests/tests_line_request.py | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index f99b93d..c9a5c81 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -310,6 +310,40 @@ class LineRequestComplexConfig(TestCase): self.assertEqual(chip.get_line_info(3).edge_detection, Edge.BOTH) +class LineRequestComplexConfigByName(TestCase): + def setUp(self): + self.sim = gpiosim.Chip(num_lines=4, line_names={2: "foo", 3: "bar", 1: "baz", 0: "xyz"}) + self.req = gpiod.request_lines( + self.sim.dev_path, + { + ("baz", "bar"): gpiod.LineSettings(direction=Direction.OUTPUT), + ("foo", "xyz"): gpiod.LineSettings(direction=Direction.INPUT) + }, + ) + + def tearDown(self): + self.req.release() + del self.req + del self.sim + + def test_set_values_by_name(self): + self.req.set_values( + {"bar": Value.ACTIVE, "baz": Value.INACTIVE} + ) + + self.assertEqual(self.sim.get_value(1), SimVal.INACTIVE) + self.assertEqual(self.sim.get_value(3), SimVal.ACTIVE) + + def test_get_values_by_name(self): + self.sim.set_pull(0, Pull.UP) + self.sim.set_pull(2, Pull.DOWN) + + self.assertEqual( + self.req.get_values(["foo", "xyz"]), + [Value.INACTIVE, Value.ACTIVE], + ) + + class RepeatingLinesInRequestConfig(TestCase): def setUp(self): self.sim = gpiosim.Chip(num_lines=4, line_names={0: "foo", 2: "bar"}) From patchwork Thu Jun 27 15:31:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuang Zhu X-Patchwork-Id: 808399 Received: from ilama.link.melty.land (mail.melty.land [45.77.175.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65DC219750B for ; Thu, 27 Jun 2024 15:31:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.77.175.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719502283; cv=none; b=ng9XCp6rRVoPd7a3r4hb2QlEOC9Cwy983Zquq7j8j68j4GMa77lkDy3+DHgjpVPstu8RQLI0lYm4XedQyTfawauogpLmAyejFWBMmL8I+7eld04q1do5z7kwSMhbm7hmqeZIUkJagd8Q/J/1PwjGlj0jb+UM1XpDjUop5wrNvbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719502283; c=relaxed/simple; bh=+lkh4VFfd0iLmwe5Qv7C/ovto4qw4zZXj7sa10shWTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b2kcF1i81bSiRTEk94jqZGTF9270KXWxPoVeylucVzOzCpfkz34rM7fc2729eaxt1fUZ8j3HpvcIUddUorB4UOVCFjMnvuJFVrcImBGcjVXUJEhqBG67+Or9kJT7fjGz98skFMYNgWWFUjo2ox1bermlgPjk1Lwy2mliGU+2Uds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=melty.land; spf=pass smtp.mailfrom=melty.land; dkim=pass (1024-bit key) header.d=melty.land header.i=@melty.land header.b=wSxZo/rT; arc=none smtp.client-ip=45.77.175.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=melty.land Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=melty.land Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=melty.land header.i=@melty.land header.b="wSxZo/rT" Received: from localhost.localdomain (hawthorn.chuang [192.168.174.5]) by ilama.link.melty.land (Postfix) with ESMTPSA id 38A4F8BAED0; Thu, 27 Jun 2024 23:31:08 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=melty.land; s=default; t=1719502268; bh=+lkh4VFfd0iLmwe5Qv7C/ovto4qw4zZXj7sa10shWTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wSxZo/rTHGg9Vv3nI66irNbcBj+/+mwLO35xZmSPKU8DbW9QxOlfC1T45XEWETGji 3cbRPixSLObTdD/XpwWCGGYKhzKsKbciKsRpK4s78Ry5ZLFrYt73VEluv57VxDXLDg u5aRFlADHXBz+NjfLpLdO8oLG1sbbmbAar3EUgRY= From: Chuang Zhu To: linux-gpio@vger.kernel.org Cc: Chuang Zhu Subject: [libgpiod][PATCH v2 2/2] bindings: python: fix line request by name with multiple entries Date: Thu, 27 Jun 2024 23:31:03 +0800 Message-ID: <20240627153103.594107-2-chuang+git@melty.land> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240627153103.594107-1-chuang+git@melty.land> References: <20240627153103.594107-1-chuang+git@melty.land> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuang Zhu When multiple entries are requested using line names in Chip.request_lines, only the the last entry is added to LineRequest._name_map, causing a ValueError when trying to use functions like LineRequest.set_value on any former entries. This patch fixes that by moving the required variables to the correct scope. Signed-off-by: Chuang Zhu --- bindings/python/gpiod/chip.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 19c62cd..55f0c3e 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -279,11 +279,12 @@ class Chip: else: mapped_output_values = None + name_map = dict() + offset_map = dict() + global_output_values = list() + for lines, settings in config.items(): offsets = list() - name_map = dict() - offset_map = dict() - global_output_values = list() if isinstance(lines, int) or isinstance(lines, str): lines = (lines,)