From patchwork Wed Feb 14 17:03:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 772671 Delivered-To: patch@linaro.org Received: by 2002:adf:9dc2:0:b0:33b:4db1:f5b3 with SMTP id q2csp411977wre; Wed, 14 Feb 2024 09:04:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVuu3xoERq54lh36sXHRS++BQcgw3LU1qNdVhVLakLg1zNNuGZN3Evs5yEGZo6sft9JfioF5LaEmPgexVeX8g7a X-Google-Smtp-Source: AGHT+IHNt1S+1XhxeGXVLYMthL8RiksrLZM6INm2WZ3jtmwOW8Y/dkdDWk8KBZ3xQHmkYmMjVUo4 X-Received: by 2002:aa7:c3c9:0:b0:55f:fdd4:437b with SMTP id l9-20020aa7c3c9000000b0055ffdd4437bmr2774851edr.0.1707930275492; Wed, 14 Feb 2024 09:04:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707930275; cv=none; d=google.com; s=arc-20160816; b=obJr2NmqD0n5+Ll6ljOcpm51yG7ALlzHmqRz6xeEkglUlchEfRrjota8+jg9F9DJOP 3hJL9RReWeuFMkjgbHV5IWDk7DYTfu2z/ydpxna+qczOLaGsRl1wMkgP5bwFEbcsmFhK RCWB/ppJMeUlTonVD8tqlrw8L0nUJZ4eb1kLoYElc8JalTMgN3waFbOuMLVpiISv+WjH 6k371lzjlyfpUiHVigBYHGGQ55wFHXaCSdNGDUNcpBeWy+8RXjVfA1G64lFim3z+DX5e vkaa0N4pgeHkXAlxMmwoO7dA/ykfni7ZJ+R9thUv0NG2B6jDY6kl0TfBnM+vKjpCdnwn TnTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=yhpMDsIC09JdO7QpMYChoW4F4CcLj2AGrV/8yzoMvMg=; fh=qcClaNJRx1BZlXJ1/tMac7q/OkfaGwgLZrUjUhbcbds=; b=gDCscpyl5TW1ufRZM8huttrlbF5uRAV3d5euM0L6bEE1mzHQ54w5HfRFj7n+Ddwpfe 1WD+bf0ExBMgmhQHNCDcko4Xgv4XZjwt5Xor1zGHqeNNq9evCUhDHdmXUO7HC95NQlvI u8CFT32VzLmLZc/0lZWIUexH9JIeqzBj1CbrIf8Lj6dFT/OojeeJP0pgBnaDIXsK+tov LS015Htadxdama1VeNtyHT8bXl5LYt5XH65BBxQvKpN5a4ynav5eI3CfivYMKyfydoLb qcqDApke8C9rRgEfO7eeA1rLy92eGmFpsYq/pTyWVNZkFcIMKNcBR+R8m39VnBMQ6CDU W9Ag==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=niRoNMaQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=1; AJvYcCWyJpLB3vzx+R8kmIXNhZQEJPEUhOAbHcoeOp5KuZ4PXeFeNowgq5dSDNVNcr5bv7JGN/rLQoF5hlgAR9ryF9YjkHlfHCM0KxwhSARxQK6CobL9Fc1nOlv/yFrc6NLUkYMCjQceqsa/r6E5wglQPFiHGokan3SF8/VyGHIpSN0pPeZGSXUoDPzLbatd2UWrVPevwxGtm8YMNkpqgeHxmGgHN5FNWbsHN8lZXsvF9rQ8bk8vIbXhPgAQzE0DmakV4tZFyc39s8OVY8IJggOUkElwo63KMeHQD1aiSFuA5GlgUX2do3TThV9CbT3vFp96ZfFwk+3d56T2dqVXUJScaZZ80pPP/fjl+nc6UVazovOgbsYW+Udad1rkt7wbyNouIbfR6cGqzAK0gKCk38pfWWDDdhiTDiULqzyEvUgpZNZTQ2liSkn4gb3JVgrmKzLxwDL8w/75yTYTbjr0nAX89A8ExySIqlQYondPR/68agtFisNS62aO74ahDySIEttdW0GUjvwcqgbRXyZ4porgmeCMJW/sCSMKdBmi4S4tFo9OGME9V++gA44LdVzN6LBICI/PCIQ0AIqrLbR9byVXsTb2254SDJN8eIGxE/3XMWz2sKw1bvZswV5pvtKNlOFPItAT4AM6xCOFLDmJ8kj8ftVKHtzS6ifSKQRtW7DwFP9kH6ZYT65kz74idlpPnNj137zKoGskg6GHIc79+TFieWVN7oWdnjdpebwkERkC4dAcyZXz9y7ObMKTFcA4DoTBF5GD/4I0nBWFPuOPgg7enTI3AucAw/8hJo2UEzL0cKnVluOhgZeI1J+1X9BwAQf6NTa448xF+J1cwVYyyq09s5etxa5VQYN7CKKoa3WdjTwiSMU3APLUPIohZf3yGU1GQOumdjtoMQNEZNdSLMMmTUEmaQusGiueh4ojxG5bS3gXvbRMPpZlKnNGZbueN4OBybKW50 7z/NOhuVkAKtS6k6wJ8c6rWNoUbDb/bxNvwHtAKlazGzOHbHmexLP0 Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id t16-20020a50ab50000000b005612b46f8d3si4884741edc.488.2024.02.14.09.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:04:35 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=niRoNMaQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 165BF87CFC; Wed, 14 Feb 2024 18:04:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="niRoNMaQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E675587D58; Wed, 14 Feb 2024 18:04:14 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D407C87CEC for ; Wed, 14 Feb 2024 18:04:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=caleb.connolly@linaro.org Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2d1094b5568so25493071fa.1 for ; Wed, 14 Feb 2024 09:04:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707930243; x=1708535043; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yhpMDsIC09JdO7QpMYChoW4F4CcLj2AGrV/8yzoMvMg=; b=niRoNMaQbYs0O+1jH7ruSkagmWR3+m5yW4fQvBDQ4g9tn8U1jDglRy3nea8fso3NuV M+/jYF5ZAxZ8U7+5z/RFPlooPi1qlowInmSgoqFjLU8RGI4mMyeBKw4r3PHaF3eZB4X6 xOObCU/tM41Zj1AgFOwDMrm4Mw11P4v8YS7aabvwRSOSx0RxmLDbIg7WbdBT17WixDP+ M1FukVQaH3e3f2NGhghlw3lJ23y3FLyX+b7GfpGWOICdzzkGgsaoczQ5yi5vVHtNaSWi SABrYSAaW5i+5nKPkMPUHMnUyH/iqJ1NnNE0n3ORDRYF81Gysc3S4D7+POaklwvV4c2L SitA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707930243; x=1708535043; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yhpMDsIC09JdO7QpMYChoW4F4CcLj2AGrV/8yzoMvMg=; b=g3tRej0LzzA5RBEawRO3ur5CgZzK7GvdZTsybNt4JCDG/uxYXUM8yfzJL1FyOPZp4w EA8UyMdYsSjbs2/49P1fFtK4GfsT4f/1NYaBkrVPwVWDEtMbgApvz1OsJqMPRmPstEnj k62yhYd9immTFKjlp3B94f61+YV6ljFCra4CpwLe+sKww9Tx1uZBUoYo31f12k6/GAyi gjeDJ9zAR7SWHO8o3ksB22utSNyMa1yARgFub0f9rJKrnPe/ra8FdiTKQlncOQfbY90Y 4IsrA/XtlzsJQWIYmjWKPk5U3vFYXMEiNdP5ywRoSUEzzbuh0E4Xvv79AAt+LtILduay mAPQ== X-Gm-Message-State: AOJu0YzFXXXUWmjKbUZSh3JUNWkODEC9K5xcN2SWRFFvKtc9bfhOrDin WEevSAwcjxvEXWLzuzmMNBye+lFJQE+sMo0gIH76UrwEaObbMxxgz/JyvAj9CX8= X-Received: by 2002:a2e:7d0f:0:b0:2d0:9fb2:2c79 with SMTP id y15-20020a2e7d0f000000b002d09fb22c79mr2704868ljc.3.1707930243027; Wed, 14 Feb 2024 09:04:03 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVtUiNBOy4obkMIYPMjD1wHa8unM3vfCfiD0SIbRjckxZ+DX6JSjyPM2K9aoCn5wEOpnLojv/WXzZ/+oJyPb141B2MN40d8a/xmsiVaRO6/fnZ5FJ8BSHD9KDhQ Received: from lion.caleb.rex.connolly.tech (host-92-17-96-232.as13285.net. [92.17.96.232]) by smtp.gmail.com with ESMTPSA id ay31-20020a05600c1e1f00b00410232ffb2csm2565063wmb.25.2024.02.14.09.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:04:02 -0800 (PST) From: Caleb Connolly To: Tom Rini , Simon Glass Cc: u-boot@lists.denx.de, Caleb Connolly Subject: [PATCH] test: dm: add button_cmd test Date: Wed, 14 Feb 2024 17:03:46 +0000 Message-ID: <20240214170357.4091708-1-caleb.connolly@linaro.org> X-Mailer: git-send-email 2.43.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add a test for the button_cmd feature. This validates that commands can be mapped to two buttons, that the correct command runs based on which button is pressed, that only 1 command is run, and that no command runs if button_cmd_0_name is wrong or unset. CONFIG_BUTTON is now enabled automatically and was removed when running save_defconfig. Signed-off-by: Caleb Connolly --- configs/sandbox_defconfig | 2 +- test/dm/button.c | 96 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index a8df5e635b26..93b52f2de5cf 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -10,6 +10,7 @@ CONFIG_PCI=y CONFIG_DEBUG_UART=y CONFIG_SYS_MEMTEST_START=0x00100000 CONFIG_SYS_MEMTEST_END=0x00101000 +CONFIG_BUTTON_CMD=y CONFIG_FIT=y CONFIG_FIT_RSASSA_PSS=y CONFIG_FIT_CIPHER=y @@ -166,7 +167,6 @@ CONFIG_DM_BOOTCOUNT=y CONFIG_DM_BOOTCOUNT_RTC=y CONFIG_DM_BOOTCOUNT_I2C_EEPROM=y CONFIG_DM_BOOTCOUNT_SYSCON=y -CONFIG_BUTTON=y CONFIG_BUTTON_ADC=y CONFIG_BUTTON_GPIO=y CONFIG_CLK=y diff --git a/test/dm/button.c b/test/dm/button.c index 3318668df25a..830d96fbef34 100644 --- a/test/dm/button.c +++ b/test/dm/button.c @@ -131,3 +131,99 @@ static int dm_test_button_keys_adc(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_button_keys_adc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +/* Test of the button uclass using the button_gpio driver */ +static int dm_test_button_cmd(struct unit_test_state *uts) +{ + struct udevice *btn1_dev, *btn2_dev, *gpio; + const char *envstr; + +#define BTN1_GPIO 3 +#define BTN2_GPIO 4 +#define BTN1_PASS_VAR "test_button_cmds_0" +#define BTN2_PASS_VAR "test_button_cmds_1" + + /* + * Buttons 1 and 2 are connected to gpio_a gpios 3 and 4 respectively. + * set the GPIOs to known values and then check that the appropriate + * commands are run when invoking process_button_cmds(). + */ + ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &btn1_dev)); + ut_assertok(uclass_get_device(UCLASS_BUTTON, 2, &btn2_dev)); + ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio)); + + /* + * Map a command to button 1 and check that it process_button_cmds() + * runs it if called with button 1 pressed. + */ + ut_assertok(env_set("button_cmd_0_name", "button1")); + ut_assertok(env_set("button_cmd_0", "env set " BTN1_PASS_VAR " PASS")); + ut_assertok(sandbox_gpio_set_value(gpio, BTN1_GPIO, 1)); + /* Sanity check that the button is actually pressed */ + ut_asserteq(BUTTON_ON, button_get_state(btn1_dev)); + process_button_cmds(); + ut_assertnonnull((envstr = env_get(BTN1_PASS_VAR))); + ut_asserteq_str(envstr, "PASS"); + + /* Clear result */ + ut_assertok(env_set(BTN1_PASS_VAR, NULL)); + + /* + * Map a command for button 2, press it, check that only the command + * for button 1 runs because it comes first and is also pressed. + */ + ut_assertok(env_set("button_cmd_1_name", "button2")); + ut_assertok(env_set("button_cmd_1", "env set " BTN2_PASS_VAR " PASS")); + ut_assertok(sandbox_gpio_set_value(gpio, BTN2_GPIO, 1)); + ut_asserteq(BUTTON_ON, button_get_state(btn2_dev)); + process_button_cmds(); + /* Check that button 1 triggered again */ + ut_assertnonnull((envstr = env_get(BTN1_PASS_VAR))); + ut_asserteq_str(envstr, "PASS"); + /* And button 2 didn't */ + ut_assertnull(env_get(BTN2_PASS_VAR)); + + /* Clear result */ + ut_assertok(env_set(BTN1_PASS_VAR, NULL)); + + /* + * Release button 1 and check that the command for button 2 is run + */ + ut_assertok(sandbox_gpio_set_value(gpio, BTN1_GPIO, 0)); + process_button_cmds(); + ut_assertnull(env_get(BTN1_PASS_VAR)); + /* Check that the command for button 2 ran */ + ut_assertnonnull((envstr = env_get(BTN2_PASS_VAR))); + ut_asserteq_str(envstr, "PASS"); + + /* Clear result */ + ut_assertok(env_set(BTN2_PASS_VAR, NULL)); + + /* + * Unset "button_cmd_0_name" and check that no commands run even + * with both buttons pressed. + */ + ut_assertok(env_set("button_cmd_0_name", NULL)); + /* Press button 1 (button 2 is already pressed )*/ + ut_assertok(sandbox_gpio_set_value(gpio, BTN1_GPIO, 1)); + ut_asserteq(BUTTON_ON, button_get_state(btn1_dev)); + process_button_cmds(); + ut_assertnull(env_get(BTN1_PASS_VAR)); + ut_assertnull(env_get(BTN2_PASS_VAR)); + + /* + * Check that no command is run if the button name is wrong. + */ + ut_assertok(env_set("button_cmd_0_name", "invalid_button")); + process_button_cmds(); + ut_assertnull(env_get(BTN1_PASS_VAR)); + ut_assertnull(env_get(BTN2_PASS_VAR)); + +#undef BTN1_PASS_VAR +#undef BTN2_PASS_VAR +#undef BTN1_GPIO +#undef BTN2_GPIO + + return 0; +} +DM_TEST(dm_test_button_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);