xref: /openbmc/u-boot/tools/binman/image_test.py (revision 8e51c0f2)
1# SPDX-License-Identifier: GPL-2.0+
2# Copyright (c) 2017 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5# Test for the image module
6
7import unittest
8
9from image import Image
10from elf_test import capture_sys_output
11
12class TestImage(unittest.TestCase):
13    def testInvalidFormat(self):
14        image = Image('name', 'node', test=True)
15        section = image._section
16        with self.assertRaises(ValueError) as e:
17            section.LookupSymbol('_binman_something_prop_', False, 'msg')
18        self.assertIn(
19            "msg: Symbol '_binman_something_prop_' has invalid format",
20            str(e.exception))
21
22    def testMissingSymbol(self):
23        image = Image('name', 'node', test=True)
24        section = image._section
25        section._entries = {}
26        with self.assertRaises(ValueError) as e:
27            section.LookupSymbol('_binman_type_prop_pname', False, 'msg')
28        self.assertIn("msg: Entry 'type' not found in list ()",
29                      str(e.exception))
30
31    def testMissingSymbolOptional(self):
32        image = Image('name', 'node', test=True)
33        section = image._section
34        section._entries = {}
35        with capture_sys_output() as (stdout, stderr):
36            val = section.LookupSymbol('_binman_type_prop_pname', True, 'msg')
37        self.assertEqual(val, None)
38        self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n",
39                         stderr.getvalue())
40        self.assertEqual('', stdout.getvalue())
41
42    def testBadProperty(self):
43        image = Image('name', 'node', test=True)
44        section = image._section
45        section._entries = {'u-boot': 1}
46        with self.assertRaises(ValueError) as e:
47            section.LookupSymbol('_binman_u_boot_prop_bad', False, 'msg')
48        self.assertIn("msg: No such property 'bad", str(e.exception))
49