blob: caa523ebf899fa06312d12dbdcbf96270004fc6f [file] [log] [blame]
Simon Glass4f443042016-11-25 20:15:52 -07001#
2# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5# SPDX-License-Identifier: GPL-2.0+
6#
7# Test for the Entry class
8
9import collections
Simon Glass934cdcf2017-11-12 21:52:21 -070010import os
11import sys
Simon Glass4f443042016-11-25 20:15:52 -070012import unittest
13
Simon Glass934cdcf2017-11-12 21:52:21 -070014import fdt
15import fdt_util
16import tools
17
Simon Glass4f443042016-11-25 20:15:52 -070018class TestEntry(unittest.TestCase):
Simon Glass934cdcf2017-11-12 21:52:21 -070019 def GetNode(self):
20 binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
21 tools.PrepareOutputDir(None)
22 fname = fdt_util.EnsureCompiled(
23 os.path.join(binman_dir,('test/05_simple.dts')))
24 dtb = fdt.FdtScan(fname)
25 return dtb.GetNode('/binman/u-boot')
26
27 def test1EntryNoImportLib(self):
28 """Test that we can import Entry subclassess successfully"""
29
30 sys.modules['importlib'] = None
31 global entry
32 import entry
33 entry.Entry.Create(None, self.GetNode(), 'u-boot')
34
35 def test2EntryImportLib(self):
36 del sys.modules['importlib']
37 global entry
38 reload(entry)
39 entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
40 tools._RemoveOutputDir()
41 del entry
42
Simon Glass4f443042016-11-25 20:15:52 -070043 def testEntryContents(self):
44 """Test the Entry bass class"""
Simon Glass4d5994f2017-11-12 21:52:20 -070045 import entry
Simon Glass4f443042016-11-25 20:15:52 -070046 base_entry = entry.Entry(None, None, None, read_node=False)
47 self.assertEqual(True, base_entry.ObtainContents())
48
49 def testUnknownEntry(self):
50 """Test that unknown entry types are detected"""
Simon Glass4d5994f2017-11-12 21:52:20 -070051 import entry
Simon Glass4f443042016-11-25 20:15:52 -070052 Node = collections.namedtuple('Node', ['name', 'path'])
53 node = Node('invalid-name', 'invalid-path')
54 with self.assertRaises(ValueError) as e:
55 entry.Entry.Create(None, node, node.name)
56 self.assertIn("Unknown entry type 'invalid-name' in node "
57 "'invalid-path'", str(e.exception))
Simon Glass9fc60b42017-11-12 21:52:22 -070058
59
60if __name__ == "__main__":
61 unittest.main()