image_test.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. import unittest
  9. from image import Image
  10. from elf_test import capture_sys_output
  11. class TestImage(unittest.TestCase):
  12. def testInvalidFormat(self):
  13. image = Image('name', 'node', test=True)
  14. with self.assertRaises(ValueError) as e:
  15. image.LookupSymbol('_binman_something_prop_', False, 'msg')
  16. self.assertIn(
  17. "msg: Symbol '_binman_something_prop_' has invalid format",
  18. str(e.exception))
  19. def testMissingSymbol(self):
  20. image = Image('name', 'node', test=True)
  21. image._entries = {}
  22. with self.assertRaises(ValueError) as e:
  23. image.LookupSymbol('_binman_type_prop_pname', False, 'msg')
  24. self.assertIn("msg: Entry 'type' not found in list ()",
  25. str(e.exception))
  26. def testMissingSymbolOptional(self):
  27. image = Image('name', 'node', test=True)
  28. image._entries = {}
  29. with capture_sys_output() as (stdout, stderr):
  30. val = image.LookupSymbol('_binman_type_prop_pname', True, 'msg')
  31. self.assertEqual(val, None)
  32. self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n",
  33. stderr.getvalue())
  34. self.assertEqual('', stdout.getvalue())
  35. def testBadProperty(self):
  36. image = Image('name', 'node', test=True)
  37. image._entries = {'u-boot': 1}
  38. with self.assertRaises(ValueError) as e:
  39. image.LookupSymbol('_binman_u_boot_prop_bad', False, 'msg')
  40. self.assertIn("msg: No such property 'bad", str(e.exception))