end = offset['embed_end'].offset
data = tools.read_file(fname)
embed_data = data[start:end]
- expect = struct.pack('<III', 0x1234, 0x5678, 0)
+ expect = struct.pack('<IIIII', 2, 3, 0x1234, 0x5678, 0)
self.assertEqual(expect, embed_data)
def testEmbedFail(self):
self.assertEqual(True, elf.is_valid(data))
self.assertEqual(False, elf.is_valid(data[4:]))
+ def test_get_symbol_offset(self):
+ fname = self.ElfTestFile('embed_data')
+ syms = elf.GetSymbols(fname, ['embed_start', 'embed'])
+ expected = syms['embed'].address - syms['embed_start'].address
+ val = elf.GetSymbolOffset(fname, 'embed', 'embed_start')
+ self.assertEqual(expected, val)
+
+ with self.assertRaises(KeyError) as e:
+ elf.GetSymbolOffset(fname, 'embed')
+ self.assertIn('__image_copy_start', str(e.exception))
+
if __name__ == '__main__':
unittest.main()
self.assertEquals(tools.get_bytes(0, 1024), base.CompressData(b'abc'))
self.assertEquals(tools.get_bytes(0, 1024), base.DecompressData(b'abc'))
+ def testLookupOffset(self):
+ """Test the lookup_offset() method of the base class"""
+ def MyFindEntryByNode(node):
+ return self.found
+
+ base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
+ base.FindEntryByNode = MyFindEntryByNode
+ base.section = base
+ self.found = None
+ base.offset_from_elf = [self.GetNode(), 'start', 0]
+ with self.assertRaises(ValueError) as e:
+ base.lookup_offset()
+ self.assertIn("Cannot find entry for node 'u-boot'", str(e.exception))
+
+ self.found = base
+ with self.assertRaises(ValueError) as e:
+ base.lookup_offset()
+ self.assertIn("Need elf-fname property 'u-boot'", str(e.exception))
+
if __name__ == "__main__":
unittest.main()