On 28/02/2025 11.27, Daniel P. Berrangé wrote:
If the QEMU binary was built for a 32-bit ELF target we cannot run the
memory address space tests as they all require ability to address more
RAM that can be represented on 32-bit.

We can't use a decorator to skip the tests as we need setUp() to run to
pick the QEMU binary, thus we must call a method at the start of each
test to check and skip it. The functional result is effectively the
same as using a decorator, just less pretty. This code will go away when
32-bit hosts are full dropped from QEMU.

The code allows any non-ELF target since all macOS versions supported
at 64-bit only and we already dropped support for 32-bit Windows.

Signed-off-by: Daniel P. Berrangé <berra...@redhat.com>
---
  tests/functional/test_mem_addr_space.py | 34 +++++++++++++++++++++++++
  1 file changed, 34 insertions(+)

diff --git a/tests/functional/test_mem_addr_space.py 
b/tests/functional/test_mem_addr_space.py
index bb0cf062ca..c8bde77e51 100755
--- a/tests/functional/test_mem_addr_space.py
+++ b/tests/functional/test_mem_addr_space.py
@@ -20,6 +20,25 @@ class MemAddrCheck(QemuSystemTest):
      # this reason.
      DELAY_Q35_BOOT_SEQUENCE = 1
+ # This helper can go away when the 32-bit host deprecation
+    # turns into full & final removal of support.
+    def ensure_64bit_binary(self):
+        with open(self.qemu_bin, "rb") as fh:
+            ident = fh.read(4)
+
+            # "\x7fELF"
+            if ident != bytes([0x7f, 0x45, 0x4C, 0x46]):
+                # Non-ELF file implies macOS or Windows which
+                # we already assume to be 64-bit only
+                return
+
+            # bits == 1 -> 32-bit; bits == 2 -> 64-bit
+            bits = int.from_bytes(fh.read(1))

This unfortunately fails in the Centos CI job (so I guess there's something different with Python 3.8):

 https://gitlab.com/thuth/qemu/-/jobs/9316861212#L131

Looking at the test log:

Traceback (most recent call last):
File "/builds/thuth/qemu/tests/functional/test_mem_addr_space.py", line 335, in test_phybits_ok_tcg_q35_intel_cxl
    self.ensure_64bit_binary()
File "/builds/thuth/qemu/tests/functional/test_mem_addr_space.py", line 36, in ensure_64bit_binary
    bits = int.from_bytes(fh.read(1))
TypeError: from_bytes() missing required argument 'byteorder' (pos 2)

Could you please have a look?

 Thanks,
  Thomas


Reply via email to