xref: /openbmc/u-boot/tools/binman/fdt_test.py (revision eb5ba3ae)
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 fdt modules
8
9import os
10import sys
11import tempfile
12import unittest
13
14from fdt_select import FdtScan
15import fdt_util
16import tools
17
18class TestFdt(unittest.TestCase):
19    @classmethod
20    def setUpClass(self):
21        self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
22        self._indir = tempfile.mkdtemp(prefix='binmant.')
23        tools.PrepareOutputDir(self._indir, True)
24
25    def TestFile(self, fname):
26        return os.path.join(self._binman_dir, 'test', fname)
27
28    def GetCompiled(self, fname):
29        return fdt_util.EnsureCompiled(self.TestFile(fname))
30
31    def _DeleteProp(self, fdt):
32        node = fdt.GetNode('/microcode/update@0')
33        node.DeleteProp('data')
34
35    def testFdtNormal(self):
36        fname = self.GetCompiled('34_x86_ucode.dts')
37        fdt = FdtScan(fname)
38        self._DeleteProp(fdt)
39
40    def testFdtFallback(self):
41        fname = self.GetCompiled('34_x86_ucode.dts')
42        fdt = FdtScan(fname, True)
43        fdt.GetProp('/microcode/update@0', 'data')
44        self.assertEqual('fred',
45            fdt.GetProp('/microcode/update@0', 'none', default='fred'))
46        self.assertEqual('12345678 12345679',
47            fdt.GetProp('/microcode/update@0', 'data', typespec='x'))
48        self._DeleteProp(fdt)
49