Message ID | 20250107165208.743958-20-alex.bennee@linaro.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | testing/next: functional tests, qtest clocks, vm and keymaps (pre-PR) | expand |
On 07/01/2025 17.51, Alex Bennée wrote: > Rather than using the python library (which has a different API > anyway) lets just call the binary. zstdtools is already in out > qemu.yml so all test containers should have it around. Tests should > still use @skipIfMissingCommands('zstd') to gracefully handle when > only minimal dependencies have been installed. Thanks, sounds like a good idea to have a common function for this. Just a comment below... > Signed-off-by: Alex Bennée <alex.bennee@linaro.org> > --- > tests/functional/qemu_test/uncompress.py | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/tests/functional/qemu_test/uncompress.py b/tests/functional/qemu_test/uncompress.py > index 6d02ded066..404eee1f83 100644 > --- a/tests/functional/qemu_test/uncompress.py > +++ b/tests/functional/qemu_test/uncompress.py > @@ -12,6 +12,7 @@ > import os > import shutil > from urllib.parse import urlparse > +from subprocess import check_call, CalledProcessError > > from .asset import Asset > > @@ -38,6 +39,18 @@ def lzma_uncompress(xz_path, output_path): > os.remove(output_path) > raise > > +def zstd_uncompress(zstd_path, output_path): > + if os.path.exists(output_path): > + return > + > + try: > + check_call(['zstd', "-f", "-d", zstd_path, > + "-o", output_path]) > + except CalledProcessError as e: > + os.remove(output_path) > + raise Exception( > + f"Unable to decompress zstd file {zstd_path} with {e}") from e In tests/functional/qemu_test/tuxruntest.py we had to add a os.chmod(..., stat.S_IRUSR | stat.S_IWUSR) to make sure that the write-protected compressed assets are usable afterwards... Would it make sense to add this here, too, so that the callers don't have to do it on their own? Also, could you maybe change tests/functional/qemu_test/tuxruntest.py accordingly to use this new function here? Thanks, Thomas > ''' > @params compressed: filename, Asset, or file-like object to uncompress > @params uncompressed: filename to uncompress into > @@ -59,6 +72,8 @@ def uncompress(compressed, uncompressed, format=None): > lzma_uncompress(str(compressed), uncompressed) > elif format == "gz": > gzip_uncompress(str(compressed), uncompressed) > + elif format == "zstd": > + zstd_uncompress(str(compressed), uncompressed) > else: > raise Exception(f"Unknown compression format {format}") > > @@ -79,5 +94,7 @@ def guess_uncompress_format(compressed): > return "xz" > elif ext == ".gz": > return "gz" > + elif ext == ".zstd": > + return "zstd" > else: > raise Exception(f"Unknown compression format for {compressed}")
diff --git a/tests/functional/qemu_test/uncompress.py b/tests/functional/qemu_test/uncompress.py index 6d02ded066..404eee1f83 100644 --- a/tests/functional/qemu_test/uncompress.py +++ b/tests/functional/qemu_test/uncompress.py @@ -12,6 +12,7 @@ import os import shutil from urllib.parse import urlparse +from subprocess import check_call, CalledProcessError from .asset import Asset @@ -38,6 +39,18 @@ def lzma_uncompress(xz_path, output_path): os.remove(output_path) raise +def zstd_uncompress(zstd_path, output_path): + if os.path.exists(output_path): + return + + try: + check_call(['zstd', "-f", "-d", zstd_path, + "-o", output_path]) + except CalledProcessError as e: + os.remove(output_path) + raise Exception( + f"Unable to decompress zstd file {zstd_path} with {e}") from e + ''' @params compressed: filename, Asset, or file-like object to uncompress @params uncompressed: filename to uncompress into @@ -59,6 +72,8 @@ def uncompress(compressed, uncompressed, format=None): lzma_uncompress(str(compressed), uncompressed) elif format == "gz": gzip_uncompress(str(compressed), uncompressed) + elif format == "zstd": + zstd_uncompress(str(compressed), uncompressed) else: raise Exception(f"Unknown compression format {format}") @@ -79,5 +94,7 @@ def guess_uncompress_format(compressed): return "xz" elif ext == ".gz": return "gz" + elif ext == ".zstd": + return "zstd" else: raise Exception(f"Unknown compression format for {compressed}")
Rather than using the python library (which has a different API anyway) lets just call the binary. zstdtools is already in out qemu.yml so all test containers should have it around. Tests should still use @skipIfMissingCommands('zstd') to gracefully handle when only minimal dependencies have been installed. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- tests/functional/qemu_test/uncompress.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)