binman: Add a test for nested and aligned sections

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@chromium.org>
This commit is contained in:
Simon Glass 2019-07-08 14:25:53 -06:00
parent 71ce0ba284
commit e2705fa9c5
2 changed files with 94 additions and 1 deletions

View File

@ -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()

View File

@ -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 {
};
};
};
};
};