]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | # SPDX-License-Identifier: GPL-2.0+ |
bf7fd50b SG |
2 | # Copyright (c) 2016 Google, Inc |
3 | # Written by Simon Glass <[email protected]> | |
4 | # | |
bf7fd50b SG |
5 | # Test for the fdt modules |
6 | ||
7 | import os | |
8 | import sys | |
9 | import tempfile | |
10 | import unittest | |
11 | ||
16287933 SG |
12 | from dtoc import fdt |
13 | from dtoc import fdt_util | |
14 | from dtoc.fdt import FdtScan | |
bf776679 | 15 | from patman import tools |
bf7fd50b SG |
16 | |
17 | class TestFdt(unittest.TestCase): | |
18 | @classmethod | |
19 | def setUpClass(self): | |
20 | self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) | |
21 | self._indir = tempfile.mkdtemp(prefix='binmant.') | |
22 | tools.PrepareOutputDir(self._indir, True) | |
23 | ||
e0e6275f SG |
24 | @classmethod |
25 | def tearDownClass(self): | |
26 | tools._FinaliseForTest() | |
27 | ||
bf7fd50b SG |
28 | def TestFile(self, fname): |
29 | return os.path.join(self._binman_dir, 'test', fname) | |
30 | ||
31 | def GetCompiled(self, fname): | |
32 | return fdt_util.EnsureCompiled(self.TestFile(fname)) | |
33 | ||
1d88ebb2 SG |
34 | def _DeleteProp(self, dt): |
35 | node = dt.GetNode('/microcode/update@0') | |
bf7fd50b SG |
36 | node.DeleteProp('data') |
37 | ||
38 | def testFdtNormal(self): | |
741f2d62 | 39 | fname = self.GetCompiled('034_x86_ucode.dts') |
1d88ebb2 SG |
40 | dt = FdtScan(fname) |
41 | self._DeleteProp(dt) | |
bf7fd50b | 42 | |
4a28b007 | 43 | def testFdtNormalProp(self): |
741f2d62 | 44 | fname = self.GetCompiled('045_prop_test.dts') |
4a28b007 SG |
45 | dt = FdtScan(fname) |
46 | node = dt.GetNode('/binman/intel-me') | |
47 | self.assertEquals('intel-me', node.name) | |
48 | val = fdt_util.GetString(node, 'filename') | |
49 | self.assertEquals(str, type(val)) | |
50 | self.assertEquals('me.bin', val) | |
51 | ||
52 | prop = node.props['intval'] | |
53 | self.assertEquals(fdt.TYPE_INT, prop.type) | |
54 | self.assertEquals(3, fdt_util.GetInt(node, 'intval')) | |
55 | ||
56 | prop = node.props['intarray'] | |
57 | self.assertEquals(fdt.TYPE_INT, prop.type) | |
58 | self.assertEquals(list, type(prop.value)) | |
59 | self.assertEquals(2, len(prop.value)) | |
60 | self.assertEquals([5, 6], | |
61 | [fdt_util.fdt32_to_cpu(val) for val in prop.value]) | |
62 | ||
63 | prop = node.props['byteval'] | |
64 | self.assertEquals(fdt.TYPE_BYTE, prop.type) | |
65 | self.assertEquals(chr(8), prop.value) | |
66 | ||
67 | prop = node.props['bytearray'] | |
68 | self.assertEquals(fdt.TYPE_BYTE, prop.type) | |
69 | self.assertEquals(list, type(prop.value)) | |
70 | self.assertEquals(str, type(prop.value[0])) | |
71 | self.assertEquals(3, len(prop.value)) | |
72 | self.assertEquals([chr(1), '#', '4'], prop.value) | |
73 | ||
74 | prop = node.props['longbytearray'] | |
75 | self.assertEquals(fdt.TYPE_INT, prop.type) | |
76 | self.assertEquals(0x090a0b0c, fdt_util.GetInt(node, 'longbytearray')) | |
77 | ||
78 | prop = node.props['stringval'] | |
79 | self.assertEquals(fdt.TYPE_STRING, prop.type) | |
80 | self.assertEquals('message2', fdt_util.GetString(node, 'stringval')) | |
81 | ||
82 | prop = node.props['stringarray'] | |
83 | self.assertEquals(fdt.TYPE_STRING, prop.type) | |
84 | self.assertEquals(list, type(prop.value)) | |
85 | self.assertEquals(3, len(prop.value)) | |
86 | self.assertEquals(['another', 'multi-word', 'message'], prop.value) |