blob: 6fa735ed5967641ef247cd06c3c46acb0b9da6eb [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glass57454f42016-11-25 20:15:52 -07002# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
Simon Glass57454f42016-11-25 20:15:52 -07005# Test for the Entry class
6
7import collections
Simon Glass8f521362017-11-12 21:52:21 -07008import os
9import sys
Simon Glass57454f42016-11-25 20:15:52 -070010import unittest
11
Simon Glass8f521362017-11-12 21:52:21 -070012import fdt
13import fdt_util
14import tools
15
Simon Glass57454f42016-11-25 20:15:52 -070016class TestEntry(unittest.TestCase):
Simon Glass8f521362017-11-12 21:52:21 -070017 def GetNode(self):
18 binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
19 tools.PrepareOutputDir(None)
20 fname = fdt_util.EnsureCompiled(
21 os.path.join(binman_dir,('test/05_simple.dts')))
22 dtb = fdt.FdtScan(fname)
23 return dtb.GetNode('/binman/u-boot')
24
25 def test1EntryNoImportLib(self):
26 """Test that we can import Entry subclassess successfully"""
27
28 sys.modules['importlib'] = None
29 global entry
30 import entry
31 entry.Entry.Create(None, self.GetNode(), 'u-boot')
32
33 def test2EntryImportLib(self):
34 del sys.modules['importlib']
35 global entry
36 reload(entry)
37 entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
38 tools._RemoveOutputDir()
39 del entry
40
Simon Glass57454f42016-11-25 20:15:52 -070041 def testEntryContents(self):
42 """Test the Entry bass class"""
Simon Glassb3393262017-11-12 21:52:20 -070043 import entry
Simon Glass57454f42016-11-25 20:15:52 -070044 base_entry = entry.Entry(None, None, None, read_node=False)
45 self.assertEqual(True, base_entry.ObtainContents())
46
47 def testUnknownEntry(self):
48 """Test that unknown entry types are detected"""
Simon Glassb3393262017-11-12 21:52:20 -070049 import entry
Simon Glass57454f42016-11-25 20:15:52 -070050 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))
Simon Glassac599912017-11-12 21:52:22 -070056
57
58if __name__ == "__main__":
59 unittest.main()