1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2016 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
5 # Entry-type module for testing purposes. Not used in real images.
8 from collections import OrderedDict
10 from entry import Entry, EntryArg
15 class Entry__testing(Entry):
16 """A fake entry used for testing
19 return_invalid_entry: Return an invalid entry from GetOffsets()
21 def __init__(self, section, etype, node):
22 Entry.__init__(self, section, etype, node)
23 self.return_invalid_entry = fdt_util.GetBool(self._node,
24 'return-invalid-entry')
25 self.return_unknown_contents = fdt_util.GetBool(self._node,
26 'return-unknown-contents')
27 self.bad_update_contents = fdt_util.GetBool(self._node,
28 'bad-update-contents')
29 self.process_fdt_ready = False
30 self.never_complete_process_fdt = fdt_util.GetBool(self._node,
31 'never-complete-process-fdt')
32 self.require_args = fdt_util.GetBool(self._node, 'require-args')
34 # This should be picked up by GetEntryArgsOrProps()
35 self.test_existing_prop = 'existing'
36 self.force_bad_datatype = fdt_util.GetBool(self._node,
38 (self.test_str_fdt, self.test_str_arg, self.test_int_fdt,
39 self.test_int_arg, existing) = self.GetEntryArgsOrProps([
40 EntryArg('test-str-fdt', str),
41 EntryArg('test-str-arg', str),
42 EntryArg('test-int-fdt', int),
43 EntryArg('test-int-arg', int),
44 EntryArg('test-existing-prop', str)], self.require_args)
45 if self.force_bad_datatype:
46 self.GetEntryArgsOrProps([EntryArg('test-bad-datatype-arg', bool)])
48 def ObtainContents(self):
49 if self.return_unknown_contents:
52 self.contents_size = len(self.data)
56 if self.return_invalid_entry :
57 return {'invalid-entry': [1, 2]}
60 def ProcessContents(self):
61 if self.bad_update_contents:
62 # Request to update the conents with something larger, to cause a
64 self.ProcessContentsUpdate('aa')
66 def ProcessFdt(self, fdt):
67 """Force reprocessing the first time"""
68 ready = self.process_fdt_ready
69 if not self.never_complete_process_fdt:
70 self.process_fdt_ready = True