Re: [PATCH v3 13/13] tests/functional: Add hexagon semihosting systests

Philippe Mathieu-Daudé <[email protected]>
Newsgroups gmane.comp.emulators.qemu
Message-ID <[email protected]>
Hi Matheus,

On 20/7/26 19:41, Matheus Tavares Bernardino wrote:
> From: Brian Cain <[email protected]>
> 
> Signed-off-by: Brian Cain <[email protected]>
> Reviewed-by: Pierrick Bouvier <[email protected]>
> Signed-off-by: Matheus Tavares Bernardino <[email protected]>
> ---
>   tests/functional/hexagon/meson.build      |   5 +
>   tests/functional/hexagon/test_systests.py | 110 ++++++++++++++++++++++
>   2 files changed, 115 insertions(+)
>   create mode 100755 tests/functional/hexagon/test_systests.py


> +class SysTestsStandaloneTests(QemuSystemTest):
> +    SYSTEST_TIMEOUT_SEC = 30
> +
> +    ASSET_TARBALL = Asset(
> +        "https://github.com/qualcomm/qemu-hexagon-testing/releases/download/v0.2.11/systests_standalone.tar.gz",
> +        "b5777aa65245de7710a7a08d717953c1362be7c8b60d9014c9fee8b17610ad1c",
> +    )
> +
> +    def setUp(self):
> +        super().setUp()
> +        self.archive_extract(self.ASSET_TARBALL)
> +
> +    def binary(self, name):
> +        """Return the full path to binary *name* inside bin dir."""

Hmm this is scratch_file() contract, not sure if worth documenting.

> +        path = self.scratch_file(*_TARBALL_BIN_PATH, name)
> +        self.assertTrue(os.path.exists(path))
> +        return path
> +
> +    def run_exit_zero(self, binary_name, *extra_args, machine="V66G_1024"):
> +        """Launch *binary_name* and assert it exits with code 0.
> +
> +        :param binary_name: name of the binary inside bin dir.
> +        :param extra_args: optional pairs of (flag, value) strings passed
> +            to set_vm_arg(), e.g. ('-append', 'myarg').

Why document that in a test?
> +        :param machine: QEMU machine type (default "V66G_1024").
> +        """
> +        self.set_machine(machine)
> +        self.set_vm_arg("-display", "none")
> +        self.set_vm_arg("-kernel", self.binary(binary_name))
> +        for flag, value in zip(extra_args[::2], extra_args[1::2]):
> +            self.set_vm_arg(flag, value)
> +        self.vm.launch()
> +        self.vm.wait(timeout=60.0)
> +        self.assertEqual(self.vm.exitcode(), 0,
> +                         f"Test {binary_name} exited with "
> +                         f"code {self.vm.exitcode()}, expected 0")
> +
> +    def run_console_pattern(self, binary_name, pattern, *extra_args,
> +                            machine="V66G_1024"):
> +        """Launch *binary_name* and wait for *pattern* on the semihosting console.
> +
> +        :param binary_name: name of the binary inside bin dir.
> +        :param pattern: string pattern to wait for via wait_for_console_pattern.
> +        :param extra_args: optional pairs of (flag, value) strings passed
> +            to set_vm_arg(), e.g. ('-append', 'myarg').

Sorry, this is not useful, just noise making the review more painful.

> +        :param machine: QEMU machine type (default "V66G_1024").
> +        """
> +        self.set_machine(machine)
> +        self.set_vm_arg("-display", "none")
> +        self.set_vm_arg("-kernel", self.binary(binary_name))
> +        for flag, value in zip(extra_args[::2], extra_args[1::2]):
> +            self.set_vm_arg(flag, value)
> +        self.vm.set_console(semihosting=True)
> +        self.vm.launch()
> +        try:
> +            wait_for_console_pattern(self, pattern)
> +        finally:
> +            self.vm.kill()
> +
> +    def test_fopen(self):
> +        """fopen reads a file passed via --append and verifies its contents."""
> +        import tempfile
> +        # The fopen binary has a short cmdline buffer; use a short path.
> +        dummy = os.path.join(tempfile.gettempdir(), "qemu_fopen_test.so")
> +        with open(dummy, "w") as f:
> +            f.write("valid\n")
> +        self.run_exit_zero("fopen", "-append", dummy)
> +
> +    def test_ftrunc(self):
> +        """ftrunc truncates _testfile_ftrunc from 6 bytes to 1 byte."""
> +        ftrunc_path = self.scratch_file("_testfile_ftrunc")
> +        with open(ftrunc_path, "w") as f:
> +            f.write("valid\n")
> +        # Sleep 1 s so mtime change is observable
> +        time.sleep(1)
> +        self.run_exit_zero("ftrunc", "-append", ftrunc_path)
> +        self.assertEqual(os.path.getsize(ftrunc_path), 1,
> +                         "_testfile_ftrunc should be 1 byte after ftrunc")
> +
> +    def test_access(self):
> +        """access checks R_OK|W_OK on _testfile_access."""
> +        testfile = self.scratch_file("_testfile_access")
> +        with open(testfile, "w") as f:
> +            f.write("valid\n")
> +        self.run_exit_zero("access", "-append", testfile)
> +
> +    def test_semihost(self):
> +        self.run_console_pattern("semihost", "PASS", "-append", "arg1", "arg2")
> +
> +if __name__ == "__main__":
> +    QemuSystemTest.main()

Did you run this test on a big-endian host? I'm suspicious about some
guest to host conversions.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.