diff options
Diffstat (limited to 'tests/functional/qemu_test')
-rw-r--r-- | tests/functional/qemu_test/asset.py | 3 | ||||
-rw-r--r-- | tests/functional/qemu_test/tuxruntest.py | 10 | ||||
-rw-r--r-- | tests/functional/qemu_test/utils.py | 21 |
3 files changed, 32 insertions, 2 deletions
diff --git a/tests/functional/qemu_test/asset.py b/tests/functional/qemu_test/asset.py index e47bfac035..f126cd5863 100644 --- a/tests/functional/qemu_test/asset.py +++ b/tests/functional/qemu_test/asset.py @@ -8,6 +8,7 @@ import hashlib import logging import os +import stat import subprocess import sys import unittest @@ -143,6 +144,8 @@ class Asset: raise Exception("Hash of %s does not match %s" % (self.url, self.hash)) tmp_cache_file.replace(self.cache_file) + # Remove write perms to stop tests accidentally modifying them + os.chmod(self.cache_file, stat.S_IRUSR | stat.S_IRGRP) self.log.info("Cached %s at %s" % (self.url, self.cache_file)) return str(self.cache_file) diff --git a/tests/functional/qemu_test/tuxruntest.py b/tests/functional/qemu_test/tuxruntest.py index 904da6f609..f05aa96ad7 100644 --- a/tests/functional/qemu_test/tuxruntest.py +++ b/tests/functional/qemu_test/tuxruntest.py @@ -10,6 +10,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later import os +import stat import time from qemu_test import QemuSystemTest @@ -77,12 +78,17 @@ class TuxRunBaselineTest(QemuSystemTest): kernel_image = kernel_asset.fetch() disk_image_zst = rootfs_asset.fetch() + disk_image = self.workdir + "/rootfs.ext4" + run_cmd([self.zstd, "-f", "-d", disk_image_zst, - "-o", self.workdir + "/rootfs.ext4"]) + "-o", disk_image]) + # zstd copies source archive permissions for the output + # file, so must make this writable for QEMU + os.chmod(disk_image, stat.S_IRUSR | stat.S_IWUSR) dtb = dtb_asset.fetch() if dtb_asset is not None else None - return (kernel_image, self.workdir + "/rootfs.ext4", dtb) + return (kernel_image, disk_image, dtb) def prepare_run(self, kernel, disk, drive, dtb=None, console_index=0): """ diff --git a/tests/functional/qemu_test/utils.py b/tests/functional/qemu_test/utils.py index 2a1cb60d38..1bf1c410d5 100644 --- a/tests/functional/qemu_test/utils.py +++ b/tests/functional/qemu_test/utils.py @@ -15,6 +15,27 @@ import shutil import subprocess import tarfile +""" +Round up to next power of 2 +""" +def pow2ceil(x): + return 1 if x == 0 else 2**(x - 1).bit_length() + +def file_truncate(path, size): + if size != os.path.getsize(path): + with open(path, 'ab+') as fd: + fd.truncate(size) + +""" +Expand file size to next power of 2 +""" +def image_pow2ceil_expand(path): + size = os.path.getsize(path) + size_aligned = pow2ceil(size) + if size != size_aligned: + with open(path, 'ab+') as fd: + fd.truncate(size_aligned) + def archive_extract(archive, dest_dir, member=None): with tarfile.open(archive) as tf: if hasattr(tarfile, 'data_filter'): |