]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
pytest: add sandbox test for "extension" command
authorKory Maincent <kory.maincent@bootlin.com>
Tue, 4 May 2021 17:31:23 +0000 (19:31 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 13 May 2021 17:09:09 +0000 (13:09 -0400)
This commit extends the sandbox to implement a dummy
extension_board_scan() function and enables the extension command in
the sandbox configuration. It then adds a test that checks the proper
functionality of the extension command by applying two Device Tree
overlays to the sandbox Device Tree.

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
[trini: Limit to running on sandbox]
Signed-off-by: Tom Rini <trini@konsulko.com>
arch/Kconfig
arch/sandbox/dts/Makefile
arch/sandbox/dts/overlay0.dts [new file with mode: 0644]
arch/sandbox/dts/overlay1.dts [new file with mode: 0644]
board/sandbox/sandbox.c
test/py/tests/test_extension.py [new file with mode: 0644]

index e61a7528bafa89e535aeedc08849e3d97ae54a12..6c4b81a4866f88129877b0a0fa0c50891d801314 100644 (file)
@@ -121,6 +121,7 @@ config SANDBOX
        select SUPPORT_OF_CONTROL
        select SYSRESET_CMD_POWEROFF
        select IRQ
+       select SUPPORT_EXTENSION_SCAN
        imply BITREVERSE
        select BLOBLIST
        imply CMD_DM
@@ -165,6 +166,7 @@ config SANDBOX
        imply BOOTARGS_SUBST
        imply PHY_FIXED
        imply DM_DSA
+       imply CMD_EXTENSION
 
 config SH
        bool "SuperH architecture"
index d231dc2877301c473dc89820a9b938b31d89a702..3e5dc67d53e515148aa62a859b91f23617009430 100644 (file)
@@ -6,6 +6,7 @@ else
 dtb-$(CONFIG_SANDBOX) += sandbox.dtb
 endif
 dtb-$(CONFIG_UT_DM) += test.dtb
+dtb-$(CONFIG_CMD_EXTENSION) += overlay0.dtbo overlay1.dtbo
 
 targets += $(dtb-y)
 
diff --git a/arch/sandbox/dts/overlay0.dts b/arch/sandbox/dts/overlay0.dts
new file mode 100644 (file)
index 0000000..70c6cf7
--- /dev/null
@@ -0,0 +1,9 @@
+/dts-v1/;
+/plugin/;
+
+&{/buttons} {
+       btn3 {
+               gpios = <&gpio_a 5 0>;
+               label = "button3";
+       };
+};
diff --git a/arch/sandbox/dts/overlay1.dts b/arch/sandbox/dts/overlay1.dts
new file mode 100644 (file)
index 0000000..51621b3
--- /dev/null
@@ -0,0 +1,9 @@
+/dts-v1/;
+/plugin/;
+
+&{/buttons} {
+       btn4 {
+               gpios = <&gpio_a 5 0>;
+               label = "button4";
+       };
+};
index 902b99ed500562950aebb3751fb0352bc3359ba2..dcd73451a34876d744f7a77353a12bddd8989c63 100644 (file)
@@ -14,6 +14,9 @@
 #include <asm/global_data.h>
 #include <asm/test.h>
 #include <asm/u-boot-sandbox.h>
+#include <malloc.h>
+
+#include <extension_board.h>
 
 /*
  * Pointer to initial global data area
@@ -79,6 +82,26 @@ int ft_board_setup(void *fdt, struct bd_info *bd)
        return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
 }
 
+#ifdef CONFIG_CMD_EXTENSION
+int extension_board_scan(struct list_head *extension_list)
+{
+       struct extension *extension;
+       int i;
+
+       for (i = 0; i < 2; i++) {
+               extension = calloc(1, sizeof(struct extension));
+               snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i);
+               snprintf(extension->name, sizeof(extension->name), "extension board %d", i);
+               snprintf(extension->owner, sizeof(extension->owner), "sandbox");
+               snprintf(extension->version, sizeof(extension->version), "1.1");
+               snprintf(extension->other, sizeof(extension->other), "Fictionnal extension board");
+               list_add_tail(&extension->list, extension_list);
+       }
+
+       return i;
+}
+#endif
+
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
diff --git a/test/py/tests/test_extension.py b/test/py/tests/test_extension.py
new file mode 100644 (file)
index 0000000..267cf2f
--- /dev/null
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2020
+# Author: Kory Maincent <kory.maincent@bootlin.com>
+
+# Test U-Boot's "extension" commands.
+
+import os
+import pytest
+import u_boot_utils
+
+overlay_addr = 0x1000
+
+SANDBOX_DTB='arch/sandbox/dts/sandbox.dtb'
+OVERLAY_DIR='arch/sandbox/dts/'
+
+def load_dtb(u_boot_console):
+    u_boot_console.log.action('Loading devicetree to RAM...')
+    u_boot_console.run_command('host load hostfs - $fdt_addr_r %s' % (os.path.join(u_boot_console.config.build_dir, SANDBOX_DTB)))
+    u_boot_console.run_command('fdt addr $fdt_addr_r')
+
+@pytest.mark.buildconfigspec('cmd_fdt')
+@pytest.mark.boardspec('sandbox')
+def test_extension(u_boot_console):
+    """Test the 'extension' command."""
+
+    load_dtb(u_boot_console)
+
+    output = u_boot_console.run_command('extension list')
+    assert('No extension' in output)
+
+    output = u_boot_console.run_command('extension scan')
+    assert output == 'Found 2 extension board(s).'
+
+    output = u_boot_console.run_command('extension list')
+    assert('overlay0.dtbo' in output)
+    assert('overlay1.dtbo' in output)
+
+    u_boot_console.run_command_list([
+        'setenv extension_overlay_addr %s' % (overlay_addr),
+        'setenv extension_overlay_cmd \'host load hostfs - ${extension_overlay_addr} %s${extension_overlay_name}\'' % (os.path.join(u_boot_console.config.build_dir, OVERLAY_DIR))])
+
+    output = u_boot_console.run_command('extension apply 0')
+    assert('bytes read' in output)
+
+    output = u_boot_console.run_command('fdt print')
+    assert('button3' in output)
+
+    output = u_boot_console.run_command('extension apply all')
+    assert('bytes read' in output)
+
+    output = u_boot_console.run_command('fdt print')
+    assert('button4' in output)
+