Skip to contentSkip to conversation

test: fit: Use shared make_fname from fit_util

PATCH Superseded Aristo Chen 3 participants 6 messages Apr 20 – May 8

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: fit: Use shared make_fname from fit_util

test_fit.py declares a local make_fname closure that is byte-identical to fit_util.make_fname. Drop the local copy and call the shared helper at all seven call sites so there is one definition to maintain.

No behavioural change. Both implementations return os.path.join(ubman.config.build_dir, basename).

---
 test/py/tests/test_fit.py | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
test/py/tests/test_fit.py +7 -17
index 619f73153a0..3b60f814c85 100755
@@ -119,16 +119,6 @@ host save hostfs 0 %(loadables2_addr)x %(loadables2_out)s %(loadables2_size)x
 @pytest.mark.buildconfigspec('fit_signature')
 @pytest.mark.requiredtool('dtc')
 def test_fit(ubman):
-    def make_fname(leaf):
-        """Make a temporary filename
-
-        Args:
-            leaf: Leaf name of file to create (within temporary directory)
-        Return:
-            Temporary filename
-        """
-        return os.path.join(ubman.config.build_dir, leaf)
-
     def filesize(fname):
         """Get the size of a file
 
@@ -156,7 +146,7 @@ def test_fit(ubman):
         Returns:
             Filename of ramdisk created
         """
-        fname = make_fname(filename)
+        fname = fit_util.make_fname(ubman, filename)
         data = ''
         for i in range(100):
             data += '%s %d was seldom used in the middle ages\n' % (text, i)
@@ -265,12 +255,12 @@ def test_fit(ubman):
         ramdisk = make_ramdisk('test-ramdisk.bin', 'ramdisk')
         loadables1 = fit_util.make_kernel(ubman, 'test-loadables1.bin', 'lenrek')
         loadables2 = make_ramdisk('test-loadables2.bin', 'ksidmar')
-        kernel_out = make_fname('kernel-out.bin')
-        fdt = make_fname('u-boot.dtb')
-        fdt_out = make_fname('fdt-out.dtb')
-        ramdisk_out = make_fname('ramdisk-out.bin')
-        loadables1_out = make_fname('loadables1-out.bin')
-        loadables2_out = make_fname('loadables2-out.bin')
+        kernel_out = fit_util.make_fname(ubman, 'kernel-out.bin')
+        fdt = fit_util.make_fname(ubman, 'u-boot.dtb')
+        fdt_out = fit_util.make_fname(ubman, 'fdt-out.dtb')
+        ramdisk_out = fit_util.make_fname(ubman, 'ramdisk-out.bin')
+        loadables1_out = fit_util.make_fname(ubman, 'loadables1-out.bin')
+        loadables2_out = fit_util.make_fname(ubman, 'loadables2-out.bin')
 
         # Set up basic parameters with default values
         params = {
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Aristo Chen

test: fit: Use shared make_fname from fit_util

test_fit.py declares a local make_fname closure that is byte-identical to fit_util.make_fname. Drop the local copy and call the shared helper at all seven call sites so there is one definition to maintain.

Quoted 7 lines

No behavioural change. Both implementations return os.path.join(ubman.config.build_dir, basename).

test/py/tests/test_fit.py | 24 +++++++-----------------

 1 file changed, 7 insertions(+), 17 deletions(-)
#2 lore raw
In reply to Aristo Chen
Quoted 4 lines · Aristo Chen

test_fit.py declares a local make_fname closure that is byte-identical to fit_util.make_fname. Drop the local copy and call the shared helper at all seven call sites so there is one definition to maintain.

Quoted 8 lines

No behavioural change. Both implementations return os.path.join(ubman.config.build_dir, basename).

---
 test/py/tests/test_fit.py | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

Can you please rebase this on current master? Thanks.

Signature · 1 line
Tom
#3 lore raw

PATCH v2 1/1 test: fit: Use shared make_fname from fit_util

In reply to Aristo Chen

test_fit.py declares a local make_fname closure that is byte-identical to fit_util.make_fname. Drop the local copy and call the shared helper at all seven call sites so there is one definition to maintain.

No behavioural change. Both implementations return os.path.join(ubman.config.build_dir, basename).

---
 test/py/tests/test_fit.py | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)
