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