[U-Boot,35/53] binman: Update the _testing entry to support shrinkage
diff mbox series

Message ID 20190720182416.183626-36-sjg@chromium.org
State Accepted
Commit 79d3c58d1268786ce40c6c0920ed2a447247fdc4
Delegated to: Simon Glass
Headers show
Series
  • binman: Support replacing entries in an existing image
Related show

Commit Message

Simon Glass July 20, 2019, 6:23 p.m. UTC
Sometimes entries shrink after packing. As a start towards supporting
this, update the _testing entry to handle the test case.

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

 tools/binman/etype/_testing.py | 25 +++++++++++++++++++------
 tools/binman/ftest.py          | 16 ++++++++--------
 2 files changed, 27 insertions(+), 14 deletions(-)

Comments

Simon Glass July 29, 2019, 9:22 p.m. UTC | #1
Sometimes entries shrink after packing. As a start towards supporting
this, update the _testing entry to handle the test case.

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

 tools/binman/etype/_testing.py | 25 +++++++++++++++++++------
 tools/binman/ftest.py          | 16 ++++++++--------
 2 files changed, 27 insertions(+), 14 deletions(-)

Applied to u-boot-dm, thanks!

Patch
diff mbox series

diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py
index 4a2e4eb7caf..25a6206bf33 100644
--- a/tools/binman/etype/_testing.py
+++ b/tools/binman/etype/_testing.py
@@ -31,8 +31,8 @@  class Entry__testing(Entry):
         return-invalid-entry: Return an invalid entry from GetOffsets()
         return-unknown-contents: Refuse to provide any contents (to cause a
             failure)
-        bad-update-contents: Implement ProcessContents() incorrectly so as to
-            cause a failure
+        bad-update-contents: Return a larger size in ProcessContents
+        bad-shrink-contents: Return a larger size in ProcessContents
         never-complete-process-fdt: Refund to process the FDT (to cause a
             failure)
         require-args: Require that all used args are present (generating an
@@ -51,6 +51,8 @@  class Entry__testing(Entry):
                                                      'return-unknown-contents')
         self.bad_update_contents = fdt_util.GetBool(self._node,
                                                     'bad-update-contents')
+        self.bad_shrink_contents = fdt_util.GetBool(self._node,
+                                                    'bad-shrink-contents')
         self.return_contents_once = fdt_util.GetBool(self._node,
                                                      'return-contents-once')
         self.bad_update_contents_twice = fdt_util.GetBool(self._node,
@@ -76,7 +78,7 @@  class Entry__testing(Entry):
         if self.force_bad_datatype:
             self.GetEntryArgsOrProps([EntryArg('test-bad-datatype-arg', bool)])
         self.return_contents = True
-        self.contents = b'a'
+        self.contents = b'aa'
 
     def ObtainContents(self):
         if self.return_unknown_contents or not self.return_contents:
@@ -93,14 +95,25 @@  class Entry__testing(Entry):
         return {}
 
     def ProcessContents(self):
+        data = self.contents
         if self.bad_update_contents:
             # Request to update the contents with something larger, to cause a
             # failure.
             if self.bad_update_contents_twice:
-                self.contents += b'a'
+                data = self.data + b'a'
             else:
-                self.contents = b'aa'
-            return self.ProcessContentsUpdate(self.contents)
+                data = b'aaa'
+            return self.ProcessContentsUpdate(data)
+        if self.bad_shrink_contents:
+            # Request to update the contents with something smaller, to cause a
+            # failure.
+            data = b'a'
+            return self.ProcessContentsUpdate(data)
+        if self.bad_shrink_contents:
+            # Request to update the contents with something smaller, to cause a
+            # failure.
+            data = b'a'
+            return self.ProcessContentsUpdate(data)
         return True
 
     def ProcessFdt(self, fdt):
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 64c6c0abae1..f8568d7cda1 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1236,7 +1236,7 @@  class TestFunctional(unittest.TestCase):
             state.SetAllowEntryExpansion(False)
             with self.assertRaises(ValueError) as e:
                 self._DoReadFile('059_change_size.dts', True)
-            self.assertIn("Node '/binman/_testing': Cannot update entry size from 1 to 2",
+            self.assertIn("Node '/binman/_testing': Cannot update entry size from 2 to 3",
                           str(e.exception))
         finally:
             state.SetAllowEntryExpansion(True)
@@ -1252,7 +1252,7 @@  class TestFunctional(unittest.TestCase):
             'image-pos': 0,
             'offset': 0,
             '_testing:offset': 32,
-            '_testing:size': 1,
+            '_testing:size': 2,
             '_testing:image-pos': 32,
             'section@0/u-boot:offset': 0,
             'section@0/u-boot:size': len(U_BOOT_DATA),
@@ -2135,9 +2135,9 @@  class TestFunctional(unittest.TestCase):
     def testEntryExpand(self):
         """Test expanding an entry after it is packed"""
         data = self._DoReadFile('121_entry_expand.dts')
-        self.assertEqual(b'aa', data[:2])
-        self.assertEqual(U_BOOT_DATA, data[2:2 + len(U_BOOT_DATA)])
-        self.assertEqual(b'aa', data[-2:])
+        self.assertEqual(b'aaa', data[:3])
+        self.assertEqual(U_BOOT_DATA, data[3:3 + len(U_BOOT_DATA)])
+        self.assertEqual(b'aaa', data[-3:])
 
     def testEntryExpandBad(self):
         """Test expanding an entry after it is packed, twice"""
@@ -2149,9 +2149,9 @@  class TestFunctional(unittest.TestCase):
     def testEntryExpandSection(self):
         """Test expanding an entry within a section after it is packed"""
         data = self._DoReadFile('123_entry_expand_section.dts')
-        self.assertEqual(b'aa', data[:2])
-        self.assertEqual(U_BOOT_DATA, data[2:2 + len(U_BOOT_DATA)])
-        self.assertEqual(b'aa', data[-2:])
+        self.assertEqual(b'aaa', data[:3])
+        self.assertEqual(U_BOOT_DATA, data[3:3 + len(U_BOOT_DATA)])
+        self.assertEqual(b'aaa', data[-3:])
 
     def testCompressDtb(self):
         """Test that compress of device-tree files is supported"""