Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 4ca8e04 | 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 | 4ca8e04 | 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 | 3609d5e | 2018-07-06 10:27:34 -0600 | [diff] [blame] | 10 | from test_util import capture_sys_output |
Simon Glass | 4ca8e04 | 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) |
Simon Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 15 | section = image._section |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 16 | with self.assertRaises(ValueError) as e: |
Simon Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 17 | section.LookupSymbol('_binman_something_prop_', False, 'msg') |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 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) |
Simon Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 24 | section = image._section |
| 25 | section._entries = {} |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 26 | with self.assertRaises(ValueError) as e: |
Simon Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 27 | section.LookupSymbol('_binman_type_prop_pname', False, 'msg') |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 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) |
Simon Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 33 | section = image._section |
| 34 | section._entries = {} |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 35 | with capture_sys_output() as (stdout, stderr): |
Simon Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 36 | val = section.LookupSymbol('_binman_type_prop_pname', True, 'msg') |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 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) |
Simon Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 44 | section = image._section |
| 45 | section._entries = {'u-boot': 1} |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 46 | with self.assertRaises(ValueError) as e: |
Simon Glass | eca3221 | 2018-06-01 09:38:12 -0600 | [diff] [blame] | 47 | section.LookupSymbol('_binman_u_boot_prop_bad', False, 'msg') |
Simon Glass | 4ca8e04 | 2017-11-13 18:55:01 -0700 | [diff] [blame] | 48 | self.assertIn("msg: No such property 'bad", str(e.exception)) |