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
|
|
|
|
|
2019-07-08 20:25:23 +00:00
|
|
|
import entry
|
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):
|
2018-10-02 03:12:41 +00:00
|
|
|
def setUp(self):
|
|
|
|
tools.PrepareOutputDir(None)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
tools.FinaliseOutputDir()
|
|
|
|
|
2017-11-13 04:52:21 +00:00
|
|
|
def GetNode(self):
|
|
|
|
binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
|
|
|
fname = fdt_util.EnsureCompiled(
|
2018-10-01 18:22:30 +00:00
|
|
|
os.path.join(binman_dir,('test/005_simple.dts')))
|
2017-11-13 04:52:21 +00:00
|
|
|
dtb = fdt.FdtScan(fname)
|
|
|
|
return dtb.GetNode('/binman/u-boot')
|
|
|
|
|
2019-07-08 20:25:23 +00:00
|
|
|
def _ReloadEntry(self):
|
2017-11-13 04:52:21 +00:00
|
|
|
global entry
|
2018-10-02 03:12:47 +00:00
|
|
|
if entry:
|
2019-05-18 04:00:47 +00:00
|
|
|
if sys.version_info[0] >= 3:
|
|
|
|
import importlib
|
|
|
|
importlib.reload(entry)
|
|
|
|
else:
|
|
|
|
reload(entry)
|
2018-10-02 03:12:47 +00:00
|
|
|
else:
|
|
|
|
import entry
|
2019-07-08 20:25:23 +00:00
|
|
|
|
|
|
|
def test1EntryNoImportLib(self):
|
|
|
|
"""Test that we can import Entry subclassess successfully"""
|
|
|
|
sys.modules['importlib'] = None
|
|
|
|
global entry
|
|
|
|
self._ReloadEntry()
|
|
|
|
entry.Entry.Create(None, self.GetNode(), 'u-boot')
|
|
|
|
self.assertFalse(entry.have_importlib)
|
|
|
|
|
|
|
|
def test2EntryImportLib(self):
|
|
|
|
del sys.modules['importlib']
|
|
|
|
global entry
|
|
|
|
self._ReloadEntry()
|
2017-11-13 04:52:21 +00:00
|
|
|
entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
|
2019-07-08 20:25:23 +00:00
|
|
|
self.assertTrue(entry.have_importlib)
|
2017-11-13 04:52:21 +00:00
|
|
|
|
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
|
2019-07-20 18:23:45 +00:00
|
|
|
base_entry = entry.Entry(None, None, None)
|
2016-11-26 03:15:52 +00:00
|
|
|
self.assertEqual(True, base_entry.ObtainContents())
|
|
|
|
|
|
|
|
def testUnknownEntry(self):
|
|
|
|
"""Test that unknown entry types are detected"""
|
|
|
|
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
|
|
|
|
2018-09-14 10:57:11 +00:00
|
|
|
def testUniqueName(self):
|
|
|
|
"""Test Entry.GetUniqueName"""
|
|
|
|
Node = collections.namedtuple('Node', ['name', 'parent'])
|
|
|
|
base_node = Node('root', None)
|
2019-07-20 18:23:45 +00:00
|
|
|
base_entry = entry.Entry(None, None, base_node)
|
2018-09-14 10:57:11 +00:00
|
|
|
self.assertEqual('root', base_entry.GetUniqueName())
|
|
|
|
sub_node = Node('subnode', base_node)
|
2019-07-20 18:23:45 +00:00
|
|
|
sub_entry = entry.Entry(None, None, sub_node)
|
2018-09-14 10:57:11 +00:00
|
|
|
self.assertEqual('root.subnode', sub_entry.GetUniqueName())
|
|
|
|
|
2018-09-14 10:57:18 +00:00
|
|
|
def testGetDefaultFilename(self):
|
|
|
|
"""Trivial test for this base class function"""
|
2019-07-20 18:23:45 +00:00
|
|
|
base_entry = entry.Entry(None, None, None)
|
2018-09-14 10:57:18 +00:00
|
|
|
self.assertIsNone(base_entry.GetDefaultFilename())
|
2017-11-13 04:52:22 +00:00
|
|
|
|
2019-07-20 18:23:31 +00:00
|
|
|
def testBlobFdt(self):
|
|
|
|
"""Test the GetFdtEtype() method of the blob-dtb entries"""
|
|
|
|
base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
|
|
|
|
self.assertIsNone(base.GetFdtEtype())
|
|
|
|
|
|
|
|
dtb = entry.Entry.Create(None, self.GetNode(), 'u-boot-dtb')
|
|
|
|
self.assertEqual('u-boot-dtb', dtb.GetFdtEtype())
|
|
|
|
|
2019-07-20 18:24:06 +00:00
|
|
|
def testWriteChildData(self):
|
|
|
|
"""Test the WriteChildData() method of the base class"""
|
|
|
|
base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
|
|
|
|
self.assertTrue(base.WriteChildData(base))
|
|
|
|
|
2019-07-20 18:23:31 +00:00
|
|
|
|
2017-11-13 04:52:22 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|