Message ID | 20220808105125.21356-4-stefan.herbrechtsmeier-oss@weidmueller.com |
---|---|
State | Superseded |
Delegated to: | Simon Glass |
Headers | show |
Series | [v2,01/10] binman: Skip elf tests if python elftools is not available | expand |
Hi Stefan, On Mon, 8 Aug 2022 at 04:51, Stefan Herbrechtsmeier <stefan.herbrechtsmeier-oss@weidmueller.com> wrote: > > From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> > > Add common test functions to test all supported compressions. > > Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> > > --- > Instead of the for loop it is possible to use Parameterized [1] testing. > > [1] https://github.com/wolever/parameterized > > Changes in v2: > - Added > > tools/binman/ftest.py | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) Reviewed-by: Simon Glass <sjg@chromium.org> nits below > > diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py > index 96c15cff77..c9b67c48d6 100644 > --- a/tools/binman/ftest.py > +++ b/tools/binman/ftest.py > @@ -5248,6 +5248,30 @@ fdt fdtmap Extract the devicetree blob from the fdtmap > comp_util.decompress(b'1234', 'invalid') > self.assertIn("Unknown algorithm 'invalid'", str(e.exception)) > > + def testCompressions(self): > + """Test compression algorithms""" > + for algo in comp_util.COMPRESSIONS: > + data = comp_util.compress(COMPRESS_DATA, algo) > + self.assertNotEqual(COMPRESS_DATA, data) > + orig = comp_util.decompress(data, algo) > + self.assertEquals(COMPRESS_DATA, orig) > + > + def testVersions(self): > + """Test tool version of compression algorithms""" > + for algo in comp_util.COMPRESSIONS: > + tool = comp_util._get_tool(algo) > + version = tool.version() > + print('%s - %s' % (algo, version)) > + self.assertRegex(version, '^v?[0-9]+[0-9.]*') > + > + def testPadding(self): > + """Test padding of compression algorithms""" > + for algo in comp_util.COMPRESSIONS: > + data = comp_util.compress(COMPRESS_DATA, algo) > + data = data + bytes([0]) * 64 tools.get_bytes(0, 64) > + orig = comp_util.decompress(data, algo) > + self.assertEquals(COMPRESS_DATA, orig) > + > def testBintoolDocs(self): > """Test for creation of bintool documentation""" > with test_util.capture_sys_output() as (stdout, stderr): > -- > 2.30.2 > Regards, Simon
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 96c15cff77..c9b67c48d6 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5248,6 +5248,30 @@ fdt fdtmap Extract the devicetree blob from the fdtmap comp_util.decompress(b'1234', 'invalid') self.assertIn("Unknown algorithm 'invalid'", str(e.exception)) + def testCompressions(self): + """Test compression algorithms""" + for algo in comp_util.COMPRESSIONS: + data = comp_util.compress(COMPRESS_DATA, algo) + self.assertNotEqual(COMPRESS_DATA, data) + orig = comp_util.decompress(data, algo) + self.assertEquals(COMPRESS_DATA, orig) + + def testVersions(self): + """Test tool version of compression algorithms""" + for algo in comp_util.COMPRESSIONS: + tool = comp_util._get_tool(algo) + version = tool.version() + print('%s - %s' % (algo, version)) + self.assertRegex(version, '^v?[0-9]+[0-9.]*') + + def testPadding(self): + """Test padding of compression algorithms""" + for algo in comp_util.COMPRESSIONS: + data = comp_util.compress(COMPRESS_DATA, algo) + data = data + bytes([0]) * 64 + orig = comp_util.decompress(data, algo) + self.assertEquals(COMPRESS_DATA, orig) + def testBintoolDocs(self): """Test for creation of bintool documentation""" with test_util.capture_sys_output() as (stdout, stderr):