xref: /openbmc/u-boot/tools/binman/image_test.py (revision 83d290c5)
1*83d290c5STom Rini# SPDX-License-Identifier: GPL-2.0+
219790632SSimon Glass# Copyright (c) 2017 Google, Inc
319790632SSimon Glass# Written by Simon Glass <sjg@chromium.org>
419790632SSimon Glass#
519790632SSimon Glass# Test for the image module
619790632SSimon Glass
719790632SSimon Glassimport unittest
819790632SSimon Glass
919790632SSimon Glassfrom image import Image
1019790632SSimon Glassfrom elf_test import capture_sys_output
1119790632SSimon Glass
1219790632SSimon Glassclass TestImage(unittest.TestCase):
1319790632SSimon Glass    def testInvalidFormat(self):
1419790632SSimon Glass        image = Image('name', 'node', test=True)
1519790632SSimon Glass        with self.assertRaises(ValueError) as e:
1619790632SSimon Glass            image.LookupSymbol('_binman_something_prop_', False, 'msg')
1719790632SSimon Glass        self.assertIn(
1819790632SSimon Glass            "msg: Symbol '_binman_something_prop_' has invalid format",
1919790632SSimon Glass            str(e.exception))
2019790632SSimon Glass
2119790632SSimon Glass    def testMissingSymbol(self):
2219790632SSimon Glass        image = Image('name', 'node', test=True)
2319790632SSimon Glass        image._entries = {}
2419790632SSimon Glass        with self.assertRaises(ValueError) as e:
2519790632SSimon Glass            image.LookupSymbol('_binman_type_prop_pname', False, 'msg')
2619790632SSimon Glass        self.assertIn("msg: Entry 'type' not found in list ()",
2719790632SSimon Glass                      str(e.exception))
2819790632SSimon Glass
2919790632SSimon Glass    def testMissingSymbolOptional(self):
3019790632SSimon Glass        image = Image('name', 'node', test=True)
3119790632SSimon Glass        image._entries = {}
3219790632SSimon Glass        with capture_sys_output() as (stdout, stderr):
3319790632SSimon Glass            val = image.LookupSymbol('_binman_type_prop_pname', True, 'msg')
3419790632SSimon Glass        self.assertEqual(val, None)
3519790632SSimon Glass        self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n",
3619790632SSimon Glass                         stderr.getvalue())
3719790632SSimon Glass        self.assertEqual('', stdout.getvalue())
3819790632SSimon Glass
3919790632SSimon Glass    def testBadProperty(self):
4019790632SSimon Glass        image = Image('name', 'node', test=True)
4119790632SSimon Glass        image._entries = {'u-boot': 1}
4219790632SSimon Glass        with self.assertRaises(ValueError) as e:
4319790632SSimon Glass            image.LookupSymbol('_binman_u_boot_prop_bad', False, 'msg')
4419790632SSimon Glass        self.assertIn("msg: No such property 'bad", str(e.exception))
45