From patchwork Wed Jun 26 05:38:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1952370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=P0igrob1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-7701-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W89Tx53kkz20XB for ; Wed, 26 Jun 2024 15:38:29 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 71E96B23471 for ; Wed, 26 Jun 2024 05:38:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4161714534D; Wed, 26 Jun 2024 05:38:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P0igrob1" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEA1213D28F for ; Wed, 26 Jun 2024 05:38:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719380307; cv=none; b=VKTmV5626MGAIp6oTpjTUkFUXvVY3vOFnPzOD1BEKfbconM+FSRs+kUVkTXjT3MxVxF4/3qduyvTVqgoRgiNZh+wQ2llakZZg8c4brjxSdPXIVgge1rPYqi6V+/Qi1uxccg0ogAEKBQof2JRLe1SRUEpWCTaSVK2Bzv5Ds86Pmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719380307; c=relaxed/simple; bh=R9TO1OdcFXqz05anwosJ6q7usrPOMc/RWkOrA0Z+E/A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X/j+y3vLQW0cSPYC2zoQSpKfT2u1bgSLwH/mcSMiQn+FB3wqCnhRD2M/ybZCAr9jZ4JhAfFMklju7ztrry+7pLGgQELR/dOXiCmpjbFtO5wt9zMcnHf2uuehbpDfiXTEm5t+MCPeEGNGuGd7EwCoGYkiP6aNINGMAOayzrkXBVs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P0igrob1; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2c80637d8adso4261062a91.0 for ; Tue, 25 Jun 2024 22:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719380305; x=1719985105; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bcc5dm+/D1AGOp5FR1AXSdHqXjg+ggR1IoBjJP6gie4=; b=P0igrob1U7wEC/Mjp8ZwG2N78JFwiIsLW4MvgsGtMFN1W2obQ8h4X49e9+DYEnzyZ9 Aq5TpQ4e9o4u5TEhfjlYsHp97lO6OcMuZYRZK6zUgACdXvijtjz0IMZvVc6ytueOZBqZ s2tJ2efXGDZzXBbNm2PTNrK2DLBl7EiOhBqVarESgUWAGCccg2Lqcl1gJrfwy3MUoZ1Q ME2X0/Zls+u7C+reuneyu4IxfYglsh6d15NP/FJxPGtmNoZGEBMcRNj/ImVEi1MgVVqk gtSYk5My9FBf4zbgviIuxtGnqtZ+a1AI+cK0ucy2i1R8zn3Ihc0OEor59m0uU7qLJntF TyPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719380305; x=1719985105; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bcc5dm+/D1AGOp5FR1AXSdHqXjg+ggR1IoBjJP6gie4=; b=JN20KRIlPs6WLEt08eqZ0kM51yanC0gNqK8kSEwrPopg/ygst8ilpU1gMAjNKWIGmX rxc2KypNtXJ1k9LhB/DSxuhqdl0I++a89bTUlyhaP2RFqBFmpm49BvMQRq9oV1CCXQ2K xwfW7tfHZlvYpk//xbXt7MKuCccoVH/ONCyDXjl0htJTAFppH//neFiulbEw8bqt3qOp Wv7+h5yhTcuUHz4G9Zcq7xAf0PDZURn7baNqsb6xrInfAD6M2ttvuBVnIgDaluO0mYu/ y3wfmDhWypnX2uy3dhC3MAyIMGurodO5boS77zPOByojPakR/aWGInThccPrpOW8MoJK mD0A== X-Gm-Message-State: AOJu0YycsfKL0pb+7z61u/Wx0xF9Cb8IqhRIFdl/tdxopepH2Yzhl7QZ HDOImMgUdIKyfk+m46kL08Fwl+KlvzP07ugArKLc2j9dKG0pappGm953yA== X-Google-Smtp-Source: AGHT+IG6vZhYS1gy2cCfzcgeRT+qzRDDbmz0u5Aaxrwne69Atq7WvFvtdUng8R+8UjDoy6rQ8ebyWA== X-Received: by 2002:a17:90b:4b0c:b0:2c2:f472:64b0 with SMTP id 98e67ed59e1d1-2c8582e1711mr7477589a91.49.1719380304642; Tue, 25 Jun 2024 22:38:24 -0700 (PDT) Received: from rigel.home.arpa ([118.209.204.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c8d7b4f821sm674370a91.0.2024.06.25.22.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 22:38:24 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod][PATCH 1/3] bindings: python: tests: extend reconfiguration tests Date: Wed, 26 Jun 2024 13:38:06 +0800 Message-Id: <20240626053808.179457-2-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240626053808.179457-1-warthog618@gmail.com> References: <20240626053808.179457-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A number of the corner cases for reconfiguration are untested, including - using None for default settings - missing settings for some lines - jumbled line ordering relative to the request - extra settings for non-requested lines Add tests for these corner cases. Signed-off-by: Kent Gibson --- bindings/python/tests/tests_line_request.py | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index f99b93d..2f375d6 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -490,6 +490,56 @@ class ReconfigureRequestedLines(TestCase): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.INPUT) + def test_reconfigure_by_misordered_offsets(self): + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.OUTPUT) + self.req.reconfigure_lines( + {(6, 0, 3, 2): gpiod.LineSettings(direction=Direction.INPUT)} + ) + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.INPUT) + + def test_reconfigure_by_misordered_names(self): + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.OUTPUT) + self.req.reconfigure_lines( + {(0, "baz", 2, "foo"): gpiod.LineSettings(direction=Direction.INPUT)} + ) + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.INPUT) + + def test_reconfigure_with_default(self): + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.OUTPUT) + self.req.reconfigure_lines({ + 0: gpiod.LineSettings(direction=Direction.INPUT), + 2: None, + ("baz", "foo"): gpiod.LineSettings(direction=Direction.INPUT) + }) + info = self.chip.get_line_info(0) + self.assertEqual(info.direction, Direction.INPUT) + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.OUTPUT) + + def test_reconfigure_missing_offsets(self): + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.OUTPUT) + self.req.reconfigure_lines( + {(6, 0): gpiod.LineSettings(direction=Direction.INPUT)} + ) + info = self.chip.get_line_info(0) + self.assertEqual(info.direction, Direction.INPUT) + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.OUTPUT) + + def test_reconfigure_extra_offsets(self): + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.OUTPUT) + self.req.reconfigure_lines( + {(0, 2, 3, 6, 5): gpiod.LineSettings(direction=Direction.INPUT)} + ) + info = self.chip.get_line_info(2) + self.assertEqual(info.direction, Direction.INPUT) class ReleasedLineRequestCannotBeUsed(TestCase): def test_using_released_line_request(self): From patchwork Wed Jun 26 05:38:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1952371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OpHIEXNn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-7702-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W89Vf12TPz20XB for ; Wed, 26 Jun 2024 15:39:06 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B25432815E2 for ; Wed, 26 Jun 2024 05:39:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07A9814534D; Wed, 26 Jun 2024 05:39:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OpHIEXNn" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7412C13A88A for ; Wed, 26 Jun 2024 05:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719380340; cv=none; b=YnsN8+iyIUQljzf94GtwYc6xJk+uCowPu/3A8/uJh/CtW6hb1SlcVjWwtOzUbSe1ZlQstl9QV7x6W7JQFTdUKF4dT2YWna5QdIYlMDQvCB71dwURNPLYX3Uxn6DbTH9mLjzdf+gVcN5Yr+zQkdJhFkm5CWYzghePPeNKiRYX1tY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719380340; c=relaxed/simple; bh=gZBFqu0R/6PPSlo2if0/0vNAbQ3tD6vTHK18yKKm/gU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pPISsOuheXUeHvto4/QxvCKM/GX0d3w2dg4yweuwH/4soNwU7iTRMNrIGGOmy/Co5qY1plqGRovLrCq01ck1iPFGatDv5CRdfrO30JmcBqFXZsubGIZuZjD7FwY5cl0pjtw0kVWi9TZHDhuzueGK7K8yfTh+x/uJ10X20IL4tS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OpHIEXNn; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2c8dc2bcb78so195467a91.1 for ; Tue, 25 Jun 2024 22:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719380339; x=1719985139; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=738mUAu30VxXe3Q6QHsbfhwgXaZjZyPVKrJfvd2O7+Y=; b=OpHIEXNnNac3F8gKx6nhkqdg1IbAKnjNAr0dsOxbYxTd5c9oHGLTzHtPTxzzdEXR1P t+pQDCwO5XrS/f5nrvKhC4xBOuRfLnaujysFr1unGUM1L+GHE3PJsWrIuaQP2y16DOi/ DhSLcChjeWdMThzXaoh6AoobYg7HxuwaEx42chWoyt8To+QMSrStH4swyEynt2piNXgV ZQK9XxxgQ4VsKlZX1pQhh/1jOGDq54sl+1igFftDFFb1vrgiamkjoFCa9z7UhpITT+FJ w9ZGcxjGKAFX5zRoLhKJNL/eDQ9kg6oW0sChHitgWK2Vftjsd1D7LBRhFFBKNDVnrbDy P+Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719380339; x=1719985139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=738mUAu30VxXe3Q6QHsbfhwgXaZjZyPVKrJfvd2O7+Y=; b=SE7oJwnVy2GETa5wuVigmWUqxHWD+UM7HtqQsDJ2IuXUwiURALkeu2EGgpGLe1RrQs wRkWLTx0avza+8ez3vcofF9enkKcsk1zCmgCQHaU1Dw5ScGh310zMsoUL2ciApmdQ/qG C+zom9QKMoQf6SQet2XV4IziXIWtZxJ4KM5qlTDerz1vXeVl70HWWyIkesCS8TZq1jdE CVNLIEC96O5e3vBkd/V0ROnVSsOAmzWjN1Di/8fzn3iwuXU6xLT6EdUhl7pC/yWz5zb8 cueq/2c5JTRLIQjxYb7yM3IP+DHnGfMI7bJBPilq/7T7OlfD6DyDnOiX2m/gbZEu8VaG J2cQ== X-Gm-Message-State: AOJu0YyTrDcyt5Sn3qmP5Idn3PRFrGuDkby8NggcKb3Kx8joE4oUyziH Yv0kQ0/RLK2acfFtcH2BnQKaZuLsMPEFj3GHFSVN8PqCribxIdzu237ZlQ== X-Google-Smtp-Source: AGHT+IFvxmOzDeXrxzeOV4CRfQmtA7d836eSKoMSN8KDco0tOPuWa6kIPhZN8d1rv8UQAENGhPXBpQ== X-Received: by 2002:a17:90a:d0c4:b0:2c4:a9b2:d4da with SMTP id 98e67ed59e1d1-2c8613e7a5bmr9243367a91.30.1719380338636; Tue, 25 Jun 2024 22:38:58 -0700 (PDT) Received: from rigel.home.arpa ([118.209.204.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c8d7b4f821sm674370a91.0.2024.06.25.22.38.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 22:38:58 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod][PATCH 2/3] bindings: python: more flexible reconfigure_lines() Date: Wed, 26 Jun 2024 13:38:07 +0800 Message-Id: <20240626053808.179457-3-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240626053808.179457-1-warthog618@gmail.com> References: <20240626053808.179457-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The C API requires the configuration passed to reconfigure_lines() to contain the lines in the same order as they were requested. This is problematic for the Python bindings which accepts the configuration in the form of a dict. For versions prior to Python 3.6, dicts do not maintain insertion order, so iterating over the dict emits lines in unreliable order. Even with later Python versions, the ordering requirement makes reconfigure_lines() awkward to use as subsequent configurations may group line settings quite differently to the request, yet the user must go out of their way to reproduce the original ordering. This is a task better performed by the bindings. Further, while the documentation for reconfigure_lines() states that None settings values are treated as default values, the current implementation raises an error when it tries to dereference the None, thinking it is an actual object. Similarly, providing default values for lines for which no settings are provided would allow support for reconfiguring a subset of requested lines. Rework reconfigure_lines() to remove the ordering requirement and construct the configuration provided to the C API in request order. Populate missing or None line settings with default values to satisfy the requirements of the C API that all requested lines must be reconfigured. Closes: https://github.com/brgl/libgpiod/issues/54 Signed-off-by: Kent Gibson --- bindings/python/gpiod/line_request.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) -- 2.39.2 diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index cde298f..51e600a 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -151,23 +151,26 @@ class LineRequest: Args: config Dictionary mapping offsets or names (or tuples thereof) to - LineSettings. If None is passed as the value of the mapping, - default settings are used. + LineSettings. If no entry exists, or a None is passed as the + settings, then the configuration for that line is not changed. + Any settings for non-requested lines are ignored. """ self._check_released() line_cfg = _ext.LineConfig() + line_settings = {} for lines, settings in config.items(): if isinstance(lines, int) or isinstance(lines, str): lines = [lines] - offsets = [ - self._name_map[line] if self._check_line_name(line) else line - for line in lines - ] + for line in lines: + offset = self._name_map[line] if self._check_line_name(line) else line + line_settings[offset] = settings - line_cfg.add_line_settings(offsets, _line_settings_to_ext(settings)) + for offset in self.offsets: + settings = line_settings.get(offset) or LineSettings() + line_cfg.add_line_settings([offset], _line_settings_to_ext(settings)) self._req.reconfigure_lines(line_cfg) From patchwork Wed Jun 26 05:38:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1952372 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iOhA4EKe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-7703-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W89Vp6JjCz20XB for ; Wed, 26 Jun 2024 15:39:14 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 70DE5B22C58 for ; Wed, 26 Jun 2024 05:39:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74578145FEB; Wed, 26 Jun 2024 05:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iOhA4EKe" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEEF413A88A for ; Wed, 26 Jun 2024 05:39:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719380349; cv=none; b=FmZdLSmZ2Pv7JF4Kg80J6LV7haAHbDWI5ZDA3jyo4T6xBcox9ixHB5AHw8C9w7Dw3xmXvfO8CIhOPSVKup9vjtqxTvg26xmCsFGIx7kgGt+277QF3v/hwJQayUuLoJKW7e4g8oGN6moKMIjCoIz96MH95spwy2gbUaN0RVE+NkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719380349; c=relaxed/simple; bh=MeMfu367/5cTcGcy3hiEtQ6Cgy2S13CUdYI5Fp3I9uA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GJOhCQt12OPDbbgsuvDGdliRBG8wa6B9+lh9nkGdNeJ5LDohjsEOdPG2+SUnO+Y63kUWl1lev4dGTeAzjhCTKUO+1NBBpOuV3R+nqqaHOnWg+apz4YSAbGD0RZkn7v/SVx8YdgIf3DkrVbMYx8sZPMz8HLqAhwzYd10tv+1pHnw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iOhA4EKe; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2c70c372755so5006231a91.1 for ; Tue, 25 Jun 2024 22:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719380347; x=1719985147; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aHbbhYphv1rn2xxMEGHnkWsU6wFQsZJUelXBc9q19C4=; b=iOhA4EKeiV6bfFUyKW6gfonubCrgOCtuzLn+iLxc14lVHPylln8qM3/3JfgXe3Ej+8 NNzG/+pcZHN0TNpMpVLdDEzkSqN6riiaElM2xpsci54AiNUDqrcqmnc/Dntokf7U/lxb 9TLzqeabVP8BNTPrMQIynpJQz9QuDWJCfzHI7LDHGGXFJ7Aq2vD6jffsPoy28WdbuCWm LdHDJLRka9mwkEv86TB7DBG9C6EkfZ+soHm4kOkSeKOQgLefXQlDwn+El2jLyA+04qXs Q4xIsYyyIChq/Gc5SJoEFuU6N/lZOQVeIQRAiV04xoX/k16t9KwAfN4CWkQ/RvRn6mr/ 6MJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719380347; x=1719985147; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aHbbhYphv1rn2xxMEGHnkWsU6wFQsZJUelXBc9q19C4=; b=PSu8nZze9SGJlS+eLawGwm3XYdmz7DGMt942i3eJ62dXrjqNPZ0mgQG04LDTiEOrdD Jyr7YDu9UelnYluCf4y4GgvtmKCM23GBz0/1FRZtfmbzWQKt2XHKXvOJXar/thMbItaD U7S9z/PvGl7bEsXLfOTRo4XCW+UzwmBMH52cI5+IIYNzmOxSWyhf3Fuh/+t2R0V0CqoY 3LFcnkN17lAYb+Vna2xvWGXoCK4QFUFK195eAe53BY8SKnuIHaeujye8P7Jk+6dW9/hU J9S5rnPfDsSaE9Nc74Ei5lhyW1FKmRQ0NynfxBq5rxs296i7iZ7SF2DjzRUpZcKwM4f0 Q8Xg== X-Gm-Message-State: AOJu0Yxn+sZH7tTAKXbECdcl7UIYT+7gla5jB22qCLAaeq5pBLbpnC+D bTCcJxfPiIL3zfxC59PjWkWgrXcbHzmiAAq9B9VJQBdZhIr9U5gYmtBpMA== X-Google-Smtp-Source: AGHT+IGMxIdQW40RENsICTouBM2EV3vk99OsDAwNGkpbyUU/WONFoVzZb/KYwRIu3zutmt1HV6Z+jA== X-Received: by 2002:a17:90a:2f41:b0:2c7:db01:c9ad with SMTP id 98e67ed59e1d1-2c8612a60f5mr7768786a91.18.1719380346895; Tue, 25 Jun 2024 22:39:06 -0700 (PDT) Received: from rigel.home.arpa ([118.209.204.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c8d7b4f821sm674370a91.0.2024.06.25.22.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 22:39:06 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod][PATCH 3/3] bindings: python: tests: add coverage of kernel reconfigure as-is behaviour Date: Wed, 26 Jun 2024 13:38:08 +0800 Message-Id: <20240626053808.179457-4-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240626053808.179457-1-warthog618@gmail.com> References: <20240626053808.179457-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The kernel's handling of reconfigure with default values, as is the case for providing a None value as the settings to the Python bindings' reconfigure_lines(), resets any flags set to non-default values when the line is requested to their default values. While the flags are cleared, the kernel makes no corresponding change to the electrical settings - though subsequent calls to get and set values will apply the updated flags. The tests for missing or None settings are extended to demonstrate the issue for active_low and drive flags, though the issue applies to all flags. The tests fail unless the kernel is patched to ignore reconfiguration of lines without direction set. Signed-off-by: Kent Gibson --- bindings/python/tests/tests_line_request.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index 2f375d6..79167f1 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -5,7 +5,7 @@ import errno import gpiod from . import gpiosim -from gpiod.line import Direction, Edge, Value +from gpiod.line import Direction, Drive, Edge, Value from unittest import TestCase Pull = gpiosim.Chip.Pull @@ -462,7 +462,9 @@ class ReconfigureRequestedLines(TestCase): self.sim = gpiosim.Chip(num_lines=8, line_names={3: "foo", 4: "bar", 6: "baz"}) self.chip = gpiod.Chip(self.sim.dev_path) self.req = self.chip.request_lines( - {(0, 2, "foo", "baz"): gpiod.LineSettings(direction=Direction.OUTPUT)} + {(0, 2, "foo", "baz"): gpiod.LineSettings(direction=Direction.OUTPUT, + active_low=True, + drive=Drive.OPEN_DRAIN)} ) def tearDown(self): @@ -511,6 +513,8 @@ class ReconfigureRequestedLines(TestCase): def test_reconfigure_with_default(self): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) + self.assertTrue(info.active_low) + self.assertEqual(info.drive, Drive.OPEN_DRAIN) self.req.reconfigure_lines({ 0: gpiod.LineSettings(direction=Direction.INPUT), 2: None, @@ -520,10 +524,14 @@ class ReconfigureRequestedLines(TestCase): self.assertEqual(info.direction, Direction.INPUT) info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) + self.assertTrue(info.active_low) + self.assertEqual(info.drive, Drive.OPEN_DRAIN) def test_reconfigure_missing_offsets(self): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) + self.assertTrue(info.active_low) + self.assertEqual(info.drive, Drive.OPEN_DRAIN) self.req.reconfigure_lines( {(6, 0): gpiod.LineSettings(direction=Direction.INPUT)} ) @@ -531,6 +539,8 @@ class ReconfigureRequestedLines(TestCase): self.assertEqual(info.direction, Direction.INPUT) info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) + self.assertTrue(info.active_low) + self.assertEqual(info.drive, Drive.OPEN_DRAIN) def test_reconfigure_extra_offsets(self): info = self.chip.get_line_info(2)