xref: /openbmc/u-boot/tools/binman/etype/_testing.py (revision 78a88f79)
1# SPDX-License-Identifier: GPL-2.0+
2# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5# Entry-type module for testing purposes. Not used in real images.
6#
7
8from entry import Entry
9import fdt_util
10import tools
11
12
13class Entry__testing(Entry):
14    """A fake entry used for testing
15
16    Properties:
17        return_invalid_entry: Return an invalid entry from GetPositions()
18    """
19    def __init__(self, section, etype, node):
20        Entry.__init__(self, section, etype, node)
21        self.return_invalid_entry = fdt_util.GetBool(self._node,
22                                                     'return-invalid-entry')
23        self.return_unknown_contents = fdt_util.GetBool(self._node,
24                                                     'return-unknown-contents')
25        self.bad_update_contents = fdt_util.GetBool(self._node,
26                                                    'bad-update-contents')
27        self.process_fdt_ready = False
28        self.never_complete_process_fdt = fdt_util.GetBool(self._node,
29                                                'never-complete-process-fdt')
30
31    def ObtainContents(self):
32        if self.return_unknown_contents:
33            return False
34        self.data = 'a'
35        self.contents_size = len(self.data)
36        return True
37
38    def GetPositions(self):
39        if self.return_invalid_entry :
40            return {'invalid-entry': [1, 2]}
41        return {}
42
43    def ProcessContents(self):
44        if self.bad_update_contents:
45            # Request to update the conents with something larger, to cause a
46            # failure.
47            self.ProcessContentsUpdate('aa')
48
49    def ProcessFdt(self, fdt):
50        """Force reprocessing the first time"""
51        ready = self.process_fdt_ready
52        if not self.never_complete_process_fdt:
53            self.process_fdt_ready = True
54        return ready
55