aboutsummaryrefslogtreecommitdiff
path: root/test/py
diff options
context:
space:
mode:
Diffstat (limited to 'test/py')
-rw-r--r--test/py/multiplexed_log.py5
-rw-r--r--test/py/tests/test_of_migrate.py108
-rw-r--r--test/py/tests/test_ofplatdata.py8
-rw-r--r--test/py/u_boot_utils.py5
4 files changed, 118 insertions, 8 deletions
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index 5e79075f2e..63237594bb 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -111,7 +111,7 @@ class RunAndLog(object):
"""Clean up any resources managed by this object."""
pass
- def run(self, cmd, cwd=None, ignore_errors=False, stdin=None):
+ def run(self, cmd, cwd=None, ignore_errors=False, stdin=None, env=None):
"""Run a command as a sub-process, and log the results.
The output is available at self.output which can be useful if there is
@@ -126,6 +126,7 @@ class RunAndLog(object):
or exits with an error code, otherwise an exception will be
raised if such problems occur.
stdin: Input string to pass to the command as stdin (or None)
+ env: Environment to use, or None to use the current one
Returns:
The output as a string.
@@ -139,7 +140,7 @@ class RunAndLog(object):
try:
p = subprocess.Popen(cmd, cwd=cwd,
stdin=subprocess.PIPE if stdin else None,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
(stdout, stderr) = p.communicate(input=stdin)
if stdout is not None:
stdout = stdout.decode('utf-8')
diff --git a/test/py/tests/test_of_migrate.py b/test/py/tests/test_of_migrate.py
new file mode 100644
index 0000000000..910f7c0551
--- /dev/null
+++ b/test/py/tests/test_of_migrate.py
@@ -0,0 +1,108 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2023 Google LLC
+# Written by Simon Glass <sjg@chromium.org>
+
+"""Test handling of unmigrated u-boot,dm- tags"""
+
+import os
+import pytest
+
+import u_boot_utils as util
+
+# This is needed for Azure, since the default '..' directory is not writeable
+TMPDIR1 = '/tmp/test_no_migrate'
+TMPDIR2 = '/tmp/test_no_migrate_spl'
+TMPDIR3 = '/tmp/test_migrate'
+
+def build_for_migrate(cons, replace_pair, board, tmpdir, disable_migrate=True):
+ """Build an updated U-Boot with a slightly modified device tree
+
+ Args:
+ cons (ConsoleBase): U-Boot console
+ replace_pair (tuple):
+ String to find
+ String to replace it with
+ board (str): Board to build
+ tmpdir (str): Temporary directory to use
+ disable_migrate (bool): True to disable CONFIG_OF_TAG_MIGRATE in build
+ """
+ srcdir = cons.config.source_dir
+ build_dir = cons.config.build_dir
+
+ # Get the source for the existing dts
+ dt_dir = os.path.join(build_dir, 'arch', 'sandbox', 'dts')
+ orig_fname = os.path.join(dt_dir, 'sandbox.dtb')
+ out_dts = os.path.join(dt_dir, 'sandbox_out.dts')
+ util.run_and_log(cons, ['dtc', orig_fname, '-I', 'dtb', '-O', 'dts',
+ '-o', out_dts])
+
+ # Update it to use an old tag
+ with open(out_dts) as inf:
+ data = inf.read()
+ data = data.replace(*replace_pair)
+
+ dts_fname = os.path.join(dt_dir, 'sandbox_oldtag.dts')
+ with open(dts_fname, 'w') as outf:
+ print(data, file=outf)
+ dtb_fname = os.path.join(dt_dir, 'sandbox_oldtag.dtb')
+ util.run_and_log(cons, ['dtc', dts_fname, '-o', dtb_fname])
+
+ migrate = ['-a', '~CONFIG_OF_TAG_MIGRATE'] if disable_migrate else []
+
+ # Build sandbox with this new dtb, turning off OF_TAG_MIGRATE
+ env = dict(os.environ)
+ env['EXT_DTB'] = dtb_fname
+ env['DEVICE_TREE'] = 'sandbox_new'
+ env['NO_LTO'] = '1' # Speed up build
+ out = util.run_and_log(
+ cons, ['./tools/buildman/buildman', '-m', '--board', board,
+ *migrate, '-w', '-o', tmpdir], ignore_errors=True, env=env)
+ return out
+
+@pytest.mark.slow
+@pytest.mark.boardspec('sandbox')
+def test_of_no_migrate(u_boot_console):
+ """Test sandbox with old boot phase tags like u-boot,dm-pre-proper"""
+ cons = u_boot_console
+
+ build_for_migrate(cons, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
+ 'sandbox', TMPDIR1)
+
+ # It should fail to run, since the lcd device will not be bound before
+ # relocation. so won't get its frame-buffer memory
+ out = util.run_and_log(
+ cons, [os.path.join(TMPDIR1, 'u-boot'), '-D', '-c', 'help'],
+ ignore_errors=True)
+ assert "Video device 'lcd' cannot allocate frame buffer memory" in out
+
+
+@pytest.mark.slow
+@pytest.mark.boardspec('sandbox_spl')
+@pytest.mark.boardspec('spl_of_platdata_inst')
+@pytest.mark.boardspec('!sandbox_tpl')
+def test_of_no_migrate_spl(u_boot_console):
+ """Test sandbox with old boot phase tags like u-boot,dm-spl"""
+ cons = u_boot_console
+
+ out = build_for_migrate(cons, ['bootph-pre-ram', 'u-boot,dm-spl'],
+ 'sandbox_spl', TMPDIR2)
+
+ # It should fail to build, since the SPL DT will not include 'spl-test'
+ # node, among others
+ assert "undefined type ‘struct dtd_sandbox_spl_test’" in out
+
+
+@pytest.mark.slow
+@pytest.mark.boardspec('sandbox')
+def test_of_migrate(u_boot_console):
+ """Test sandbox shows a message when tags were migrated"""
+ cons = u_boot_console
+
+ build_for_migrate(cons, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
+ 'sandbox', TMPDIR3, disable_migrate=False)
+
+ # It should show a migration message
+ out = util.run_and_log(
+ cons, [os.path.join(TMPDIR3, 'u-boot'), '-D', '-c', 'help'],
+ ignore_errors=True)
+ assert "Warning: Device tree includes old 'u-boot,dm-' tags" in out
diff --git a/test/py/tests/test_ofplatdata.py b/test/py/tests/test_ofplatdata.py
index e9cce4daf4..51a188454f 100644
--- a/test/py/tests/test_ofplatdata.py
+++ b/test/py/tests/test_ofplatdata.py
@@ -13,10 +13,10 @@ def test_spl_devicetree(u_boot_console):
fdtgrep = cons.config.build_dir + '/tools/fdtgrep'
output = util.run_and_log(cons, [fdtgrep, '-l', dtb])
- assert "u-boot,dm-pre-reloc" not in output
- assert "u-boot,dm-pre-proper" not in output
- assert "u-boot,dm-spl" not in output
- assert "u-boot,dm-tpl" not in output
+ assert "bootph-all" not in output
+ assert "bootph-some-ram" not in output
+ assert "bootph-pre-ram" not in output
+ assert "bootph-pre-sram" not in output
assert "spl-test5" not in output
assert "spl-test6" not in output
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
index c4fc23aeda..9e161fbc23 100644
--- a/test/py/u_boot_utils.py
+++ b/test/py/u_boot_utils.py
@@ -157,7 +157,7 @@ def wait_until_file_open_fails(fn, ignore_errors):
return
raise Exception('File can still be opened')
-def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
+def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None, env=None):
"""Run a command and log its output.
Args:
@@ -170,6 +170,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
an error code, otherwise an exception will be raised if such
problems occur.
stdin: Input string to pass to the command as stdin (or None)
+ env: Environment to use, or None to use the current one
Returns:
The output as a string.
@@ -177,7 +178,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
if isinstance(cmd, str):
cmd = cmd.split()
runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
- output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin)
+ output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env)
runner.close()
return output