Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp884770rdb; Wed, 6 Dec 2023 02:47:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IH84rVHLmQXrZ4Y6bgg2DNoejWoXFb4FH0lPpKWeNmA/4cAJT7xU9SJm5l2DwJKnLJF0iNn X-Received: by 2002:a17:90b:33c6:b0:286:707a:ba32 with SMTP id lk6-20020a17090b33c600b00286707aba32mr711022pjb.38.1701859633407; Wed, 06 Dec 2023 02:47:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701859633; cv=none; d=google.com; s=arc-20160816; b=g7VrazwoZgF8kb6ItniEZ13CMx68CGhuAoTBUDRfKe4vOtuN5HMIibh8nV2d0cEDwE LHdhO6VboUWHgz8JzKyqSlY5lVqkna5DLabEHRYQ1IcWvaMRxWUy8PCGxMG4PWi2M663 rZfrasBAjHj6u+CAmQPnuCHAgUDfeJ08eziYaqFkCsvHgcdNN3BLfqKEsKQZK63F/t2T kPqU3abktQXjBVQnf7ZgasDI0BIkxWEEpLitRIT+Z7X8uIZ21WQZlGp3c+/Guh3exCKc +1yvGZm1yStt3FkY7sXBwHiHSdhNiDN1YHTn0ffXSsqsf7iWoakxgo1uuEc5t3isuuDi g0ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=HkO+eK7cRvXeQVbSKzt/fTyQG4GEZMbg2UsfhejWDME=; fh=M/4CRKlsQR53kOvbvsHfGDOrpcvBUt/h3Rh4tB3zkdA=; b=S2XtGUDACJl2j2fhdUFE3kKP/yY12A9YgbnNFI8AgoT7gpFy2kwaAzSXL+x6xoPw34 Xc3mXWz6yHmHh0x+d8IqhlhEqMeE1zKjDrn91eebIGd3Dm+tsUlPESPmLykTA1RbxgMn npkMOpuYve+gj2iUwhrZWU6UXilhIsGtWpANG/Ftg9ir+wANGA59NQOZZXlRAsE2c5jx mNVGJCtoN4ptflbgLdkxQTCq3idJN+3lpK1Z2ax84E6t0itJ9NS5ptVHECRqy8bRg5RD fnGB+HDfp7lBKBNPkQcnWW69AGnXGmLkffDv57iQA1hiWgabgLwlVZQ8GK4sWXQYA3up eLrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WsnaotKY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id ei5-20020a17090ae54500b00286c365df4bsi4188810pjb.30.2023.12.06.02.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 02:47:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WsnaotKY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4E4C9802C6B5; Wed, 6 Dec 2023 02:47:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377577AbjLFKqt (ORCPT + 99 others); Wed, 6 Dec 2023 05:46:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377742AbjLFKqe (ORCPT ); Wed, 6 Dec 2023 05:46:34 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFE051723 for ; Wed, 6 Dec 2023 02:46:19 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8B92C433C7; Wed, 6 Dec 2023 10:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701859579; bh=Hif8AQyE2YPxh4c1ifXxoCQdIEAvk7GdDFIcyZbu0Rg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WsnaotKYKcZ5jyNyBNanqgasEniPy/IK218oEK0mTTJx4IZhwZ8WsB4RfXXX7Mtcp KQA4sKiqnZ5SFFXGlfuxyJ0Xu2xEETjfxzC+MHlzPO6lTz1Nx09ogJMGxTYNHwsx6R 0T4fI5Kr+ChGEwCdSr4K/j2LMZbv0C9f3xDJKF+/rAwE+bI5wJNmt2mWh8tCf7QuyJ 8la3tRyiT4w/MHYYpU41q9ESjjMu+jiA8zbFrPlMDokrG24Vq9SR/B9IhH9Nq5ySLI gLIm4j4m2b+F8bUYIFCagviAwmjey/W8ihBeezcHXf6xo5aTAnNzVphOsyb78LAfHJ KCummq02Vmt5A== From: Benjamin Tissoires Date: Wed, 06 Dec 2023 11:45:57 +0100 Subject: [PATCH v2 06/15] selftests/hid: tablets: move move_to function to PenDigitizer MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231206-wip-selftests-v2-6-c0350c2f5986@kernel.org> References: <20231206-wip-selftests-v2-0-c0350c2f5986@kernel.org> In-Reply-To: <20231206-wip-selftests-v2-0-c0350c2f5986@kernel.org> To: Jiri Kosina , Benjamin Tissoires , Shuah Khan , Peter Hutterer Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701859565; l=5364; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=Hif8AQyE2YPxh4c1ifXxoCQdIEAvk7GdDFIcyZbu0Rg=; b=sB4yEgfiYows++yOpiowOjIdzwzmxxx9prSxRmLvJL+ZhD1Z8+3Wai3Ol4MNtCIMp+teVboBa Pu4jM341xvcDVgNslAXP6SuRQhajOo/DpUXJ7GVfVF/hwDXUVcgvVmJ X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 02:47:12 -0800 (PST) We can easily subclass PenDigitizer for introducing firmware bugs when subclassing Pen is harder. Move move_to from Pen to PenDigitizer so we get that ability Reviewed-by: Peter Hutterer Signed-off-by: Benjamin Tissoires --- no changes in v2 --- tools/testing/selftests/hid/tests/test_tablet.py | 97 ++++++++++++------------ 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/tools/testing/selftests/hid/tests/test_tablet.py b/tools/testing/selftests/hid/tests/test_tablet.py index ddf28c245046..27260dc02cc4 100644 --- a/tools/testing/selftests/hid/tests/test_tablet.py +++ b/tools/testing/selftests/hid/tests/test_tablet.py @@ -282,7 +282,7 @@ class Pen(object): self._old_values = None self.current_state = None - def _restore(self): + def restore(self): if self._old_values is not None: for i in [ "x", @@ -297,50 +297,8 @@ class Pen(object): ]: setattr(self, i, getattr(self._old_values, i)) - def move_to(self, state): - # fill in the previous values - if self.current_state == PenState.PEN_IS_OUT_OF_RANGE: - self._restore() - - print(f"\n *** pen is moving to {state} ***") - - if state == PenState.PEN_IS_OUT_OF_RANGE: - self._old_values = copy.copy(self) - self.x = 0 - self.y = 0 - self.tipswitch = False - self.tippressure = 0 - self.azimuth = 0 - self.inrange = False - self.width = 0 - self.height = 0 - self.invert = False - self.eraser = False - self.x_tilt = 0 - self.y_tilt = 0 - self.twist = 0 - elif state == PenState.PEN_IS_IN_RANGE: - self.tipswitch = False - self.inrange = True - self.invert = False - self.eraser = False - elif state == PenState.PEN_IS_IN_CONTACT: - self.tipswitch = True - self.inrange = True - self.invert = False - self.eraser = False - elif state == PenState.PEN_IS_IN_RANGE_WITH_ERASING_INTENT: - self.tipswitch = False - self.inrange = True - self.invert = True - self.eraser = False - elif state == PenState.PEN_IS_ERASING: - self.tipswitch = False - self.inrange = True - self.invert = True - self.eraser = True - - self.current_state = state + def backup(self): + self._old_values = copy.copy(self) def __assert_axis(self, evdev, axis, value): if ( @@ -384,6 +342,51 @@ class PenDigitizer(base.UHIDTestDevice): continue self.fields = [f.usage_name for f in r] + def move_to(self, pen, state): + # fill in the previous values + if pen.current_state == PenState.PEN_IS_OUT_OF_RANGE: + pen.restore() + + print(f"\n *** pen is moving to {state} ***") + + if state == PenState.PEN_IS_OUT_OF_RANGE: + pen.backup() + pen.x = 0 + pen.y = 0 + pen.tipswitch = False + pen.tippressure = 0 + pen.azimuth = 0 + pen.inrange = False + pen.width = 0 + pen.height = 0 + pen.invert = False + pen.eraser = False + pen.x_tilt = 0 + pen.y_tilt = 0 + pen.twist = 0 + elif state == PenState.PEN_IS_IN_RANGE: + pen.tipswitch = False + pen.inrange = True + pen.invert = False + pen.eraser = False + elif state == PenState.PEN_IS_IN_CONTACT: + pen.tipswitch = True + pen.inrange = True + pen.invert = False + pen.eraser = False + elif state == PenState.PEN_IS_IN_RANGE_WITH_ERASING_INTENT: + pen.tipswitch = False + pen.inrange = True + pen.invert = True + pen.eraser = False + elif state == PenState.PEN_IS_ERASING: + pen.tipswitch = False + pen.inrange = True + pen.invert = True + pen.eraser = True + + pen.current_state = state + def event(self, pen): rs = [] r = self.create_report(application=self.cur_application, data=pen) @@ -462,7 +465,7 @@ class BaseTest: cur_state = PenState.PEN_IS_OUT_OF_RANGE p = Pen(50, 60) - p.move_to(PenState.PEN_IS_OUT_OF_RANGE) + uhdev.move_to(p, PenState.PEN_IS_OUT_OF_RANGE) events = self.post(uhdev, p) self.validate_transitions(cur_state, p, evdev, events) @@ -475,7 +478,7 @@ class BaseTest: events = self.post(uhdev, p) self.validate_transitions(cur_state, p, evdev, events) assert len(events) >= 3 # X, Y, SYN - p.move_to(state) + uhdev.move_to(p, state) if scribble and state != PenState.PEN_IS_OUT_OF_RANGE: p.x += 1 p.y -= 1 -- 2.41.0