binman: Move compression bintools creation into test setup

Move compression bintools (packer) creation into test setup to reuse
bintool objects between tests.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Put comp_util import back in, since it is still needed here:
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Stefan Herbrechtsmeier 2022-08-19 16:25:28 +02:00 committed by Simon Glass
parent 4f463e3dee
commit cbe2e75d00

View file

@ -107,6 +107,8 @@ BASE_DTB_PROPS = ['offset', 'size', 'image-pos']
# Extra properties expected to be in the device tree when allow-repack is used # Extra properties expected to be in the device tree when allow-repack is used
REPACK_DTB_PROPS = ['orig-offset', 'orig-size'] REPACK_DTB_PROPS = ['orig-offset', 'orig-size']
# Supported compression bintools
COMP_BINTOOLS = ['lz4', 'lzma_alone']
class TestFunctional(unittest.TestCase): class TestFunctional(unittest.TestCase):
"""Functional tests for binman """Functional tests for binman
@ -212,7 +214,9 @@ class TestFunctional(unittest.TestCase):
TestFunctional._MakeInputFile('tee.elf', TestFunctional._MakeInputFile('tee.elf',
tools.read_file(cls.ElfTestFile('elf_sections'))) tools.read_file(cls.ElfTestFile('elf_sections')))
cls.have_lz4 = comp_util.HAVE_LZ4 cls.comp_bintools = {}
for name in COMP_BINTOOLS:
cls.comp_bintools[name] = bintool.Bintool.create(name)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
@ -242,9 +246,13 @@ class TestFunctional(unittest.TestCase):
cls.toolpath = toolpath cls.toolpath = toolpath
cls.verbosity = verbosity cls.verbosity = verbosity
def _CheckBintool(self, bintool):
if not bintool.is_present():
self.skipTest('%s not available' % bintool.name)
def _CheckLz4(self): def _CheckLz4(self):
if not self.have_lz4: bintool = self.comp_bintools['lz4']
self.skipTest('lz4 --no-frame-crc not available') self._CheckBintool(bintool)
def _CleanupOutputDir(self): def _CleanupOutputDir(self):
"""Remove the temporary output directory""" """Remove the temporary output directory"""
@ -1967,7 +1975,8 @@ class TestFunctional(unittest.TestCase):
self._ResetDtbs() self._ResetDtbs()
def _decompress(self, data): def _decompress(self, data):
return comp_util.decompress(data, 'lz4') bintool = self.comp_bintools['lz4']
return bintool.decompress(data)
def testCompress(self): def testCompress(self):
"""Test compression of blobs""" """Test compression of blobs"""
@ -2855,8 +2864,10 @@ class TestFunctional(unittest.TestCase):
def testExtractCbfsRaw(self): def testExtractCbfsRaw(self):
"""Test extracting CBFS compressed data without decompressing it""" """Test extracting CBFS compressed data without decompressing it"""
bintool = self.comp_bintools['lzma_alone']
self._CheckBintool(bintool)
data = self._RunExtractCmd('section/cbfs/u-boot-dtb', decomp=False) data = self._RunExtractCmd('section/cbfs/u-boot-dtb', decomp=False)
dtb = comp_util.decompress(data, 'lzma') dtb = bintool.decompress(data)
self.assertEqual(EXTRACT_DTB_SIZE, len(dtb)) self.assertEqual(EXTRACT_DTB_SIZE, len(dtb))
def testExtractBadEntry(self): def testExtractBadEntry(self):
@ -4427,14 +4438,15 @@ class TestFunctional(unittest.TestCase):
rest = base[len(U_BOOT_DATA):] rest = base[len(U_BOOT_DATA):]
# Check compressed data # Check compressed data
expect1 = comp_util.compress(COMPRESS_DATA + U_BOOT_DATA, 'lz4') bintool = self.comp_bintools['lz4']
expect1 = bintool.compress(COMPRESS_DATA + U_BOOT_DATA)
data1 = rest[:len(expect1)] data1 = rest[:len(expect1)]
section1 = self._decompress(data1) section1 = self._decompress(data1)
self.assertEquals(expect1, data1) self.assertEquals(expect1, data1)
self.assertEquals(COMPRESS_DATA + U_BOOT_DATA, section1) self.assertEquals(COMPRESS_DATA + U_BOOT_DATA, section1)
rest1 = rest[len(expect1):] rest1 = rest[len(expect1):]
expect2 = comp_util.compress(COMPRESS_DATA + COMPRESS_DATA, 'lz4') expect2 = bintool.compress(COMPRESS_DATA + COMPRESS_DATA)
data2 = rest1[:len(expect2)] data2 = rest1[:len(expect2)]
section2 = self._decompress(data2) section2 = self._decompress(data2)
self.assertEquals(expect2, data2) self.assertEquals(expect2, data2)