diff mbox series

[6/7] binman: Test replacing non-section entries in FIT subsections

Message ID 20220327153151.15912-7-alpernebiyasak@gmail.com
State Accepted
Commit 99283e5389cd5b8b7bb191913fa1d3d18e4bfbec
Delegated to: Tom Rini
Headers show
Series binman: Fix replacing FIT subentries | expand

Commit Message

Alper Nebi Yasak March 27, 2022, 3:31 p.m. UTC
A previous patch fixes binman to correctly extract FIT subentries. This
makes it easier to test replacing these entries as we can write tests
using an existing helper function that relies on extracting the replaced
entry.

Add tests that replace leaf entries in FIT subsections with data of
various sizes. Replacing the subsections or the whole FIT section does
not work yet due to the section contents being re-built from unreplaced
subentries' data.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---

 tools/binman/ftest.py | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Comments

Simon Glass April 19, 2022, 9:54 p.m. UTC | #1
On Sun, 27 Mar 2022 at 09:32, Alper Nebi Yasak <alpernebiyasak@gmail.com> wrote:
>
> A previous patch fixes binman to correctly extract FIT subentries. This
> makes it easier to test replacing these entries as we can write tests
> using an existing helper function that relies on extracting the replaced
> entry.
>
> Add tests that replace leaf entries in FIT subsections with data of
> various sizes. Replacing the subsections or the whole FIT section does
> not work yet due to the section contents being re-built from unreplaced
> subentries' data.
>
> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> ---
>
>  tools/binman/ftest.py | 38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)

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

Patch

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index a31568997f6f..43bec4a88841 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -5603,6 +5603,44 @@  def testExtractFitSubentries(self):
             data = control.ReadEntry(image_fname, entry_path)
             self.assertEqual(expected, data)
 
+    def testReplaceFitSubentryLeafSameSize(self):
+        """Test replacing a FIT leaf subentry with same-size data"""
+        new_data = b'x' * len(U_BOOT_DATA)
+        data, expected_fdtmap, _ = self._RunReplaceCmd(
+            'fit/kernel/u-boot', new_data,
+            dts='233_fit_extract_replace.dts')
+        self.assertEqual(new_data, data)
+
+        path, fdtmap = state.GetFdtContents('fdtmap')
+        self.assertIsNotNone(path)
+        self.assertEqual(expected_fdtmap, fdtmap)
+
+    def testReplaceFitSubentryLeafBiggerSize(self):
+        """Test replacing a FIT leaf subentry with bigger-size data"""
+        new_data = b'ub' * len(U_BOOT_NODTB_DATA)
+        data, expected_fdtmap, _ = self._RunReplaceCmd(
+            'fit/fdt-1/u-boot-nodtb', new_data,
+            dts='233_fit_extract_replace.dts')
+        self.assertEqual(new_data, data)
+
+        # Will be repacked, so fdtmap must change
+        path, fdtmap = state.GetFdtContents('fdtmap')
+        self.assertIsNotNone(path)
+        self.assertNotEqual(expected_fdtmap, fdtmap)
+
+    def testReplaceFitSubentryLeafSmallerSize(self):
+        """Test replacing a FIT leaf subentry with smaller-size data"""
+        new_data = b'x'
+        expected = new_data.ljust(len(U_BOOT_NODTB_DATA), b'\0')
+        data, expected_fdtmap, _ = self._RunReplaceCmd(
+            'fit/fdt-1/u-boot-nodtb', new_data,
+            dts='233_fit_extract_replace.dts')
+        self.assertEqual(expected, data)
+
+        path, fdtmap = state.GetFdtContents('fdtmap')
+        self.assertIsNotNone(path)
+        self.assertEqual(expected_fdtmap, fdtmap)
+
 
 if __name__ == "__main__":
     unittest.main()