2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2016-11-26 03:15:52 +00:00
|
|
|
# Copyright (c) 2016 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
# Test for the Entry class
|
|
|
|
|
|
|
|
import collections
|
2017-11-13 04:52:21 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2016-11-26 03:15:52 +00:00
|
|
|
import unittest
|
|
|
|
|
2017-11-13 04:52:21 +00:00
|
|
|
import fdt
|
|
|
|
import fdt_util
|
|
|
|
import tools
|
|
|
|
|
2016-11-26 03:15:52 +00:00
|
|
|
class TestEntry(unittest.TestCase):
|
2017-11-13 04:52:21 +00:00
|
|
|
def GetNode(self):
|
|
|
|
binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
|
|
|
tools.PrepareOutputDir(None)
|
|
|
|
fname = fdt_util.EnsureCompiled(
|
|
|
|
os.path.join(binman_dir,('test/05_simple.dts')))
|
|
|
|
dtb = fdt.FdtScan(fname)
|
|
|
|
return dtb.GetNode('/binman/u-boot')
|
|
|
|
|
|
|
|
def test1EntryNoImportLib(self):
|
|
|
|
"""Test that we can import Entry subclassess successfully"""
|
|
|
|
|
|
|
|
sys.modules['importlib'] = None
|
|
|
|
global entry
|
|
|
|
import entry
|
|
|
|
entry.Entry.Create(None, self.GetNode(), 'u-boot')
|
|
|
|
|
|
|
|
def test2EntryImportLib(self):
|
|
|
|
del sys.modules['importlib']
|
|
|
|
global entry
|
|
|
|
reload(entry)
|
|
|
|
entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
|
|
|
|
tools._RemoveOutputDir()
|
|
|
|
del entry
|
|
|
|
|
2016-11-26 03:15:52 +00:00
|
|
|
def testEntryContents(self):
|
|
|
|
"""Test the Entry bass class"""
|
2017-11-13 04:52:20 +00:00
|
|
|
import entry
|
2016-11-26 03:15:52 +00:00
|
|
|
base_entry = entry.Entry(None, None, None, read_node=False)
|
|
|
|
self.assertEqual(True, base_entry.ObtainContents())
|
|
|
|
|
|
|
|
def testUnknownEntry(self):
|
|
|
|
"""Test that unknown entry types are detected"""
|
2017-11-13 04:52:20 +00:00
|
|
|
import entry
|
2016-11-26 03:15:52 +00:00
|
|
|
Node = collections.namedtuple('Node', ['name', 'path'])
|
|
|
|
node = Node('invalid-name', 'invalid-path')
|
|
|
|
with self.assertRaises(ValueError) as e:
|
|
|
|
entry.Entry.Create(None, node, node.name)
|
|
|
|
self.assertIn("Unknown entry type 'invalid-name' in node "
|
|
|
|
"'invalid-path'", str(e.exception))
|
2017-11-13 04:52:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|