Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4663776rdh; Wed, 29 Nov 2023 07:27:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpuJ/o8zCrmgnmoZgJRbjZ6x+e6hW0Vl+h18DfknBqQo5hSAWXO0XKztBtt3nLHOX759FS X-Received: by 2002:a92:d20f:0:b0:35d:2d3e:38cc with SMTP id y15-20020a92d20f000000b0035d2d3e38ccmr2779511ily.31.1701271658716; Wed, 29 Nov 2023 07:27:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701271658; cv=none; d=google.com; s=arc-20160816; b=zadH8TlJ54XvPzGKrdyzKaH7l88uNSBiIGBEYhybFYzk+pfq26UiCnM+b/xJ6EZ4QA jBWo62vRWHDUIFlJhrHFkdgfahYZlswXtBozwRorjVO4oad0FVpu/ZoWz9BARgs7jh5u NkZYIcJNZ7wZcXLbE97s74R2pjjGA5tXrEVUGvSO6qEoTU8YuMPQi60A7rXMelRm3yiT 2rC1cr3huB/8c2x9XvszuvyamI0C+GQeRoRtUkkgFn5BsB+urIEDmkur3VPCx1/1LOaw n84S1p8U0pYjKDNEkXr3IW70yPUkOuEXsEMGsox8MAT/ykPvknFrQFSAt6i+v/r5D5i7 5YJA== 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=bLFtcsXrv6Y2qD2bLEHLxdH+4nfTRhDk3Uzxr2EaJuk=; fh=M/4CRKlsQR53kOvbvsHfGDOrpcvBUt/h3Rh4tB3zkdA=; b=cWdekdQGUWD8jhutBJrfo5V7+oky1YcOW+74UTEG35Kt6j6S3477RjtWR2L71WhrDb deY+CF0DIjDAf7GHdkNRqRV9oHPDmmOdHb4m55nifmTpaHyHs7pJuKawlRcoh1q7i7Cm /9Tvydh8pHTrV6UV5n/ZfCuakdtrMY9yCF1epbwOKeuOprTcFB8/hLCdoZN89z9fMtut Kja5P+HkS4hw8L6q+6G7IbI4FeaKzTqfB6ajB57i/FG9ajnn4/sKPYbe3+yLlUUDYdEL XjllRXCq1zdw+Ca2jM2J5d8LjDhX4pWD9j3JYaTWaweVYsDQfXwmbawVwsvyqxIHdLNb bxQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r8czLiG4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id x20-20020a63f714000000b005ab2613a571si14800803pgh.495.2023.11.29.07.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 07:27:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r8czLiG4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 231E380930E2; Wed, 29 Nov 2023 07:26:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234775AbjK2PZX (ORCPT + 99 others); Wed, 29 Nov 2023 10:25:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234067AbjK2PZM (ORCPT ); Wed, 29 Nov 2023 10:25:12 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A92AE10E2 for ; Wed, 29 Nov 2023 07:25:13 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADEFCC433C7; Wed, 29 Nov 2023 15:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701271513; bh=cc0b1jiuNKRXpLCKlecakBm8q8bu4sRt8EzldFhVXEg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=r8czLiG4SA/CrUJNFmFmVRqOyTquHJcSu4YN0Pglq3iArYsmbJL9uPF5mLJQxGkT6 V2ZDAZtjZbdUDb3nImKNxYc3yNN00wL87AWjRQ7Dp7ZDlxHrrwihQEPfuAYbL71qUh JPlXg3UMrdRUP/+bm7Yrcziqa/fnkdd9FXFLrjZ1/vf8w8q+NpRAK22KSyiX7uuqSf qIVDpYZd0ZyYoW8E+D+0d7YxnGdA9pG13y3m5Z0i02x4eSjM4LSQW+BzeEVUXoMSgY AcHhroL+tU1nPo9OVNwkuUh6ItLeuKTNXf9m+5RVgZOSnKm8L7UmJ8/esfn93JjdXH Qd4BUXYDPEz4w== From: Benjamin Tissoires Date: Wed, 29 Nov 2023 16:24:31 +0100 Subject: [PATCH 06/12] 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: <20231129-wip-selftests-v1-6-ba15a1fe1b0d@kernel.org> References: <20231129-wip-selftests-v1-0-ba15a1fe1b0d@kernel.org> In-Reply-To: <20231129-wip-selftests-v1-0-ba15a1fe1b0d@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=1701271499; l=5281; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=cc0b1jiuNKRXpLCKlecakBm8q8bu4sRt8EzldFhVXEg=; b=s/G95xyyW0nb0zcopdvpLLf34B8+2cViUddub6Sm8ZpAJ8SZV9dQGN4Q8b8B6X1vmzjqn9E/u C3hARQugD3BBBvLb5+wTmL8/YyUyj4nUUQYyAAPdyH1FjyBEBuAish5 X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Wed, 29 Nov 2023 07:26:32 -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 Signed-off-by: Benjamin Tissoires --- 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 18961758e4aa..44a004ca69d1 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