Simon Glass | bf7fd50 | 2016-11-25 20:15:51 -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 fdt modules |
| 8 | |
| 9 | import os |
| 10 | import sys |
| 11 | import tempfile |
| 12 | import unittest |
| 13 | |
| 14 | from fdt_select import FdtScan |
| 15 | import fdt_util |
| 16 | import tools |
| 17 | |
| 18 | class 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) |