aboutsummaryrefslogtreecommitdiff
path: root/tools/binman/cbfs_util_test.py
diff options
context:
space:
mode:
authorSimon Glass2022-01-09 20:13:58 -0700
committerSimon Glass2022-01-25 12:36:11 -0700
commit5417da574e058efc66b471a3286cef5ac3bba1e1 (patch)
tree890d84ea3971fd2aaab90a4f8fd2734f946f6b3b /tools/binman/cbfs_util_test.py
parent56ee85eef11e6162e2626ba644c6de459137dd23 (diff)
binman: Convert to using the CBFS bintool
Update the CBFS tests to use this bintool, instead of running cbfstool directly. This simplifies the overall code and provides more consistency, as well as supporting missing bintools. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/cbfs_util_test.py')
-rwxr-xr-xtools/binman/cbfs_util_test.py51
1 files changed, 19 insertions, 32 deletions
diff --git a/tools/binman/cbfs_util_test.py b/tools/binman/cbfs_util_test.py
index 2c62c8a0f81..70b42795bfd 100755
--- a/tools/binman/cbfs_util_test.py
+++ b/tools/binman/cbfs_util_test.py
@@ -16,6 +16,7 @@ import struct
import tempfile
import unittest
+from binman import bintool
from binman import cbfs_util
from binman.cbfs_util import CbfsWriter
from binman import elf
@@ -45,11 +46,8 @@ class TestCbfs(unittest.TestCase):
# compressing files
tools.PrepareOutputDir(None)
- cls.have_cbfstool = True
- try:
- tools.Run('which', 'cbfstool')
- except:
- cls.have_cbfstool = False
+ cls.cbfstool = bintool.Bintool.create('cbfstool')
+ cls.have_cbfstool = cls.cbfstool.is_present()
cls.have_lz4 = True
try:
@@ -177,19 +175,19 @@ class TestCbfs(unittest.TestCase):
if not self.have_cbfstool or not self.have_lz4:
return None
cbfs_fname = os.path.join(self._indir, 'test.cbfs')
- cbfs_util.cbfstool(cbfs_fname, 'create', '-m', arch, '-s', '%#x' % size)
+ self.cbfstool.create_new(cbfs_fname, size, arch)
if base:
base = [(1 << 32) - size + b for b in base]
- cbfs_util.cbfstool(cbfs_fname, 'add', '-n', 'u-boot', '-t', 'raw',
- '-c', compress and compress[0] or 'none',
- '-f', tools.GetInputFilename(
- compress and 'compress' or 'u-boot.bin'),
- base=base[0] if base else None)
- cbfs_util.cbfstool(cbfs_fname, 'add', '-n', 'u-boot-dtb', '-t', 'raw',
- '-c', compress and compress[1] or 'none',
- '-f', tools.GetInputFilename(
- compress and 'compress' or 'u-boot.dtb'),
- base=base[1] if base else None)
+ self.cbfstool.add_raw(
+ cbfs_fname, 'u-boot',
+ tools.GetInputFilename(compress and 'compress' or 'u-boot.bin'),
+ compress[0] if compress else None,
+ base[0] if base else None)
+ self.cbfstool.add_raw(
+ cbfs_fname, 'u-boot-dtb',
+ tools.GetInputFilename(compress and 'compress' or 'u-boot.dtb'),
+ compress[1] if compress else None,
+ base[1] if base else None)
return cbfs_fname
def _compare_expected_cbfs(self, data, cbfstool_fname):
@@ -223,18 +221,9 @@ class TestCbfs(unittest.TestCase):
"""Test failure to run cbfstool"""
if not self.have_cbfstool:
self.skipTest('No cbfstool available')
- try:
- # In verbose mode this test fails since stderr is not captured. Fix
- # this by turning off verbosity.
- old_verbose = cbfs_util.VERBOSE
- cbfs_util.VERBOSE = False
- with test_util.capture_sys_output() as (_stdout, stderr):
- with self.assertRaises(Exception) as e:
- cbfs_util.cbfstool('missing-file', 'bad-command')
- finally:
- cbfs_util.VERBOSE = old_verbose
- self.assertIn('Unknown command', stderr.getvalue())
- self.assertIn('Failed to run', str(e.exception))
+ with self.assertRaises(ValueError) as exc:
+ out = self.cbfstool.fail()
+ self.assertIn('cbfstool missing-file bad-command', str(exc.exception))
def test_cbfs_raw(self):
"""Test base handling of a Coreboot Filesystem (CBFS)"""
@@ -515,10 +504,8 @@ class TestCbfs(unittest.TestCase):
# Compare against what cbfstool creates
if self.have_cbfstool:
cbfs_fname = os.path.join(self._indir, 'test.cbfs')
- cbfs_util.cbfstool(cbfs_fname, 'create', '-m', 'x86', '-s',
- '%#x' % size)
- cbfs_util.cbfstool(cbfs_fname, 'add-stage', '-n', 'u-boot',
- '-f', elf_fname)
+ self.cbfstool.create_new(cbfs_fname, size)
+ self.cbfstool.add_stage(cbfs_fname, 'u-boot', elf_fname)
self._compare_expected_cbfs(data, cbfs_fname)
def test_cbfs_raw_compress(self):