[PATCH v5 15/21] binman: Add compression tests

Stefan Herbrechtsmeier stefan.herbrechtsmeier-oss at weidmueller.com
Fri Aug 19 16:00:29 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

Changes in v5:
- Use self.comp_bintools dict
- Use _CheckBintool(bintool) function

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

Changes in v2:
- Add commit to add compression tests

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

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index ffcd7d2567..bbb2fa19c1 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -5779,6 +5779,32 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
             self._DoTestFile('237_compress_dtb_invalid.dts')
         self.assertIn("Unknown algorithm 'invalid'", str(e.exception))
 
+    def testCompUtilCompressions(self):
+        """Test compression algorithms"""
+        for bintool in self.comp_bintools.values():
+            self._CheckBintool(bintool)
+            data = bintool.compress(COMPRESS_DATA)
+            self.assertNotEqual(COMPRESS_DATA, data)
+            orig = bintool.decompress(data)
+            self.assertEquals(COMPRESS_DATA, orig)
+
+    def testCompUtilVersions(self):
+        """Test tool version of compression algorithms"""
+        for bintool in self.comp_bintools.values():
+            self._CheckBintool(bintool)
+            version = bintool.version()
+            self.assertRegex(version, '^v?[0-9]+[0-9.]*')
+
+    def testCompUtilPadding(self):
+        """Test padding of compression algorithms"""
+        for bintool in self.comp_bintools.values():
+            self._CheckBintool(bintool)
+            data = bintool.compress(COMPRESS_DATA)
+            self.assertNotEqual(COMPRESS_DATA, data)
+            data += tools.get_bytes(0, 64)
+            orig = bintool.decompress(data)
+            self.assertEquals(COMPRESS_DATA, orig)
+
 
 if __name__ == "__main__":
     unittest.main()
-- 
2.30.2



More information about the U-Boot mailing list