]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
test/py: move find_ram_base() into u_boot_utils
authorStephen Warren <swarren@nvidia.com>
Thu, 21 Jan 2016 23:05:30 +0000 (16:05 -0700)
committerSimon Glass <sjg@chromium.org>
Fri, 29 Jan 2016 04:01:23 +0000 (21:01 -0700)
find_ram_base() is a shared utility function, not a core part of the
U-Boot console interaction.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
test/py/tests/test_md.py
test/py/u_boot_console_base.py
test/py/u_boot_utils.py

index 94603c7df609efe9ab6d8e6b9825b2cf69ee38ea..32cce4f15c53342c2c8aa03f25fa3b812d226208 100644 (file)
@@ -4,13 +4,14 @@
 # SPDX-License-Identifier: GPL-2.0
 
 import pytest
+import u_boot_utils
 
 @pytest.mark.buildconfigspec('cmd_memory')
 def test_md(u_boot_console):
     '''Test that md reads memory as expected, and that memory can be modified
     using the mw command.'''
 
-    ram_base = u_boot_console.find_ram_base()
+    ram_base = u_boot_utils.find_ram_base(u_boot_console)
     addr = '%08x' % ram_base
     val = 'a5f09876'
     expected_response = addr + ': ' + val
@@ -26,7 +27,7 @@ def test_md_repeat(u_boot_console):
     '''Test command repeat (via executing an empty command) operates correctly
     for "md"; the command must repeat and dump an incrementing address.'''
 
-    ram_base = u_boot_console.find_ram_base()
+    ram_base = u_boot_utils.find_ram_base(u_boot_console)
     addr_base = '%08x' % ram_base
     words = 0x10
     addr_repeat = '%08x' % (ram_base + (words * 4))
index 06f61f987180e73968e77b4b8047a017fac7bbe4..51163bc0db68d5e291a5d1fd4622a5f817cba02b 100644 (file)
@@ -86,7 +86,6 @@ class ConsoleBase(object):
 
         self.at_prompt = False
         self.at_prompt_logevt = None
-        self.ram_base = None
 
     def close(self):
         '''Terminate the connection to the U-Boot console.
@@ -378,39 +377,3 @@ class ConsoleBase(object):
         '''
 
         return ConsoleDisableCheck(self, check_type)
-
-    def find_ram_base(self):
-        '''Find the running U-Boot's RAM location.
-
-        Probe the running U-Boot to determine the address of the first bank
-        of RAM. This is useful for tests that test reading/writing RAM, or
-        load/save files that aren't associated with some standard address
-        typically represented in an environment variable such as
-        ${kernel_addr_r}. The value is cached so that it only needs to be
-        actively read once.
-
-        Args:
-            None.
-
-        Returns:
-            The address of U-Boot's first RAM bank, as an integer.
-        '''
-
-        if self.config.buildconfig.get('config_cmd_bdi', 'n') != 'y':
-            pytest.skip('bdinfo command not supported')
-        if self.ram_base == -1:
-            pytest.skip('Previously failed to find RAM bank start')
-        if self.ram_base is not None:
-            return self.ram_base
-
-        with self.log.section('find_ram_base'):
-            response = self.run_command('bdinfo')
-            for l in response.split('\n'):
-                if '-> start' in l:
-                    self.ram_base = int(l.split('=')[1].strip(), 16)
-                    break
-            if self.ram_base is None:
-                self.ram_base = -1
-                raise Exception('Failed to find RAM bank start in `bdinfo`')
-
-        return self.ram_base
index 539af618dbf228c8b8175578d72ee67eff01213d..522390a207effa669371c26478c74b9b9bf7626a 100644 (file)
@@ -169,3 +169,41 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False):
     runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
     runner.run(cmd, ignore_errors=ignore_errors)
     runner.close()
+
+ram_base = None
+def find_ram_base(u_boot_console):
+    '''Find the running U-Boot's RAM location.
+
+    Probe the running U-Boot to determine the address of the first bank
+    of RAM. This is useful for tests that test reading/writing RAM, or
+    load/save files that aren't associated with some standard address
+    typically represented in an environment variable such as
+    ${kernel_addr_r}. The value is cached so that it only needs to be
+    actively read once.
+
+    Args:
+        u_boot_console: A console connection to U-Boot.
+
+    Returns:
+        The address of U-Boot's first RAM bank, as an integer.
+    '''
+
+    global ram_base
+    if u_boot_console.config.buildconfig.get('config_cmd_bdi', 'n') != 'y':
+        pytest.skip('bdinfo command not supported')
+    if ram_base == -1:
+        pytest.skip('Previously failed to find RAM bank start')
+    if ram_base is not None:
+        return ram_base
+
+    with u_boot_console.log.section('find_ram_base'):
+        response = u_boot_console.run_command('bdinfo')
+        for l in response.split('\n'):
+            if '-> start' in l:
+                ram_base = int(l.split('=')[1].strip(), 16)
+                break
+        if ram_base is None:
+            ram_base = -1
+            raise Exception('Failed to find RAM bank start in `bdinfo`')
+
+    return ram_base