Skip to contentSkip to conversation

test: dm: add button_cmd test

PATCH Superseded Caleb Connolly 2 participants 2 messages Mar 5, 2024 – Mar 14, 2024

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 test: dm: add button_cmd test

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.

Additionally, fix a potential uninitialised variable use caught by these tests, the btn variable in get_button_cmd() is assumed to be null if button_get_by_label() fails, but it's actually used uninitialised in that case.

CONFIG_BUTTON is now enabled automatically and was removed when running save_defconfig.

Fixes e761035b6423 ("boot: add support for button commands")

---
Changes in v2:
- Explicitly assign btn as NULL in get_button_cmd(). This fixes a
bug where if the undefined variable is non-zero the
button_get_by_label() check would fail and result in invalid memory
being accessed.
- Enable CONFIG_BUTTON_CMD for sandbox64 as well as sandbox.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

---
 common/button_cmd.c         |  2 +-
 configs/sandbox64_defconfig |  2 +-
 configs/sandbox_defconfig   |  2 +-
 test/dm/button.c            | 96 +++++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+), 3 deletions(-)
common/button_cmd.c +1 -1
index b6a8434d6f29..8642c26735cc 100644
@@ -32,9 +32,9 @@ struct button_cmd {
  */
 static int get_button_cmd(int n, struct button_cmd *cmd)
 {
 	const char *cmd_str;
-	struct udevice *btn;
+	struct udevice *btn = NULL;
 	char buf[24];
 
 	snprintf(buf, sizeof(buf), "button_cmd_%d_name", n);
 	cmd->btn_name = env_get(buf);
configs/sandbox64_defconfig +1 -1
index d101cca6a738..a62faf772482 100644
@@ -10,8 +10,9 @@ CONFIG_PCI=y
 CONFIG_SANDBOX64=y
 CONFIG_DEBUG_UART=y
 CONFIG_SYS_MEMTEST_START=0x00100000
 CONFIG_SYS_MEMTEST_END=0x00101000
+CONFIG_BUTTON_CMD=y
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
@@ -122,9 +123,8 @@ CONFIG_SYS_ATA_STRIDE=4
 CONFIG_SYS_ATA_DATA_OFFSET=0
 CONFIG_SYS_ATA_REG_OFFSET=1
 CONFIG_SYS_ATA_ALT_OFFSET=2
 CONFIG_SYS_ATA_IDE0_OFFSET=0
-CONFIG_BUTTON=y
 CONFIG_BUTTON_ADC=y
 CONFIG_BUTTON_GPIO=y
 CONFIG_CLK=y
 CONFIG_CLK_COMPOSITE_CCF=y
configs/sandbox_defconfig +1 -1
index a8df5e635b26..93b52f2de5cf 100644
@@ -9,8 +9,9 @@ CONFIG_SYS_LOAD_ADDR=0x0
 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
 CONFIG_FIT_VERBOSE=y
@@ -165,9 +166,8 @@ CONFIG_BOOTCOUNT_LIMIT=y
 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
 CONFIG_CLK_COMPOSITE_CCF=y
test/dm/button.c +96 -0

100 lines not on this page · raw message

Signature · 1 line
2.44.0
#1 lore raw
Quoted 10 lines · Caleb Connolly

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.

Additionally, fix a potential uninitialised variable use caught by these tests, the btn variable in get_button_cmd() is assumed to be null if button_get_by_label() fails, but it's actually used uninitialised in that case.

Quoted 5 lines

CONFIG_BUTTON is now enabled automatically and was removed when running save_defconfig.

Fixes e761035b6423 ("boot: add support for button commands")

This still leads to CI failures:
https://source.denx.de/u-boot/u-boot/-/jobs/798332

Signature · 1 line
Tom