binman: Correct operation of ObtainContents()
[oweals/u-boot.git] / tools / binman / etype / _testing.py
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
8 from entry import Entry
9 import fdt_util
10 import tools
11
12
13 class 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
26     def ObtainContents(self):
27         if self.return_unknown_contents:
28             return False
29         self.data = 'a'
30         self.contents_size = len(self.data)
31         return True
32
33     def GetPositions(self):
34         if self.return_invalid_entry :
35             return {'invalid-entry': [1, 2]}
36         return {}