From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2fGYGm8l32q6xxsAWB0awg (envelope-from ) for ; Mon, 26 Oct 2026 06:03:27 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=vrany.io header.i=@vrany.io header.a=rsa-sha256 header.s=protonmail header.b=ctHBUw1P; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 67E98378002; Mon, 26 Oct 2026 06:03:27 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 667021E007 for ; Mon, 26 Oct 2026 06:03:24 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 195B94BA23C4 for ; Mon, 26 Oct 2026 10:03:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 195B94BA23C4 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=vrany.io header.i=@vrany.io header.a=rsa-sha256 header.s=protonmail header.b=ctHBUw1P Received: from mail-10625.protonmail.ch (mail-10625.protonmail.ch [79.135.106.25]) by sourceware.org (Postfix) with ESMTPS id DCF7F4BA2E36 for ; Mon, 26 Oct 2026 10:02:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCF7F4BA2E36 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=vrany.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrany.io ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DCF7F4BA2E36 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=79.135.106.25 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793008946; cv=none; b=tuUL7C5nReDFm2pntuc9piYG4mu5EYEWV3ndrwGJXr8rkNeS4WpgmfF3S/rv9qV7pnjn2JB61KyJY/Y6EoHLx7/+Uj4bP5CHXeIWAMcdcnL7lqLF59VE2zeAM7PpfgcxUGwFObR7lHCYWkVPexdwfACjwceTj/lb4zR3PqiaTgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793008946; c=relaxed/simple; bh=Mizyc9tpEnid25WsGuxnw3LF1Gkpfl9VN/Cw0mErNYI=; h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version; b=KsVJrGBE3RPsgn862W7sLL7nxWAoXDe50eOuBTmzQcYSvtsfQ4y3aptfxByZsQikTInG5N4DaHjVpKwNoDNHqMQzOVV3tVxtuzXipaN98NXBqDXlnOgrcW+sdJRmj5f4TT5mfzk6Z8kMfdIajksFO3OKHcR8uPA6ejOO6I1UUiM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=vrany.io header.i=@vrany.io header.a=rsa-sha256 header.s=protonmail header.b=ctHBUw1P DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DCF7F4BA2E36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrany.io; s=protonmail; t=1793008934; x=1793268134; bh=rQ9PqLUnc8FqlM0x7hxIr0sQ41037pU+rnJ9IaUjOYA=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=ctHBUw1PtaxAZRhJhCK+i44GI54jlCHjOGSp0t5aD1gpgwlXfc3IhRXVzSuBbSNIW beubftNczFPfbVCwdNu66/xmZVOXS3itWCX41plm8LAF6z8zlMoYfKrtXz9/clhY0y Tth7aUNmnXyPesYh2dYUN1fq62+6Xj/hscpjH2MifH/XXhvHI/CWxMacVQ9Z95W6Xm f7VMp5Q/AxToq232bJjN1tKOSNmyqO7Lhwv95MJyVqLC6HpnbSwXqh9MjQ9Z+6a0fd qO8UVs8FSGGj4i38YZ9R+I9XBD5F7V1J12iy/wqOBhCd/F4aLBwkHUNemrqgbVbnMd H3ZdQ0Qrxytgg== Date: Mon, 26 Oct 2026 10:02:10 +0000 To: gdb-patches@sourceware.org From: Jan Vrany Cc: Jan Vrany Subject: [PATCH] gdb/testsuite: add support for running tests using QEMU Message-ID: <20261026100153.1789950-1-jan@vrany.io> Feedback-ID: 40767693:user:proton X-Pm-Message-ID: 6aa3383e5d6bb3785f810359689b83a26e007a45 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org While debugging failing RISC-V tests, I found myself once again in a situation where running tests easily using QEMU usermode emulation would be useful. Since this is something that resurfaces every now and then [1], I decided to have another stab at it. This commit adds a new "board" file - qemu.exp - that allows running tests using QEMU usermode emulation. The main goal is to make it easier to test changes on multiple different architectures. However using QEMU to run tests is no substitute for running tests on real hardware (or in a VM). See limitations below. The implementation based on simavr.exp and on an earlier patch by Zeck S [2] and somewhat simplified. Unlike previous attempts, test programs are no compiled statically in order to support broader set of testcases. It also supports more targets (new targets should be easy to add). Not all test that pass on real hardware pass when run under usermode QEMU. Some failures stem from limitations of QEMU's GDB stub - it does not support non-stop mode, multiple threads, hardware watchpoints. In some other cases GDB crashes, perhaps due to a bug in either GDB or QEMU. I have made no attempt to investigate these failures in detail. Running all tests in gdb.base on x86_64 Linux using qemu-aarch64 I got: # of unexpected core files=091 # of expected passes=0966088 # of unexpected failures=091431 # of expected failures=0914 # of known failures=09=0925 # of untested testcases=0914 # of unresolved testcases=0925 # of unsupported tests=09227 # of paths in test names=0938 # of duplicate test names=095 Running same set of tests using qemu-x86_64 I got: # of unexpected core files=091 # of expected passes=0964988 # of unexpected failures=092527 # of expected failures=0920 # of known failures=09=0929 # of untested testcases=098 # of unresolved testcases=095 # of unsupported tests=09174 # of paths in test names=097 # of duplicate test names=095 [1]: https://inbox.sourceware.org/gdb/938d2b5574b94d9584b758eee3c0c064@ti.c= om/ [2]: https://inbox.sourceware.org/gdb-patches/20231204024634.419445-3-zeck6= 54321@gmail.com/ Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D33590 --- gdb/testsuite/boards/qemu.exp | 195 ++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 gdb/testsuite/boards/qemu.exp diff --git a/gdb/testsuite/boards/qemu.exp b/gdb/testsuite/boards/qemu.exp new file mode 100644 index 00000000000..2d15294d369 --- /dev/null +++ b/gdb/testsuite/boards/qemu.exp @@ -0,0 +1,195 @@ +# Copyright 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is a dejagnu "board file" and is used to run the testsuite +# using QEMU's usermode emulation. Use --target to specify desired target. +# +# To use specific QEMU, pass custom options to QEMU or target toolchain to= use, +# set environment variable QEMU, QEMU_FLAGS or CROSS (see examples below). +# +# Example usage: +# +# make check RUNTESTFLAGS=3D'--target=3Driscv64-unknown-linux-gnu --ta= rget_board=3Dqemu' +# +# make check QEMU=3Dqemu-arm CROSS=3D/opt/gcc-8-armhf/bin/arm-linux-gn= ueabihf- \ +# RUNTESTFLAGS=3D'--target=3Darm-unknown-linux-gnueabihf --target_b= oard=3Dqemu' +# + +# Load this for "gdb_target_cmd_ext" +load_lib gdbserver-support.exp + +# +# Setup +# +set qemu "" +set qemu_flags "" +set cross "" + +switch -glob $target_triplet { + "x86_64-*-linux-gnu" { +=09set qemu "qemu-x86_64" +=09set cross "x86_64-linux-gnu-" + } + "riscv64-*-linux-gnu" { +=09set qemu "qemu-riscv64" +=09set cross "riscv64-linux-gnu-" + } + "aarch64-*-linux-gnu" { +=09set qemu "qemu-aarch64" +=09set cross "aarch64-linux-gnu-" + } + "arm-*-linux-gnueabihf" { +=09set qemu "qemu-arm" +=09set cross "arm-linux-gnueabihf-" + } + "powerpc-*-linux-gnu" { +=09set qemu "qemu-ppc" +=09set cross "powerpc-linux-gnu-" + } + "powerpc64le-*-linux-gnu" { +=09set qemu "qemu-ppc64le" +=09set cross "powerpc64le-linux-gnu-" + } + # + # Add more here if needed. + # + default { +=09error "Target $target_triplet not yet supported by board" + } +} + +# +# Allow user to specify QEMU binary and/or custom options by setting +# QEMU and/or QEMU_FLAGS environment variables. +# +if [info exists ::env(QEMU)] { + set qemu $::env(QEMU) +} +if [info exists ::env(QEMU_FLAGS)] { + set qemu_flags $::env(QEMU_FLAGS) +} + +# +# Allow user to specify target toolchain by setting CROSS environment vari= able +# +if [info exists ::env(CROSS)] { + set cross $::env(CROSS) +} + +set qemu_spawn_id "" + +set_board_info compiler "${cross}gcc" +set_board_info c++compiler "${cross}g++" + +set_board_info use_gdb_stub 1 +set_board_info gdb_protocol "remote" +set_board_info gdb,do_reload_on_run 1 +set_board_info gdb,nofileio 1 +set_board_info exit_is_reliable 1 +# QEMU does not support HW watchpoints +set_board_info gdb,no_hardware_watchpoints 1 + +# +# Helper function to run QEMU. Returns the port number on which QEMU +# stub listens. +# +proc qemu_spawn { file inferior_args } { + global qemu_spawn_id + global qemu + global qemu_flags + + # + # Close any previous QEMU instance. + # + if { $qemu_spawn_id !=3D "" } { +=09verbose -log "qemu: closing previous spawn id $qemu_spawn_id" +=09if [catch { close -i $qemu_spawn_id } !=3D 0] { +=09 warning "qemu: failed to close connection to previous qemu instance= " +=09} + +=09# some tests get QEMU/its gdb stub +=09# into a state where the process doesn't want to die +=09# so -nowait to not hang the entire test run +=09wait -nowait -i $qemu_spawn_id +=09set qemu_spawn_id "" + } + + + # + # Run QEMU. + # + while 1 { +=09set portnum [expr {1024+round(rand()*(65535-1024))}] +=09set cmd "spawn -noecho $qemu $qemu_flags -g $portnum $file $inferior_ar= gs" + +=09verbose -log "Spawning qemu: $cmd" +=09eval $cmd +=09set qemu_spawn_id $spawn_id + +=09# QEMU stub doesn't do inferior I/O through GDB. But we can +=09# talk to the program using QEMU's tty instead. +=09global inferior_spawn_id +=09set inferior_spawn_id $spawn_id + +=09expect { +=09 -i $qemu_spawn_id +=09 -timeout 1 +=09 -re "$qemu:.*Address already in use.*" { +=09=09# Port already in use. Cleanup and retry. +=09=09verbose -log "Port $portnum is already in use." +=09=09if [catch { close -i $qemu_spawn_id } !=3D 0] { +=09=09 warning "failed to terminate QEMU instance" +=09=09} +=09=09wait -i $qemu_spawn_id +=09=09continue +=09 } +=09} + +=09verbose -log "QEMU spawned with spawn id $qemu_spawn_id, pid [exp_pid $= qemu_spawn_id], stub listening at $portnum" +=09break + } + + return $portnum +} + + +# +# gdb_reload -- load a file into the target. +# +proc gdb_reload { {inferior_args {}} } { + global last_loaded_file + set portnum [qemu_spawn $last_loaded_file $inferior_args] + + if { [gdb_target_cmd_ext "remote" ":$portnum"] =3D=3D 2 } { +=09unsupported +=09# QEMU does not support non-stop mode. Exit here to avoid subseqn=3Duen= t +=09# failts / timeouts. +=09exit 0 + } + return 0 +} + +proc mi_gdb_target_load { } { + global last_loaded_file + set portnum [qemu_spawn $last_loaded_file ""] + + if { [mi_gdb_target_cmd "remote" ":$portnum"] !=3D 0 } { +=09return -1 + } + + return 0 +} + +set GDBFLAGS "${GDBFLAGS} -iex \"set auto-connect-native-target off\"" --=20 2.53.0