[U-Boot] [PATCH v2 31/31] binman: Add a test for nested and aligned sections

Simon Glass sjg at chromium.org
Mon Jul 8 20:25:53 UTC 2019


Current test coverage is likely sufficient for the logic used to place
sections in the image. However it seems useful to add a test specifically
for nested sections, since these could have some unusual interactions.

Add a new test for this and aligned sections. This test failed before the
refactor to drop the bsection.py file (Section class), but passes now.

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

Changes in v2:
- Add patches to enhance the 'ls' command to filter which entries are shown
- Add patches to implement the 'extract' command

 tools/binman/ftest.py                        | 67 +++++++++++++++++++-
 tools/binman/test/131_pack_align_section.dts | 28 ++++++++
 2 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/test/131_pack_align_section.dts

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 709fa0adc3f..6a40d1fdbb4 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -586,7 +586,7 @@ class TestFunctional(unittest.TestCase):
 
     def testSimpleDebug(self):
         """Test a simple binman run with debugging enabled"""
-        data = self._DoTestFile('005_simple.dts', debug=True)
+        self._DoTestFile('005_simple.dts', debug=True)
 
     def testDual(self):
         """Test that we can handle creating two images
@@ -2654,6 +2654,71 @@ class TestFunctional(unittest.TestCase):
         self.assertIn('Must specify exactly one entry path to write with -o',
                       str(e.exception))
 
+    def testPackAlignSection(self):
+        """Test that sections can have alignment"""
+        self._DoReadFile('131_pack_align_section.dts')
+
+        self.assertIn('image', control.images)
+        image = control.images['image']
+        entries = image.GetEntries()
+        self.assertEqual(3, len(entries))
+
+        # First u-boot
+        self.assertIn('u-boot', entries)
+        entry = entries['u-boot']
+        self.assertEqual(0, entry.offset)
+        self.assertEqual(0, entry.image_pos)
+        self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
+        self.assertEqual(len(U_BOOT_DATA), entry.size)
+
+        # Section0
+        self.assertIn('section0', entries)
+        section0 = entries['section0']
+        self.assertEqual(0x10, section0.offset)
+        self.assertEqual(0x10, section0.image_pos)
+        self.assertEqual(len(U_BOOT_DATA), section0.size)
+
+        # Second u-boot
+        section_entries = section0.GetEntries()
+        self.assertIn('u-boot', section_entries)
+        entry = section_entries['u-boot']
+        self.assertEqual(0, entry.offset)
+        self.assertEqual(0x10, entry.image_pos)
+        self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
+        self.assertEqual(len(U_BOOT_DATA), entry.size)
+
+        # Section1
+        self.assertIn('section1', entries)
+        section1 = entries['section1']
+        self.assertEqual(0x14, section1.offset)
+        self.assertEqual(0x14, section1.image_pos)
+        self.assertEqual(0x20, section1.size)
+
+        # Second u-boot
+        section_entries = section1.GetEntries()
+        self.assertIn('u-boot', section_entries)
+        entry = section_entries['u-boot']
+        self.assertEqual(0, entry.offset)
+        self.assertEqual(0x14, entry.image_pos)
+        self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
+        self.assertEqual(len(U_BOOT_DATA), entry.size)
+
+        # Section2
+        self.assertIn('section2', section_entries)
+        section2 = section_entries['section2']
+        self.assertEqual(0x4, section2.offset)
+        self.assertEqual(0x18, section2.image_pos)
+        self.assertEqual(4, section2.size)
+
+        # Third u-boot
+        section_entries = section2.GetEntries()
+        self.assertIn('u-boot', section_entries)
+        entry = section_entries['u-boot']
+        self.assertEqual(0, entry.offset)
+        self.assertEqual(0x18, entry.image_pos)
+        self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
+        self.assertEqual(len(U_BOOT_DATA), entry.size)
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/131_pack_align_section.dts b/tools/binman/test/131_pack_align_section.dts
new file mode 100644
index 00000000000..44478855b09
--- /dev/null
+++ b/tools/binman/test/131_pack_align_section.dts
@@ -0,0 +1,28 @@
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		u-boot {
+		};
+		section0 {
+			type = "section";
+			align = <0x10>;
+			u-boot {
+			};
+		};
+		section1 {
+			type = "section";
+			align-size = <0x20>;
+			u-boot {
+			};
+			section2 {
+				type = "section";
+				u-boot {
+				};
+			};
+		};
+	};
+};
-- 
2.22.0.410.gd8fdbe21b5-goog



More information about the U-Boot mailing list