1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2016 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
5 # Test for the Entry class
12 from binman import entry
14 from dtoc import fdt_util
15 from patman import tools
17 class TestEntry(unittest.TestCase):
19 tools.PrepareOutputDir(None)
22 tools.FinaliseOutputDir()
25 binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
26 fname = fdt_util.EnsureCompiled(
27 os.path.join(binman_dir,('test/005_simple.dts')))
28 dtb = fdt.FdtScan(fname)
29 return dtb.GetNode('/binman/u-boot')
31 def _ReloadEntry(self):
34 if sys.version_info[0] >= 3:
36 importlib.reload(entry)
40 from binman import entry
42 def testEntryContents(self):
43 """Test the Entry bass class"""
44 from binman import entry
45 base_entry = entry.Entry(None, None, None)
46 self.assertEqual(True, base_entry.ObtainContents())
48 def testUnknownEntry(self):
49 """Test that unknown entry types are detected"""
50 Node = collections.namedtuple('Node', ['name', 'path'])
51 node = Node('invalid-name', 'invalid-path')
52 with self.assertRaises(ValueError) as e:
53 entry.Entry.Create(None, node, node.name)
54 self.assertIn("Unknown entry type 'invalid-name' in node "
55 "'invalid-path'", str(e.exception))
57 def testUniqueName(self):
58 """Test Entry.GetUniqueName"""
59 Node = collections.namedtuple('Node', ['name', 'parent'])
60 base_node = Node('root', None)
61 base_entry = entry.Entry(None, None, base_node)
62 self.assertEqual('root', base_entry.GetUniqueName())
63 sub_node = Node('subnode', base_node)
64 sub_entry = entry.Entry(None, None, sub_node)
65 self.assertEqual('root.subnode', sub_entry.GetUniqueName())
67 def testGetDefaultFilename(self):
68 """Trivial test for this base class function"""
69 base_entry = entry.Entry(None, None, None)
70 self.assertIsNone(base_entry.GetDefaultFilename())
72 def testBlobFdt(self):
73 """Test the GetFdtEtype() method of the blob-dtb entries"""
74 base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
75 self.assertIsNone(base.GetFdtEtype())
77 dtb = entry.Entry.Create(None, self.GetNode(), 'u-boot-dtb')
78 self.assertEqual('u-boot-dtb', dtb.GetFdtEtype())
80 def testWriteChildData(self):
81 """Test the WriteChildData() method of the base class"""
82 base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
83 self.assertTrue(base.WriteChildData(base))
85 def testReadChildData(self):
86 """Test the ReadChildData() method of the base class"""
87 base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
88 self.assertIsNone(base.ReadChildData(base))
91 if __name__ == "__main__":