[PATCH v4 06/13] binman: Add compression tests

Stefan Herbrechtsmeier stefan.herbrechtsmeier-oss at weidmueller.com
Tue Aug 16 10:42:03 CEST 2022


From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier at weidmueller.com>

Add common test functions to test all supported compressions.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier at weidmueller.com>
Reviewed-by: Simon Glass <sjg at chromium.org>

---
Instead of the for loop it is possible to use Parameterized [1] testing.

[1] https://github.com/wolever/parameterized

(no changes since v3)

Changes in v3:
- Use 'tools.get_bytes(0, 64)' instead of 'bytes([0]) * 64'
- Check if tool is present
- Rename tests

Changes in v2:
- Added

 tools/binman/ftest.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 96c15cff77..bc17107735 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -5248,6 +5248,37 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
             comp_util.decompress(b'1234', 'invalid')
         self.assertIn("Unknown algorithm 'invalid'", str(e.exception))
 
+    def _checkCompUtil(self, algo):
+        if not comp_util.is_present(algo):
+            self.skipTest('%s not available' % comp_util._get_tool_name(algo))
+
+    def testCompUtilCompressions(self):
+        """Test compression algorithms"""
+        for algo in comp_util.ALGORITHMS:
+            self._checkCompUtil(algo)
+            data = comp_util.compress(COMPRESS_DATA, algo)
+            self.assertNotEqual(COMPRESS_DATA, data)
+            orig = comp_util.decompress(data, algo)
+            self.assertEquals(COMPRESS_DATA, orig)
+
+    def testCompUtilVersions(self):
+        """Test tool version of compression algorithms"""
+        for algo in comp_util.ALGORITHMS:
+            self._checkCompUtil(algo)
+            tool = comp_util._get_tool(algo)
+            version = tool.version()
+            print('%s - %s' % (algo, version))
+            self.assertRegex(version, '^v?[0-9]+[0-9.]*')
+
+    def testCompUtilPadding(self):
+        """Test padding of compression algorithms"""
+        for algo in comp_util.ALGORITHMS:
+            self._checkCompUtil(algo)
+            data = comp_util.compress(COMPRESS_DATA, algo)
+            data = data + 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



More information about the U-Boot mailing list