183d290c5STom 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) 15*8f1da50cSSimon Glass section = image._section 1619790632SSimon Glass with self.assertRaises(ValueError) as e: 17*8f1da50cSSimon Glass section.LookupSymbol('_binman_something_prop_', False, 'msg') 1819790632SSimon Glass self.assertIn( 1919790632SSimon Glass "msg: Symbol '_binman_something_prop_' has invalid format", 2019790632SSimon Glass str(e.exception)) 2119790632SSimon Glass 2219790632SSimon Glass def testMissingSymbol(self): 2319790632SSimon Glass image = Image('name', 'node', test=True) 24*8f1da50cSSimon Glass section = image._section 25*8f1da50cSSimon Glass section._entries = {} 2619790632SSimon Glass with self.assertRaises(ValueError) as e: 27*8f1da50cSSimon Glass section.LookupSymbol('_binman_type_prop_pname', False, 'msg') 2819790632SSimon Glass self.assertIn("msg: Entry 'type' not found in list ()", 2919790632SSimon Glass str(e.exception)) 3019790632SSimon Glass 3119790632SSimon Glass def testMissingSymbolOptional(self): 3219790632SSimon Glass image = Image('name', 'node', test=True) 33*8f1da50cSSimon Glass section = image._section 34*8f1da50cSSimon Glass section._entries = {} 3519790632SSimon Glass with capture_sys_output() as (stdout, stderr): 36*8f1da50cSSimon Glass val = section.LookupSymbol('_binman_type_prop_pname', True, 'msg') 3719790632SSimon Glass self.assertEqual(val, None) 3819790632SSimon Glass self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n", 3919790632SSimon Glass stderr.getvalue()) 4019790632SSimon Glass self.assertEqual('', stdout.getvalue()) 4119790632SSimon Glass 4219790632SSimon Glass def testBadProperty(self): 4319790632SSimon Glass image = Image('name', 'node', test=True) 44*8f1da50cSSimon Glass section = image._section 45*8f1da50cSSimon Glass section._entries = {'u-boot': 1} 4619790632SSimon Glass with self.assertRaises(ValueError) as e: 47*8f1da50cSSimon Glass section.LookupSymbol('_binman_u_boot_prop_bad', False, 'msg') 4819790632SSimon Glass self.assertIn("msg: No such property 'bad", str(e.exception)) 49