test/py/tests/test_fit.py +7 -19
index bcaaa6a5fc4..4f56a1421e1 100755
@@ -140,18 +140,6 @@ class TestFitImage:
       - run code coverage to make sure we are testing all the code
     """
 
-    def make_fname(self, ubman, leaf):
-        """Make a temporary filename
-
-        Args:
-            ubman (ConsoleBase): U-Boot fixture
-            leaf (str): Leaf name of file to create (within temporary directory)
-
-        Return:
-            str: Temporary filename
-        """
-        return os.path.join(ubman.config.build_dir, leaf)
-
     def filesize(self, fname):
         """Get the size of a file
 
@@ -181,7 +169,7 @@ class TestFitImage:
         Returns:
             str: Filename of ramdisk created
         """
-        fname = self.make_fname(ubman, filename)
+        fname = fit_util.make_fname(ubman, filename)
         data = ''
         for i in range(100):
             data += f'{text} {i} was seldom used in the middle ages\n'
@@ -278,33 +266,33 @@ class TestFitImage:
             'fit_addr' : 0x1000,
 
             'kernel' : kernel,
-            'kernel_out' : self.make_fname(ubman, 'kernel-out.bin'),
+            'kernel_out' : fit_util.make_fname(ubman, 'kernel-out.bin'),
             'kernel_addr' : 0x40000,
             'kernel_size' : self.filesize(kernel),
             'kernel_config' : 'kernel = "kernel-1";',
 
             'fdt_data' : fdt_data,
-            'fdt' : self.make_fname(ubman, 'u-boot.dtb'),
-            'fdt_out' : self.make_fname(ubman, 'fdt-out.dtb'),
+            'fdt' : fit_util.make_fname(ubman, 'u-boot.dtb'),
+            'fdt_out' : fit_util.make_fname(ubman, 'fdt-out.dtb'),
             'fdt_addr' : 0x80000,
             'fdt_size' : self.filesize(fdt_data),
             'fdt_load' : '',
 
             'ramdisk' : ramdisk,
-            'ramdisk_out' : self.make_fname(ubman, 'ramdisk-out.bin'),
+            'ramdisk_out' : fit_util.make_fname(ubman, 'ramdisk-out.bin'),
             'ramdisk_addr' : 0xc0000,
             'ramdisk_size' : self.filesize(ramdisk),
             'ramdisk_load' : '',
             'ramdisk_config' : '',
 
             'loadables1' : loadables1,
-            'loadables1_out' : self.make_fname(ubman, 'loadables1-out.bin'),
+            'loadables1_out' : fit_util.make_fname(ubman, 'loadables1-out.bin'),
             'loadables1_addr' : 0x100000,
             'loadables1_size' : self.filesize(loadables1),
             'loadables1_load' : '',
 
             'loadables2' : loadables2,
-            'loadables2_out' : self.make_fname(ubman, 'loadables2-out.bin'),
+            'loadables2_out' : fit_util.make_fname(ubman, 'loadables2-out.bin'),
             'loadables2_addr' : 0x140000,
             'loadables2_size' : self.filesize(loadables2),
             'loadables2_load' : '',
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#4 lore raw
Quoted 6 lines · Aristo Chen

test: fit: Use shared make_fname from fit_util

test_fit.py declares a local make_fname closure that is byte-identical to fit_util.make_fname. Drop the local copy and call the shared helper at all seven call sites so there is one definition to maintain.

Quoted 7 lines

No behavioural change. Both implementations return os.path.join(ubman.config.build_dir, basename).

test/py/tests/test_fit.py | 26 +++++++-------------------

 1 file changed, 7 insertions(+), 19 deletions(-)
#5 lore raw
In reply to Aristo Chen
Quoted 8 lines · Aristo Chen

test_fit.py declares a local make_fname closure that is byte-identical to fit_util.make_fname. Drop the local copy and call the shared helper at all seven call sites so there is one definition to maintain.

No behavioural change. Both implementations return os.path.join(ubman.config.build_dir, basename).

[...]

Applied to u-boot/master, thanks!

[1/1] test: fit: Use shared make_fname from fit_util

      commit: 28eed2103cc3eb8ef4c07ce514114961c0414aab
Signature · 1 line
Tom