diff mbox series

[v2,1/4] test: Add test for source command

Message ID 20221020192404.2500251-2-sean.anderson@seco.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series cmd: source: Support specifying config name | expand

Commit Message

Sean Anderson Oct. 20, 2022, 7:24 p.m. UTC
This adds a basic test for FIT image handling by the source command.
It's a python test becase we need to run mkimage.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

Changes in v2:
- New

 test/py/tests/source.its     | 43 ++++++++++++++++++++++++++++++++++++
 test/py/tests/test_source.py | 28 +++++++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 test/py/tests/source.its
 create mode 100644 test/py/tests/test_source.py

Comments

Simon Glass Oct. 21, 2022, 8:17 p.m. UTC | #1
On Thu, 20 Oct 2022 at 13:24, Sean Anderson <sean.anderson@seco.com> wrote:
>
> This adds a basic test for FIT image handling by the source command.
> It's a python test becase we need to run mkimage.
>
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> ---
>
> Changes in v2:
> - New
>
>  test/py/tests/source.its     | 43 ++++++++++++++++++++++++++++++++++++
>  test/py/tests/test_source.py | 28 +++++++++++++++++++++++
>  2 files changed, 71 insertions(+)
>  create mode 100644 test/py/tests/source.its
>  create mode 100644 test/py/tests/test_source.py

Reviewed-by: Simon Glass <sjg@chromium.org>

Please use single quotes in Python
Tom Rini Nov. 2, 2022, 5:57 p.m. UTC | #2
On Thu, Oct 20, 2022 at 03:24:01PM -0400, Sean Anderson wrote:

> This adds a basic test for FIT image handling by the source command.
> It's a python test becase we need to run mkimage.
> 
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> ---
> 
> Changes in v2:
> - New

The series needs to be rebased on to master now that Simon's VPL series
has been merged, sorry.
diff mbox series

Patch

diff --git a/test/py/tests/source.its b/test/py/tests/source.its
new file mode 100644
index 00000000000..3c62f777f17
--- /dev/null
+++ b/test/py/tests/source.its
@@ -0,0 +1,43 @@ 
+/dts-v1/;
+
+/ {
+    description = "FIT image to test the source command";
+    #address-cells = <1>;
+
+    images {
+        default = "script-1";
+
+        script-1 {
+            data = "echo 1";
+            type = "script";
+            arch = "sandbox";
+            compression = "none";
+        };
+
+        script-2 {
+            data = "echo 2";
+            type = "script";
+            arch = "sandbox";
+            compression = "none";
+        };
+
+        not-a-script {
+            data = "echo 3";
+            type = "kernel";
+            arch = "sandbox";
+            compression = "none";
+        };
+    };
+
+    configurations {
+        default = "conf-2";
+
+        conf-1 {
+            script = "script-1";
+        };
+
+        conf-2 {
+            script = "script-2";
+        };
+    };
+};
diff --git a/test/py/tests/test_source.py b/test/py/tests/test_source.py
new file mode 100644
index 00000000000..85751ee6f76
--- /dev/null
+++ b/test/py/tests/test_source.py
@@ -0,0 +1,28 @@ 
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022 Sean Anderson <sean.anderson@seco.com>
+
+import os
+import pytest
+import u_boot_utils as util
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_echo')
+@pytest.mark.buildconfigspec('cmd_source')
+@pytest.mark.buildconfigspec('fit')
+def test_source(u_boot_console):
+    # Compile our test script image
+    cons = u_boot_console
+    mkimage = os.path.join(cons.config.build_dir, "tools/mkimage")
+    its = os.path.join(cons.config.source_dir, "test/py/tests/source.its")
+    fit = os.path.join(cons.config.build_dir, "source.itb")
+    util.run_and_log(cons, (mkimage, '-f', its, fit))
+    cons.run_command(f"host load hostfs - $loadaddr {fit}")
+
+    assert "1" in cons.run_command("source")
+    assert "1" in cons.run_command("source :script-1")
+    assert "2" in cons.run_command("source :script-2")
+    assert "Fail" in cons.run_command("source :not-a-script || echo Fail")
+
+    cons.run_command("fdt addr $loadaddr")
+    cons.run_command("fdt rm /images default")
+    assert "Fail" in cons.run_command("source || echo Fail")