From nobody Tue Apr 7 19:50:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1773267253; cv=none; d=zohomail.com; s=zohoarc; b=bh4TUrhdFh5/Pr9dV5XPMlIYeBsTxXkkBkiHD01T5qYrtX8SXDZypXKUTGcWKEDO3vUU+8if+prsCy3vYKHnVDNi5waacPtWbolNH8LMBE3mMa89rVdjDa/TjBZAdhxJSxkbnMkLUkOF299PLVFg2GER+kqBkPM6rnBiz4JIBJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773267253; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4bUxM2kWtbIydGXKb0MroLDjr7nUS9i7JFN2WLUWOOY=; b=G8qbgwRDkHvW59QJzQYdJf2dh1ZrJvIqT7zt5VKQf4LjYEN1M19dDWX2e0uHoeX+YYSgT/KlpZXYy6WQ61ihkLvFuy/vLkBzAY/qs1gwcA6R2zvbDxhYwBYbKpJXuxqo/tNazC7Bl4wEe29CCHB1KEn8F1ggHSWNurs2GxDHxBs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773267253230344.53150090791576; Wed, 11 Mar 2026 15:14:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0Ro4-0000sM-Pl; Wed, 11 Mar 2026 18:13:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w0Ro3-0000rn-9r for qemu-devel@nongnu.org; Wed, 11 Mar 2026 18:13:31 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w0Rnz-0004yi-8V for qemu-devel@nongnu.org; Wed, 11 Mar 2026 18:13:30 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5A0845C226; Wed, 11 Mar 2026 22:13:25 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6BCF83FC44; Wed, 11 Mar 2026 22:13:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WGfPDATpsWnCeQAAD6G6ig (envelope-from ); Wed, 11 Mar 2026 22:13:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1773267205; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4bUxM2kWtbIydGXKb0MroLDjr7nUS9i7JFN2WLUWOOY=; b=YLi5aIVe1cVG3IcnY6K1iUuuahyKJgZ5CIFvgTqAjQmdXgNmmyiS1x+2yxDbdiqGfZgSHu XoqD7pUeyiDNYjaUzGzqj1ijdklIAAd9uIeNmTbpFhfu06Oh9Racj2QXuTHyR9JJg6lEYV 1uHOrsGIeIWK3q8/UWL/uYeQFKeau6g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1773267205; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4bUxM2kWtbIydGXKb0MroLDjr7nUS9i7JFN2WLUWOOY=; b=QGzDgzh7mtlV/+rPprY9Jd1Avv8oTtD/5nOJhmVp8eB81MA+INpDM+XN7EYu911cHiXBKM 77C96LUtVttcjdAA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1773267205; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4bUxM2kWtbIydGXKb0MroLDjr7nUS9i7JFN2WLUWOOY=; b=YLi5aIVe1cVG3IcnY6K1iUuuahyKJgZ5CIFvgTqAjQmdXgNmmyiS1x+2yxDbdiqGfZgSHu XoqD7pUeyiDNYjaUzGzqj1ijdklIAAd9uIeNmTbpFhfu06Oh9Racj2QXuTHyR9JJg6lEYV 1uHOrsGIeIWK3q8/UWL/uYeQFKeau6g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1773267205; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4bUxM2kWtbIydGXKb0MroLDjr7nUS9i7JFN2WLUWOOY=; b=QGzDgzh7mtlV/+rPprY9Jd1Avv8oTtD/5nOJhmVp8eB81MA+INpDM+XN7EYu911cHiXBKM 77C96LUtVttcjdAA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 1/3] tests/qtest/vhost-user-test: Use g_timeout_add() to schedule connect Date: Wed, 11 Mar 2026 19:13:18 -0300 Message-ID: <20260311221320.22112-2-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260311221320.22112-1-farosas@suse.de> References: <20260311221320.22112-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,linaro.org:email]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_TWO(0.00)[2]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[] Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1773267255856154100 Content-Type: text/plain; charset="utf-8" From: Peter Maydell In vhost-user-test, we currently create a new g_thread to run the connect_thread() function. This function sleeps for 1 second, and then calls test_server_create_chr() to create and configure a chardev: chr =3D qemu_chr_new(server->chr_name, chr_path, server->context); g_assert(chr); qemu_chr_fe_init(&server->chr, chr, &error_abort); qemu_chr_fe_set_handlers(&server->chr, chr_can_read, chr_read, chr_event, NULL, server, server->context, true= ); This has a race condition, because when we set the 'reconnect-ms=3D1000' option on the chardev the socket chardev's implementation handles the connect asynchronously, via a background thread and a callback invoked in the main-loop thread. This means that that callback and the test_server_create_chr() call to qemu_chr_fe_set_handlers() can both enter the char-socket code simultaneously. The result is random assertion failures and memory leaks reported by the clang address-sanitizer. Fix this by using g_timeout_source_new() to set up a GSource that will run test_server_connect() on the main-loop thread. This ensures it can't execute in parallel with the callback that the socket chardev sets up. This is similar to how we already handle the reconnect_cb() in test_reconnect(). Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas Signed-off-by: Fabiano Rosas --- tests/qtest/vhost-user-test.c | 36 ++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index d2bb21d5b9..c8b5f8ff71 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -930,26 +930,42 @@ reconnect_cb(gpointer user_data) return FALSE; } =20 -static gpointer -connect_thread(gpointer data) +static gboolean connect_cb(gpointer user_data) { - TestServer *s =3D data; + TestServer *s =3D user_data; =20 - /* wait for qemu to start before first try, to avoid extra warnings */ - g_usleep(G_USEC_PER_SEC); test_server_connect(s); =20 - return NULL; + /* We only need to be called once */ + return G_SOURCE_REMOVE; +} + +/* Initial delay before connect, in milliseconds (1 second) */ +#define INITIAL_CONNECT_DELAY_MS (1 * 1000) + +static void test_schedule_connect(TestServer *s) +{ + /* + * Wait for a bit for QEMU to start before we first try to connect, + * to avoid extra warnings. We must run the "connect" on the + * main-loop thread so it doesn't race with a callback that + * the socket-chardev sets up on the main-loop. + */ + GSource *src =3D g_timeout_source_new(INITIAL_CONNECT_DELAY_MS); + g_source_set_callback(src, connect_cb, s, NULL); + g_source_attach(src, s->context); + g_source_unref(src); } =20 static void *vhost_user_test_setup_reconnect(GString *cmd_line, void *arg) { TestServer *s =3D test_server_new("reconnect", arg); =20 - g_thread_unref(g_thread_new("connect", connect_thread, s)); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); s->vu_ops->append_opts(s, cmd_line, ",server=3Don"); =20 + test_schedule_connect(s); + g_test_queue_destroy(vhost_user_test_cleanup, s); =20 return s; @@ -983,10 +999,11 @@ static void *vhost_user_test_setup_connect_fail(GStri= ng *cmd_line, void *arg) =20 s->test_fail =3D true; =20 - g_thread_unref(g_thread_new("connect", connect_thread, s)); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); s->vu_ops->append_opts(s, cmd_line, ",server=3Don"); =20 + test_schedule_connect(s); + g_test_queue_destroy(vhost_user_test_cleanup, s); =20 return s; @@ -998,10 +1015,11 @@ static void *vhost_user_test_setup_flags_mismatch(GS= tring *cmd_line, void *arg) =20 s->test_flags =3D TEST_FLAGS_DISCONNECT; =20 - g_thread_unref(g_thread_new("connect", connect_thread, s)); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); s->vu_ops->append_opts(s, cmd_line, ",server=3Don"); =20 + test_schedule_connect(s); + g_test_queue_destroy(vhost_user_test_cleanup, s); =20 return s; --=20 2.51.0 From nobody Tue Apr 7 19:50:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1773267276; cv=none; d=zohomail.com; s=zohoarc; b=YZ67CVbWWqVW1jwv6gTT5JoUb2Lw/wo1cSnq/jq04QX2JzCgUlZZmA776WPUiuDVQux0oHbWiPgVhCgO8fr5KtW7oTWRVxt0VJ7YHe0PinmErttHRL9z553l+gOB1xqXGFSlkuOCUORlnVQmTQVk7ym+BxkV/rQ/z4vhYMsChZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773267276; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XXKCgnqGyH/v/Xg2Zt+YIbaZeNFOItL55qSzGq0aF5w=; b=Jhr7CBoQqpS+fujRqlp4pzf7uePVe+EBOTejhZCk092RLKbGJBtU8hljk6hTOu+obXtPM6zwO2IrA14g0PGJ6BWpvWzxwENGHmHp0VrDikDVtpEzu5KakdCwrBuKY2l2zvp7YntuxxVpAaTrGNiLe4v+s6r1/wkxfjc11dBS1g0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177326727663518.580935019474964; Wed, 11 Mar 2026 15:14:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0RoD-0000vc-78; Wed, 11 Mar 2026 18:13:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w0RoB-0000us-6u for qemu-devel@nongnu.org; Wed, 11 Mar 2026 18:13:39 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w0Ro7-0004zu-NS for qemu-devel@nongnu.org; Wed, 11 Mar 2026 18:13:37 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B51D44D642; Wed, 11 Mar 2026 22:13:26 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C5BC43FC44; Wed, 11 Mar 2026 22:13:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id QLO8IgXpsWnCeQAAD6G6ig (envelope-from ); Wed, 11 Mar 2026 22:13:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1773267206; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XXKCgnqGyH/v/Xg2Zt+YIbaZeNFOItL55qSzGq0aF5w=; b=k+KXuRzUyd3XzkXm+e1RoZSMpJqx/sywaLVIkx+g+11T0L+Thk2gcfZSQ3Z16P6yfb5R3k OEt3cJ+6Jaqr9hjZ8AkHxuFZES9lIduOiRuIsIKd1gAF25IZJ9KyirryzyxrkXXD2fnVqp miJ6FQA+qTWwbB/LocrPOxSSCO7qpUE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1773267206; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XXKCgnqGyH/v/Xg2Zt+YIbaZeNFOItL55qSzGq0aF5w=; b=NrFZBqBosCFBwzs2wd8Js9Y2A3TxmtuWoSO56ZH4pBxxf6Len7QgdItD//5XmUFz5IS3el gB0/Wpr0FzC42RBg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=k+KXuRzU; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NrFZBqBo DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1773267206; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XXKCgnqGyH/v/Xg2Zt+YIbaZeNFOItL55qSzGq0aF5w=; b=k+KXuRzUyd3XzkXm+e1RoZSMpJqx/sywaLVIkx+g+11T0L+Thk2gcfZSQ3Z16P6yfb5R3k OEt3cJ+6Jaqr9hjZ8AkHxuFZES9lIduOiRuIsIKd1gAF25IZJ9KyirryzyxrkXXD2fnVqp miJ6FQA+qTWwbB/LocrPOxSSCO7qpUE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1773267206; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XXKCgnqGyH/v/Xg2Zt+YIbaZeNFOItL55qSzGq0aF5w=; b=NrFZBqBosCFBwzs2wd8Js9Y2A3TxmtuWoSO56ZH4pBxxf6Len7QgdItD//5XmUFz5IS3el gB0/Wpr0FzC42RBg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 2/3] tests/qtest/test-x86-cpuid-compat: Switch test_cpuid_prop to data-driven Date: Wed, 11 Mar 2026 19:13:19 -0300 Message-ID: <20260311221320.22112-3-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260311221320.22112-1-farosas@suse.de> References: <20260311221320.22112-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:dkim,suse.de:email,linaro.org:email]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_SOME(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: B51D44D642 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1773267278646158501 Content-Type: text/plain; charset="utf-8" From: Peter Maydell In test-x86-cpuid-compat, we allocate memory in add_cpuid_test() which is then freed in the test function test_cpuid_prop(). This means that this memory is leaked if the test is never run, which happens in several cases: * user asks to list tests with -l option * user asks to run only some tests with -p or similar option * we are running a "subprocess" test and glib re-invokes the test binary telling it to run a specific single test As noted in the commit message of commit 93ed7d330321dc, we cannot deal with this by using g_test_add_data_func_full() and passing a free-function, because glib doesn't call that if the test is not executed. Instead, move all the data allocations into test_cpuid_prop(), and pass it a pointer to a struct with the necessary parameters which is a compile-time constant. Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas Signed-off-by: Fabiano Rosas --- tests/qtest/test-x86-cpuid-compat.c | 278 ++++++++++++++++------------ 1 file changed, 164 insertions(+), 114 deletions(-) diff --git a/tests/qtest/test-x86-cpuid-compat.c b/tests/qtest/test-x86-cpu= id-compat.c index be67631a85..fc90a46d37 100644 --- a/tests/qtest/test-x86-cpuid-compat.c +++ b/tests/qtest/test-x86-cpuid-compat.c @@ -44,19 +44,43 @@ static bool qom_get_bool(const char *path, const char *= prop) } =20 typedef struct CpuidTestArgs { - const char *cmdline; + /* test name */ + const char *name; + /* CPU type */ + const char *cpu; + /* CPU features (may be NULL) */ + const char *cpufeat; + /* machine type (may be NULL to use default machine) */ + const char *machine; + /* CPU property to read */ const char *property; + /* expected value of the property */ int64_t expected_value; } CpuidTestArgs; =20 static void test_cpuid_prop(const void *data) { const CpuidTestArgs *args =3D data; + char *cmdline; + char *save; char *path; QNum *value; int64_t val; =20 - qtest_start(args->cmdline); + cmdline =3D g_strdup_printf("-cpu %s", args->cpu); + + if (args->cpufeat) { + save =3D cmdline; + cmdline =3D g_strdup_printf("%s,%s", cmdline, args->cpufeat); + g_free(save); + } + if (args->machine) { + save =3D cmdline; + cmdline =3D g_strdup_printf("-machine %s %s", args->machine, cmdli= ne); + g_free(save); + } + + qtest_start(cmdline); path =3D get_cpu0_qom_path(); value =3D qobject_to(QNum, qom_get(path, args->property)); g_assert(qnum_get_try_int(value, &val)); @@ -65,40 +89,9 @@ static void test_cpuid_prop(const void *data) =20 qobject_unref(value); g_free(path); - g_free((void *)args->cmdline); - g_free((void *)data); + g_free(cmdline); } =20 -static void add_cpuid_test(const char *name, const char *cpu, - const char *cpufeat, const char *machine, - const char *property, int64_t expected_value) -{ - CpuidTestArgs *args =3D g_new0(CpuidTestArgs, 1); - char *cmdline; - char *save; - - if (!qtest_has_cpu_model(cpu)) { - return; - } - cmdline =3D g_strdup_printf("-cpu %s", cpu); - - if (cpufeat) { - save =3D cmdline; - cmdline =3D g_strdup_printf("%s,%s", cmdline, cpufeat); - g_free(save); - } - if (machine) { - save =3D cmdline; - cmdline =3D g_strdup_printf("-machine %s %s", machine, cmdline); - g_free(save); - } - args->cmdline =3D cmdline; - args->property =3D property; - args->expected_value =3D expected_value; - qtest_add_data_func(name, args, test_cpuid_prop); -} - - /* Parameters to a add_feature_test() test case */ typedef struct FeatureTestArgs { /* cmdline to start QEMU */ @@ -249,103 +242,160 @@ static void test_plus_minus(void) g_test_trap_assert_stdout(""); } =20 -int main(int argc, char **argv) -{ - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess", - test_plus_minus_subprocess); - g_test_add_func("/x86/cpuid/parsing-plus-minus", test_plus_minus); - +static const CpuidTestArgs cpuid_tests[] =3D { /* Original level values for CPU models: */ - add_cpuid_test("x86/cpuid/phenom/level", - "phenom", NULL, NULL, "level", 5); - add_cpuid_test("x86/cpuid/Conroe/level", - "Conroe", NULL, NULL, "level", 10); - add_cpuid_test("x86/cpuid/SandyBridge/level", - "SandyBridge", NULL, NULL, "level", 0xd); - add_cpuid_test("x86/cpuid/486/xlevel", - "486", NULL, NULL, "xlevel", 0); - add_cpuid_test("x86/cpuid/core2duo/xlevel", - "core2duo", NULL, NULL, "xlevel", 0x80000008); - add_cpuid_test("x86/cpuid/phenom/xlevel", - "phenom", NULL, NULL, "xlevel", 0x8000001A); - add_cpuid_test("x86/cpuid/athlon/xlevel", - "athlon", NULL, NULL, "xlevel", 0x80000008); - + { + "x86/cpuid/phenom/level", + "phenom", NULL, NULL, "level", 5, + }, + { + "x86/cpuid/Conroe/level", + "Conroe", NULL, NULL, "level", 10, + }, + { + "x86/cpuid/SandyBridge/level", + "SandyBridge", NULL, NULL, "level", 0xd, + }, + { + "x86/cpuid/486/xlevel", + "486", NULL, NULL, "xlevel", 0, + }, + { + "x86/cpuid/core2duo/xlevel", + "core2duo", NULL, NULL, "xlevel", 0x80000008, + }, + { + "x86/cpuid/phenom/xlevel", + "phenom", NULL, NULL, "xlevel", 0x8000001A, + }, + { + "x86/cpuid/athlon/xlevel", + "athlon", NULL, NULL, "xlevel", 0x80000008, + }, /* If level is not large enough, it should increase automatically: */ /* CPUID[6].EAX: */ - add_cpuid_test("x86/cpuid/auto-level/486/arat", - "486", "arat=3Don", NULL, "level", 6); + { + "x86/cpuid/auto-level/486/arat", + "486", "arat=3Don", NULL, "level", 6, + }, /* CPUID[EAX=3D7,ECX=3D0].EBX: */ - add_cpuid_test("x86/cpuid/auto-level/phenom/fsgsbase", - "phenom", "fsgsbase=3Don", NULL, "level", 7); + { + "x86/cpuid/auto-level/phenom/fsgsbase", + "phenom", "fsgsbase=3Don", NULL, "level", 7, + }, /* CPUID[EAX=3D7,ECX=3D0].ECX: */ - add_cpuid_test("x86/cpuid/auto-level/phenom/avx512vbmi", - "phenom", "avx512vbmi=3Don", NULL, "level", 7); + { + "x86/cpuid/auto-level/phenom/avx512vbmi", + "phenom", "avx512vbmi=3Don", NULL, "level", 7, + }, /* CPUID[EAX=3D0xd,ECX=3D1].EAX: */ - add_cpuid_test("x86/cpuid/auto-level/phenom/xsaveopt", - "phenom", "xsaveopt=3Don", NULL, "level", 0xd); + { + "x86/cpuid/auto-level/phenom/xsaveopt", + "phenom", "xsaveopt=3Don", NULL, "level", 0xd, + }, /* CPUID[8000_0001].EDX: */ - add_cpuid_test("x86/cpuid/auto-xlevel/486/3dnow", - "486", "3dnow=3Don", NULL, "xlevel", 0x80000001); + { + "x86/cpuid/auto-xlevel/486/3dnow", + "486", "3dnow=3Don", NULL, "xlevel", 0x80000001, + }, /* CPUID[8000_0001].ECX: */ - add_cpuid_test("x86/cpuid/auto-xlevel/486/sse4a", - "486", "sse4a=3Don", NULL, "xlevel", 0x80000001); + { + "x86/cpuid/auto-xlevel/486/sse4a", + "486", "sse4a=3Don", NULL, "xlevel", 0x80000001, + }, /* CPUID[8000_0007].EDX: */ - add_cpuid_test("x86/cpuid/auto-xlevel/486/invtsc", - "486", "invtsc=3Don", NULL, "xlevel", 0x80000007); + { + "x86/cpuid/auto-xlevel/486/invtsc", + "486", "invtsc=3Don", NULL, "xlevel", 0x80000007, + }, /* CPUID[8000_000A].EDX: */ - add_cpuid_test("x86/cpuid/auto-xlevel/486/npt", - "486", "svm=3Don,npt=3Don", NULL, "xlevel", 0x8000000A); + { + "x86/cpuid/auto-xlevel/486/npt", + "486", "svm=3Don,npt=3Don", NULL, "xlevel", 0x8000000A, + }, /* CPUID[C000_0001].EDX: */ - add_cpuid_test("x86/cpuid/auto-xlevel2/phenom/xstore", - "phenom", "xstore=3Don", NULL, "xlevel2", 0xC0000001); + { + "x86/cpuid/auto-xlevel2/phenom/xstore", + "phenom", "xstore=3Don", NULL, "xlevel2", 0xC0000001, + }, /* SVM needs CPUID[0x8000000A] */ - add_cpuid_test("x86/cpuid/auto-xlevel/athlon/svm", - "athlon", "svm=3Don", NULL, "xlevel", 0x8000000A); - - + { + "x86/cpuid/auto-xlevel/athlon/svm", + "athlon", "svm=3Don", NULL, "xlevel", 0x8000000A, + }, /* If level is already large enough, it shouldn't change: */ - add_cpuid_test("x86/cpuid/auto-level/SandyBridge/multiple", - "SandyBridge", "arat=3Don,fsgsbase=3Don,avx512vbmi=3Don= ", - NULL, "level", 0xd); + { + "x86/cpuid/auto-level/SandyBridge/multiple", + "SandyBridge", "arat=3Don,fsgsbase=3Don,avx512vbmi=3Don", + NULL, "level", 0xd, + }, /* If level is explicitly set, it shouldn't change: */ - add_cpuid_test("x86/cpuid/auto-level/486/fixed/0xF", - "486", - "level=3D0xF,arat=3Don,fsgsbase=3Don,avx512vbmi=3Don,xs= aveopt=3Don", - NULL, "level", 0xF); - add_cpuid_test("x86/cpuid/auto-level/486/fixed/2", - "486", - "level=3D2,arat=3Don,fsgsbase=3Don,avx512vbmi=3Don,xsav= eopt=3Don", - NULL, "level", 2); - add_cpuid_test("x86/cpuid/auto-level/486/fixed/0", - "486", - "level=3D0,arat=3Don,fsgsbase=3Don,avx512vbmi=3Don,xsav= eopt=3Don", - NULL, "level", 0); - + { + "x86/cpuid/auto-level/486/fixed/0xF", + "486", + "level=3D0xF,arat=3Don,fsgsbase=3Don,avx512vbmi=3Don,xsaveopt=3Don= ", + NULL, "level", 0xF, + }, + { + "x86/cpuid/auto-level/486/fixed/2", + "486", + "level=3D2,arat=3Don,fsgsbase=3Don,avx512vbmi=3Don,xsaveopt=3Don", + NULL, "level", 2, + }, + { + "x86/cpuid/auto-level/486/fixed/0", + "486", + "level=3D0,arat=3Don,fsgsbase=3Don,avx512vbmi=3Don,xsaveopt=3Don", + NULL, "level", 0, + }, /* if xlevel is already large enough, it shouldn't change: */ - add_cpuid_test("x86/cpuid/auto-xlevel/phenom/3dnow", - "phenom", "3dnow=3Don,sse4a=3Don,invtsc=3Don,npt=3Don,s= vm=3Don", - NULL, "xlevel", 0x8000001A); + { + "x86/cpuid/auto-xlevel/phenom/3dnow", + "phenom", "3dnow=3Don,sse4a=3Don,invtsc=3Don,npt=3Don,svm=3Don", + NULL, "xlevel", 0x8000001A, + }, /* If xlevel is explicitly set, it shouldn't change: */ - add_cpuid_test("x86/cpuid/auto-xlevel/486/fixed/80000002", - "486", - "xlevel=3D0x80000002,3dnow=3Don,sse4a=3Don,invtsc=3Don,= npt=3Don,svm=3Don", - NULL, "xlevel", 0x80000002); - add_cpuid_test("x86/cpuid/auto-xlevel/486/fixed/8000001A", - "486", - "xlevel=3D0x8000001A,3dnow=3Don,sse4a=3Don,invtsc=3Don,= npt=3Don,svm=3Don", - NULL, "xlevel", 0x8000001A); - add_cpuid_test("x86/cpuid/auto-xlevel/phenom/fixed/0", - "486", - "xlevel=3D0,3dnow=3Don,sse4a=3Don,invtsc=3Don,npt=3Don,= svm=3Don", - NULL, "xlevel", 0); - + { + "x86/cpuid/auto-xlevel/486/fixed/80000002", + "486", + "xlevel=3D0x80000002,3dnow=3Don,sse4a=3Don,invtsc=3Don,npt=3Don,sv= m=3Don", + NULL, "xlevel", 0x80000002, + }, + { + "x86/cpuid/auto-xlevel/486/fixed/8000001A", + "486", + "xlevel=3D0x8000001A,3dnow=3Don,sse4a=3Don,invtsc=3Don,npt=3Don,sv= m=3Don", + NULL, "xlevel", 0x8000001A, + }, + { + "x86/cpuid/auto-xlevel/phenom/fixed/0", + "486", + "xlevel=3D0,3dnow=3Don,sse4a=3Don,invtsc=3Don,npt=3Don,svm=3Don", + NULL, "xlevel", 0, + }, /* if xlevel2 is already large enough, it shouldn't change: */ - add_cpuid_test("x86/cpuid/auto-xlevel2/486/fixed", - "486", "xlevel2=3D0xC0000002,xstore=3Don", - NULL, "xlevel2", 0xC0000002); + { + "x86/cpuid/auto-xlevel2/486/fixed", + "486", "xlevel2=3D0xC0000002,xstore=3Don", + NULL, "xlevel2", 0xC0000002, + }, +}; + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess", + test_plus_minus_subprocess); + g_test_add_func("/x86/cpuid/parsing-plus-minus", test_plus_minus); + + for (int i =3D 0; i < ARRAY_SIZE(cpuid_tests); i++) { + if (!qtest_has_cpu_model(cpuid_tests[i].cpu)) { + continue; + } + qtest_add_data_func(cpuid_tests[i].name, + &cpuid_tests[i], test_cpuid_prop); + } =20 /* Test feature parsing */ add_feature_test("x86/cpuid/features/plus", --=20 2.51.0 From nobody Tue Apr 7 19:50:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1773267259; cv=none; d=zohomail.com; s=zohoarc; b=lU+H+v4fV7mMdigKkQsYZa2CztzwNzEd5XUKUHO82rFDsAG/RszcymhLNd0JZzlep7Ffrg+4OfiE+AmdA2jeO3vhBRnopQzpKiAqzQb5z/VXTLoXqpPur9E2ye0MO4QifbJlLg0qKwVAChxDu374GDCVnyVbBDLa27iY/Ile2Uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773267259; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OFa9YYC1bR3F6UF+0MBTKURV7W7gTNMZCeq4R2tsyMc=; b=oFLskyNEiYwDmwUrBQnh/0W5HA6fSvY85oTPWAjQlcBFGV+BnzAJgiLEqyGfn9u3Mr3xGDGe85/xsN2CPoRV3d5ABxFKG6ZBcbobXDzGp6PeprxpQHFWSV1YB1XWY9Lpg1a/x0ABomMZmJH3K1CW5KgjPpNv0ihS5DTmeGmzXwA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773267259469480.58288206392695; Wed, 11 Mar 2026 15:14:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0RoK-0000x8-C1; Wed, 11 Mar 2026 18:13:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w0RoH-0000wh-RJ for qemu-devel@nongnu.org; Wed, 11 Mar 2026 18:13:45 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w0RoF-00051F-8h for qemu-devel@nongnu.org; Wed, 11 Mar 2026 18:13:44 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1A15F4D643; Wed, 11 Mar 2026 22:13:28 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2C6343FC44; Wed, 11 Mar 2026 22:13:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wK3qOAbpsWnCeQAAD6G6ig (envelope-from ); Wed, 11 Mar 2026 22:13:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1773267208; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OFa9YYC1bR3F6UF+0MBTKURV7W7gTNMZCeq4R2tsyMc=; b=j1hk1C6LH6Ci0nenk77gJeo8zXHxojUyIRvhlvEHnwgsCDvDv4x25vtsGT9CqSMDTeGlgq bhyCiJa2saUOdN/zEPtcWaRgMvh+/Mlg2k3JM93BDujzj91aAQE9ymY5hUnlIbHCCgXYlo Xx1p0eVtjJwmQpJPjftu1Led2XYcf2c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1773267208; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OFa9YYC1bR3F6UF+0MBTKURV7W7gTNMZCeq4R2tsyMc=; b=ZJXjMLcKb88oP4u+YjhjW7zmJ+hJ9eCMHzl+suuK63Tmq5T6Qe0iH3tvkjWFK7/rnLMp5J PWa3oMVDL3dGIfBw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=j1hk1C6L; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ZJXjMLcK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1773267208; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OFa9YYC1bR3F6UF+0MBTKURV7W7gTNMZCeq4R2tsyMc=; b=j1hk1C6LH6Ci0nenk77gJeo8zXHxojUyIRvhlvEHnwgsCDvDv4x25vtsGT9CqSMDTeGlgq bhyCiJa2saUOdN/zEPtcWaRgMvh+/Mlg2k3JM93BDujzj91aAQE9ymY5hUnlIbHCCgXYlo Xx1p0eVtjJwmQpJPjftu1Led2XYcf2c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1773267208; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OFa9YYC1bR3F6UF+0MBTKURV7W7gTNMZCeq4R2tsyMc=; b=ZJXjMLcKb88oP4u+YjhjW7zmJ+hJ9eCMHzl+suuK63Tmq5T6Qe0iH3tvkjWFK7/rnLMp5J PWa3oMVDL3dGIfBw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 3/3] tests/qtest/test-x86-cpuid-compat: Switch test_feature_flag to data-driven Date: Wed, 11 Mar 2026 19:13:20 -0300 Message-ID: <20260311221320.22112-4-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260311221320.22112-1-farosas@suse.de> References: <20260311221320.22112-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,suse.de:email,linaro.org:email]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_SOME(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Queue-Id: 1A15F4D643 X-Spam-Score: -3.01 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1773267260810158500 Content-Type: text/plain; charset="utf-8" From: Peter Maydell As with add_cpuid_test(), the add_feature_test() function also allocates memory that is leaked if the test case is not run. Fix this in the same way, by moving all the allocations into test_feature_flag() and passing it a pointer to a struct with the necessary parameters which is a compile-time constant. Signed-off-by: Peter Maydell Reviewed-by: Fabiano Rosas Signed-off-by: Fabiano Rosas --- tests/qtest/test-x86-cpuid-compat.c | 134 +++++++++++++++------------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/tests/qtest/test-x86-cpuid-compat.c b/tests/qtest/test-x86-cpu= id-compat.c index fc90a46d37..17c0965827 100644 --- a/tests/qtest/test-x86-cpuid-compat.c +++ b/tests/qtest/test-x86-cpuid-compat.c @@ -94,8 +94,12 @@ static void test_cpuid_prop(const void *data) =20 /* Parameters to a add_feature_test() test case */ typedef struct FeatureTestArgs { - /* cmdline to start QEMU */ - const char *cmdline; + /* Test name */ + const char *name; + /* CPU type */ + const char *cpu; + /* CPU features, may be NULL */ + const char *cpufeat; /* * cpuid-input-eax and cpuid-input-ecx values to look for, * in "feature-words" and "filtered-features" properties. @@ -140,10 +144,17 @@ static void test_feature_flag(const void *data) { const FeatureTestArgs *args =3D data; char *path; + char *cmdline; QList *present, *filtered; uint32_t value; =20 - qtest_start(args->cmdline); + if (args->cpufeat) { + cmdline =3D g_strdup_printf("-cpu %s,%s", args->cpu, args->cpufeat= ); + } else { + cmdline =3D g_strdup_printf("-cpu %s", args->cpu); + } + + qtest_start(cmdline); path =3D get_cpu0_qom_path(); present =3D qobject_to(QList, qom_get(path, "feature-words")); filtered =3D qobject_to(QList, qom_get(path, "filtered-features")); @@ -156,40 +167,7 @@ static void test_feature_flag(const void *data) qobject_unref(present); qobject_unref(filtered); g_free(path); - g_free((void *)args->cmdline); - g_free((void *)data); -} - -/* - * Add test case to ensure that a given feature flag is set in - * either "feature-words" or "filtered-features", when running QEMU - * using cmdline - */ -static void add_feature_test(const char *name, const char *cpu, - const char *cpufeat, uint32_t eax, - uint32_t ecx, const char *reg, - int bitnr, bool expected_value) -{ - FeatureTestArgs *args =3D g_new0(FeatureTestArgs, 1); - char *cmdline; - - if (!qtest_has_cpu_model(cpu)) { - return; - } - - if (cpufeat) { - cmdline =3D g_strdup_printf("-cpu %s,%s", cpu, cpufeat); - } else { - cmdline =3D g_strdup_printf("-cpu %s", cpu); - } - - args->cmdline =3D cmdline; - args->in_eax =3D eax; - args->in_ecx =3D ecx; - args->reg =3D reg; - args->bitnr =3D bitnr; - args->expected_value =3D expected_value; - qtest_add_data_func(name, args, test_feature_flag); + g_free(cmdline); } =20 static void test_plus_minus_subprocess(void) @@ -381,6 +359,56 @@ static const CpuidTestArgs cpuid_tests[] =3D { }, }; =20 +/* + * Test cases to ensure that a given feature flag is set in + * either "feature-words" or "filtered-features", when running QEMU + * using cmdline + */ +static const FeatureTestArgs feature_tests[] =3D { + /* Test feature parsing */ + { + "x86/cpuid/features/plus", + "486", "+arat", + 6, 0, "EAX", 2, true, + }, + { + "x86/cpuid/features/minus", + "pentium", "-mmx", + 1, 0, "EDX", 23, false, + }, + { + "x86/cpuid/features/on", + "486", "arat=3Don", + 6, 0, "EAX", 2, true, + }, + { + "x86/cpuid/features/off", + "pentium", "mmx=3Doff", + 1, 0, "EDX", 23, false, + }, + + { + "x86/cpuid/features/max-plus-invtsc", + "max" , "+invtsc", + 0x80000007, 0, "EDX", 8, true, + }, + { + "x86/cpuid/features/max-invtsc-on", + "max", "invtsc=3Don", + 0x80000007, 0, "EDX", 8, true, + }, + { + "x86/cpuid/features/max-minus-mmx", + "max", "-mmx", + 1, 0, "EDX", 23, false, + }, + { + "x86/cpuid/features/max-invtsc-on,mmx=3Doff", + "max", "mmx=3Doff", + 1, 0, "EDX", 23, false, + }, +}; + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -397,32 +425,14 @@ int main(int argc, char **argv) &cpuid_tests[i], test_cpuid_prop); } =20 - /* Test feature parsing */ - add_feature_test("x86/cpuid/features/plus", - "486", "+arat", - 6, 0, "EAX", 2, true); - add_feature_test("x86/cpuid/features/minus", - "pentium", "-mmx", - 1, 0, "EDX", 23, false); - add_feature_test("x86/cpuid/features/on", - "486", "arat=3Don", - 6, 0, "EAX", 2, true); - add_feature_test("x86/cpuid/features/off", - "pentium", "mmx=3Doff", - 1, 0, "EDX", 23, false); =20 - add_feature_test("x86/cpuid/features/max-plus-invtsc", - "max" , "+invtsc", - 0x80000007, 0, "EDX", 8, true); - add_feature_test("x86/cpuid/features/max-invtsc-on", - "max", "invtsc=3Don", - 0x80000007, 0, "EDX", 8, true); - add_feature_test("x86/cpuid/features/max-minus-mmx", - "max", "-mmx", - 1, 0, "EDX", 23, false); - add_feature_test("x86/cpuid/features/max-invtsc-on,mmx=3Doff", - "max", "mmx=3Doff", - 1, 0, "EDX", 23, false); + for (int i =3D 0; i < ARRAY_SIZE(feature_tests); i++) { + if (!qtest_has_cpu_model(feature_tests[i].cpu)) { + continue; + } + qtest_add_data_func(feature_tests[i].name, + &feature_tests[i], test_feature_flag); + } =20 return g_test_run(); } --=20 2.51.0