Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 1 | # |
| 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 | |
| 9 | import collections |
Simon Glass | 8f52136 | 2017-11-12 21:52:21 -0700 | [diff] [blame] | 10 | import os |
| 11 | import sys |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 12 | import unittest |
| 13 | |
Simon Glass | 8f52136 | 2017-11-12 21:52:21 -0700 | [diff] [blame] | 14 | import fdt |
| 15 | import fdt_util |
| 16 | import tools |
| 17 | |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 18 | class TestEntry(unittest.TestCase): |
Simon Glass | 8f52136 | 2017-11-12 21:52:21 -0700 | [diff] [blame] | 19 | 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 Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 43 | def testEntryContents(self): |
| 44 | """Test the Entry bass class""" |
Simon Glass | b339326 | 2017-11-12 21:52:20 -0700 | [diff] [blame] | 45 | import entry |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 46 | 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 Glass | b339326 | 2017-11-12 21:52:20 -0700 | [diff] [blame] | 51 | import entry |
Simon Glass | 57454f4 | 2016-11-25 20:15:52 -0700 | [diff] [blame] | 52 | 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 Glass | ac59991 | 2017-11-12 21:52:22 -0700 | [diff] [blame] | 58 | |
| 59 | |
| 60 | if __name__ == "__main__": |
| 61 | unittest.main() |