[Concept,12/19] test: py: Fix test_source breaking later tests

Message ID 20260314231618.338113-13-sjg@u-boot.org
State New
Headers
Series test: Fix pytest inter-test side effects |

Commit Message

Simon Glass March 14, 2026, 11:16 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

The source command's ':' and '#' variants use the global image_load_addr
variable, not the loadaddr env var. Prior tests (e.g. PXE) can change
image_load_addr via load commands, causing test_source to look for the
FIT at the wrong address. Fix this by explicitly setting loadaddr before
loading the FIT, which triggers the env callback that synchronises
image_load_addr.

Also restore the control FDT and clean up loadaddr at the end so that
later tests are not affected by the modified FDT pointer.

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

 test/py/tests/test_source.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Patch

diff --git a/test/py/tests/test_source.py b/test/py/tests/test_source.py
index 970d8c79869..4b9a12890c7 100644
--- a/test/py/tests/test_source.py
+++ b/test/py/tests/test_source.py
@@ -15,6 +15,12 @@  def test_source(ubman):
     its = os.path.join(ubman.config.source_dir, 'test/py/tests/source.its')
     fit = os.path.join(ubman.config.build_dir, 'source.itb')
     utils.run_and_log(ubman, (mkimage, '-f', its, fit))
+
+    # Set loadaddr to match CONFIG_SYS_LOAD_ADDR, in case a previous test
+    # (e.g. PXE) changed image_load_addr. The 'source :' and 'source #'
+    # variants use image_load_addr, which is synchronised via the loadaddr
+    # env-var callback.
+    ubman.run_command('setenv loadaddr 0')
     ubman.run_command(f'host load hostfs - $loadaddr {fit}')
 
     assert '2' in ubman.run_command('source')
@@ -34,3 +40,7 @@  def test_source(ubman):
     ubman.run_command('fdt rm /images default')
     assert 'Fail' in ubman.run_command('source || echo Fail')
     assert 'Fail' in ubman.run_command('source \\# || echo Fail')
+
+    # Restore the control FDT and clean up
+    ubman.run_command('fdt addr $fdtcontroladdr')
+    ubman.run_command('setenv loadaddr')