]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
tests/functional/qemu_test: Use Python hashlib instead of external programs
authorThomas Huth <thuth@redhat.com>
Tue, 10 Sep 2024 20:17:42 +0000 (22:17 +0200)
committerThomas Huth <thuth@redhat.com>
Wed, 11 Sep 2024 07:49:12 +0000 (09:49 +0200)
Some systems (like OpenBSD) do not have the sha256sum or sha512sum programs
installed by default, or use different names for those. Use the Python
hashlib instead so we don't have to rely on the external programs.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20240910201742.239559-1-thuth@redhat.com>
Reviewed-by: Brian Cain <bcain@quicinc.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
tests/functional/qemu_test/asset.py

index d3be2aff82934b84f04fc204ceb6a9833c9adc40..3ec429217e596d43e3a116218272aa3aff8cda0b 100644 (file)
@@ -43,15 +43,21 @@ class Asset:
         if self.hash is None:
             return True
         if len(self.hash) == 64:
-            sum_prog = 'sha256sum'
+            hl = hashlib.sha256()
         elif len(self.hash) == 128:
-            sum_prog = 'sha512sum'
+            hl = hashlib.sha512()
         else:
             raise Exception("unknown hash type")
 
-        checksum = subprocess.check_output(
-            [sum_prog, str(cache_file)]).split()[0]
-        return self.hash == checksum.decode("utf-8")
+        # Calculate the hash of the file:
+        with open(cache_file, 'rb') as file:
+            while True:
+                chunk = file.read(1 << 20)
+                if not chunk:
+                    break
+                hl.update(chunk)
+
+        return  hl.hexdigest()
 
     def valid(self):
         return self.cache_file.exists() and self._check(self.cache_file)