From patchwork Mon Sep 15 10:46:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 308 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933269; bh=OJfb1VnkQJgWyl+X8EkTOYlizx53+astXtsOXvZvSa0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=QKKyu/2pEzLqyiBXrqqiuDaFU7+Dx5C7Z2YTqElt5ZEoHSi8kDKxArMvk+8SIQwW9 vLo3auHo3JuJbA3U5Gn5Uqx/QQkeaQxjz8qH6weygqRNHr1Hy9U40sjM3GUqWIoFBT xIX/G2KjnanBkKrZAHlik7f+OT21+GPYejyCJXXasRLusQh7znSVdVt9BtG+xmcd04 HMfP59eWtd6O3SdBgJxa7DGqLqkOGjdkff3tr3isMXEX0xLmpnd6Nlb3WioY8mP52l 7qxZaYNI+tFzuPkOR255zc5ajQtY4Y+xZdzlTxq9NTuXdCPORNwwhMkHFr5umX6l3e s2FzK/CWCyB7g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CDAE267BBB for ; Mon, 15 Sep 2025 04:47:49 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 4aqmqp1HPxqC for ; Mon, 15 Sep 2025 04:47:49 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933268; bh=OJfb1VnkQJgWyl+X8EkTOYlizx53+astXtsOXvZvSa0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=gzWqeqGFR44k8VLBOjSA+M8xXtkyBkReqhxWmLBDvJV75qjbRenkAjTxC+fRuVW30 fa5qQ6jQYUtD+g/gUcgmE4fFkUrGxqVsr0wmLrF/KL1mblMGwtMKFu+5/38AuUZbqH pCdKiX0U9dVNUlHirDyfVDW5UKz23ox4nWC3ZT+xVkBDu6zEr7foKHTEHccWWfT5TV Cw2Vl5lEsjwb90x2zSa8ypCJBBqF4sb8KW6iaQ2144HCtDtDrVqGXRxSO+BSnahL6B wdLtSLeAIrEA/N10kY2Y0sakOpnrnyZ3pAQwZ7iw9e89GZE5gd5S1Ijmd0oH+p0uRK aX4Hx6Hod6yJg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7C2A967B44 for ; Mon, 15 Sep 2025 04:47:48 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933265; bh=BwVJ6hSqTsoPbNUJLWZ5UwuGhPT+6fWDU1nzz8XZCmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QfFzn5IIM6WzPEDqmzeCbCTiyrTVKc0ch+lpeYMYKE/jrrgWQXtGVZZcjygp0xQ8w v1zWKbML03UY3UsY8aPtb+9q6cf/wnRRgJ0gjSUNZQSFxEOsZW4Sy1rmS1wmvlksBW iqHP5v8jsIKeaeVCR0ISK4aNXAU7uM9LaLt3fdxpko4tT3sTWxBj8Llbvcuwr5Iv/Y OQhelqWr6fblxVO0b2Zlm3oTUrVQWQTlwdUe0FeBjQY1aAsS5GkzbRyE9yJsTch7xG zkTT/nNgYnTD9VBxAIHCa9pUt/lzfgBo4lfcG8lKjoGGKtf6aYM7zMppVhRSLP2Ypa iMz6NE+iWoSVQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8E53467B04; Mon, 15 Sep 2025 04:47:45 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id x_B6QIyrpzkU; Mon, 15 Sep 2025 04:47:45 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933264; bh=ceEBMVUibKm/cuUv0wFH2n58GZf/8/JS4nNA2dl7U84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kdo12FsKIQmIcpo7wVrE96FS4o3ytx7YvKbOVgO+tLFhxrt+BUNW3ydL2lqDE2IK1 GAWZkiZpZ+gJ1RFFl9UQdG12Y7at+jBotVuVrDvVZL6Py+U5T0pr12GONbWbliC4bs BBaTF/JpRL2O5h91TRThj2yM3vYHJA+V618qWFtNMQuUxuHAWQnYjMe1eyfYcKMRGS 10zOJed+cJLpjodvuw3h/xbBQATmB6/pj8iteeUPzb7k1HGeT7WA/oFu71u0ivLoLX y+YwLyTbuE2q/V1Asww7aWaYDAaWwCUR6WKM+zRwptBo6OSFWzfwpy0xLIkfxxdvLJ UFCIpL3xqExyg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B9E8667A99; Mon, 15 Sep 2025 04:47:43 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 15 Sep 2025 04:46:50 -0600 Message-ID: <20250915104705.937780-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250915104705.937780-1-sjg@u-boot.org> References: <20250915104705.937780-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KOUEGV6WKTHZDGUXQGU7M7PNOU7454RT X-Message-ID-Hash: KOUEGV6WKTHZDGUXQGU7M7PNOU7454RT X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 09/17] sandbox: Provide a test for the mouse uclass List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Provide a few simple tests for two methods available in the mouse uclass. Signed-off-by: Simon Glass --- arch/sandbox/include/asm/test.h | 17 ++++++ drivers/input/sandbox_mouse.c | 49 +++++++++++++++++ test/dm/Makefile | 1 + test/dm/mouse.c | 96 +++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 test/dm/mouse.c diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 4df39fac1da..499db42804c 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -11,6 +11,7 @@ #include struct unit_test_state; +struct mouse_event; /* The sandbox driver always permits an I2C device with this address */ #define SANDBOX_I2C_TEST_ADDR 0x59 @@ -361,4 +362,20 @@ bool sandbox_sf_bootdev_enabled(void); */ void sandbox_sf_set_enable_bootdevs(bool enable); +/** + * sandbox_mouse_set_test_mode() - Enable/disable test mode for sandbox mouse + * + * @dev: Mouse device + * @test_mode: true to enable test mode, false to use SDL + */ +void sandbox_mouse_set_test_mode(struct udevice *dev, bool test_mode); + +/** + * sandbox_mouse_inject() - Inject a mouse event for testing + * + * @dev: Mouse device (must be in test mode) + * @event: Event to inject + */ +void sandbox_mouse_inject(struct udevice *dev, struct mouse_event *event); + #endif diff --git a/drivers/input/sandbox_mouse.c b/drivers/input/sandbox_mouse.c index 4aedf0fdf2d..ba271242b1a 100644 --- a/drivers/input/sandbox_mouse.c +++ b/drivers/input/sandbox_mouse.c @@ -8,11 +8,29 @@ #include #include +struct sandbox_mouse_priv { + bool test_mode; + struct mouse_event test_event; + bool test_event_pending; +}; + static int mouse_sandbox_get_event(struct udevice *dev, struct mouse_event *event) { + struct sandbox_mouse_priv *priv = dev_get_priv(dev); int ret; + /* If in test mode, return test event if pending */ + if (priv->test_mode) { + if (priv->test_event_pending) { + *event = priv->test_event; + priv->test_event_pending = false; + return 0; + } else { + return -EAGAIN; + } + } + ret = sandbox_sdl_get_mouse_event(event); return ret; @@ -27,9 +45,40 @@ static const struct udevice_id mouse_sandbox_ids[] = { { } }; +/** + * sandbox_mouse_set_test_mode() - Enable/disable test mode + * + * @dev: Mouse device + * @test_mode: true to enable test mode, false to use SDL + */ +void sandbox_mouse_set_test_mode(struct udevice *dev, bool test_mode) +{ + struct sandbox_mouse_priv *priv = dev_get_priv(dev); + + priv->test_mode = test_mode; + priv->test_event_pending = false; +} + +/** + * sandbox_mouse_inject() - Inject a mouse event for testing + * + * @dev: Mouse device (must be in test mode) + * @event: Event to inject + */ +void sandbox_mouse_inject(struct udevice *dev, struct mouse_event *event) +{ + struct sandbox_mouse_priv *priv = dev_get_priv(dev); + + if (priv->test_mode) { + priv->test_event = *event; + priv->test_event_pending = true; + } +} + U_BOOT_DRIVER(mouse_sandbox) = { .name = "mouse_sandbox", .id = UCLASS_MOUSE, .of_match = mouse_sandbox_ids, .ops = &mouse_sandbox_ops, + .priv_auto = sizeof(struct sandbox_mouse_priv), }; diff --git a/test/dm/Makefile b/test/dm/Makefile index eab78d3ac4a..b38de3e12d0 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -68,6 +68,7 @@ obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o obj-$(CONFIG_MEMORY) += memory.o obj-$(CONFIG_MISC) += misc.o obj-$(CONFIG_DM_MMC) += mmc.o +obj-$(CONFIG_MOUSE) += mouse.o obj-$(CONFIG_CMD_MUX) += mux-cmd.o obj-$(CONFIG_MULTIPLEXER) += mux-emul.o obj-$(CONFIG_MUX_MMIO) += mux-mmio.o diff --git a/test/dm/mouse.c b/test/dm/mouse.c new file mode 100644 index 00000000000..f9c2e88c43a --- /dev/null +++ b/test/dm/mouse.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for the driver model mouse API + * + * Copyright 2025 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include + +static int dm_test_mouse_basic(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_first_device_err(UCLASS_MOUSE, &dev)); + + /* put mouse in test mode */ + sandbox_mouse_set_test_mode(dev, true); + + return 0; +} +DM_TEST(dm_test_mouse_basic, UTF_SCAN_PDATA | UTF_SCAN_FDT); + +static int dm_test_mouse_motion(struct unit_test_state *uts) +{ + struct udevice *dev; + struct mouse_event event, inject; + + ut_assertok(uclass_first_device_err(UCLASS_MOUSE, &dev)); + + /* put mouse in test mode */ + sandbox_mouse_set_test_mode(dev, true); + + /* inject a motion event */ + inject.type = MOUSE_EV_MOTION; + inject.motion.state = 0; + inject.motion.x = 100; + inject.motion.y = 200; + inject.motion.xrel = 10; + inject.motion.yrel = 20; + + sandbox_mouse_inject(dev, &inject); + + /* get and verify the event */ + ut_assertok(mouse_get_event(dev, &event)); + ut_asserteq(MOUSE_EV_MOTION, event.type); + ut_asserteq(0, event.motion.state); + ut_asserteq(100, event.motion.x); + ut_asserteq(200, event.motion.y); + ut_asserteq(10, event.motion.xrel); + ut_asserteq(20, event.motion.yrel); + + /* verify no more events are pending */ + ut_asserteq(-EAGAIN, mouse_get_event(dev, &event)); + + return 0; +} +DM_TEST(dm_test_mouse_motion, UTF_SCAN_PDATA | UTF_SCAN_FDT); + +static int dm_test_mouse_button(struct unit_test_state *uts) +{ + struct udevice *dev; + struct mouse_event event, inject; + + ut_assertok(uclass_first_device_err(UCLASS_MOUSE, &dev)); + + /* put mouse in test mode */ + sandbox_mouse_set_test_mode(dev, true); + + /* inject a button press event */ + inject.type = MOUSE_EV_BUTTON; + inject.button.button = BUTTON_LEFT; + inject.button.press_state = BUTTON_PRESSED; + inject.button.clicks = 1; + inject.button.x = 150; + inject.button.y = 250; + + sandbox_mouse_inject(dev, &inject); + + /* get and verify the event */ + ut_assertok(mouse_get_event(dev, &event)); + ut_asserteq(MOUSE_EV_BUTTON, event.type); + ut_asserteq(BUTTON_LEFT, event.button.button); + ut_asserteq(BUTTON_PRESSED, event.button.press_state); + ut_asserteq(1, event.button.clicks); + ut_asserteq(150, event.button.x); + ut_asserteq(250, event.button.y); + + return 0; +} +DM_TEST(dm_test_mouse_button, UTF_SCAN_PDATA | UTF_SCAN_FDT);