Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 2 | # Copyright (c) 2017 Google, Inc |
| 3 | # Written by Simon Glass <sjg@chromium.org> |
| 4 | # |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 5 | # Test for the image module |
| 6 | |
| 7 | import unittest |
| 8 | |
| 9 | from image import Image |
Simon Glass | c3f9454 | 2018-07-06 10:27:34 -0600 | [diff] [blame] | 10 | from test_util import capture_sys_output |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 11 | |
| 12 | class TestImage(unittest.TestCase): |
| 13 | def testInvalidFormat(self): |
| 14 | image = Image('name', 'node', test=True) |
| 15 | with self.assertRaises(ValueError) as e: |
Simon Glass | 7c15013 | 2019-11-06 17:22:44 -0700 | [diff] [blame] | 16 | image.LookupSymbol('_binman_something_prop_', False, 'msg', 0) |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 17 | self.assertIn( |
| 18 | "msg: Symbol '_binman_something_prop_' has invalid format", |
| 19 | str(e.exception)) |
| 20 | |
| 21 | def testMissingSymbol(self): |
| 22 | image = Image('name', 'node', test=True) |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 23 | image._entries = {} |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 24 | with self.assertRaises(ValueError) as e: |
Simon Glass | 7c15013 | 2019-11-06 17:22:44 -0700 | [diff] [blame] | 25 | image.LookupSymbol('_binman_type_prop_pname', False, 'msg', 0) |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 26 | self.assertIn("msg: Entry 'type' not found in list ()", |
| 27 | str(e.exception)) |
| 28 | |
| 29 | def testMissingSymbolOptional(self): |
| 30 | image = Image('name', 'node', test=True) |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 31 | image._entries = {} |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 32 | with capture_sys_output() as (stdout, stderr): |
Simon Glass | 7c15013 | 2019-11-06 17:22:44 -0700 | [diff] [blame] | 33 | val = image.LookupSymbol('_binman_type_prop_pname', True, 'msg', 0) |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 34 | self.assertEqual(val, None) |
| 35 | self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n", |
| 36 | stderr.getvalue()) |
| 37 | self.assertEqual('', stdout.getvalue()) |
| 38 | |
| 39 | def testBadProperty(self): |
| 40 | image = Image('name', 'node', test=True) |
Simon Glass | 8beb11e | 2019-07-08 14:25:47 -0600 | [diff] [blame] | 41 | image._entries = {'u-boot': 1} |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 42 | with self.assertRaises(ValueError) as e: |
Simon Glass | 7c15013 | 2019-11-06 17:22:44 -0700 | [diff] [blame] | 43 | image.LookupSymbol('_binman_u_boot_prop_bad', False, 'msg', 0) |
Simon Glass | 1979063 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 44 | self.assertIn("msg: No such property 'bad", str(e.exception)) |