diff mbox series

[v6,15/21] binman: Add compression tests

Message ID 20220819142538.24847-16-stefan.herbrechtsmeier-oss@weidmueller.com
State Accepted
Commit da1af35c2f4c09a1fad9b135a11b754e5c6cb234
Delegated to: Simon Glass
Headers show
Series binman: Rework compression support | expand

Commit Message

Stefan Herbrechtsmeier Aug. 19, 2022, 2:25 p.m. UTC
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>
Reviewed-by: Simon Glass <sjg@chromium.org>

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

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

(no changes since v5)

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(+)

Comments

Simon Glass Aug. 20, 2022, 9:33 p.m. UTC | #1
On Fri, 19 Aug 2022 at 08:26, 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>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> ---
> Instead of the for loop it is possible to use Parameterized [1] testing.
>
> [1] https://github.com/wolever/parameterized
>
> (no changes since v5)
>
> 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(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass Aug. 21, 2022, 12:10 a.m. UTC | #2
On Fri, 19 Aug 2022 at 08:26, 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>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> ---
> Instead of the for loop it is possible to use Parameterized [1] testing.
>
> [1] https://github.com/wolever/parameterized
>
> (no changes since v5)
>
> 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(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!
diff mbox series

Patch

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()