From nobody Sun Apr 12 07:24:46 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770907752; cv=none; d=zohomail.com; s=zohoarc; b=EIw13fJEj+S0Zcbd+L5aZsd3BGt7nluvV9M71ez/TumQJkfEioekD1QvVHz7vIkyf5uUVI/5TNUmLatKR+WYGbVtygjjqzr9mQCQK95Vd/2mFv6Mw4iuV+JJ7K5vNHeAPNTI+rASZHHQ0IgaRi3dudYu/FASMyZlqj+/xt8u2vs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770907752; h=Content-Type: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=ODhn/b5AvptlCuVZKL5lyPwHbvz25VOUzIhw6xuP1GI=; b=mbU5X8jeIpfCh5CJmg8mdIvVO2Wz2u//iNIpLLh7ZfFcOdTxPcnkO6btYeAFq5H0Fz3R0jk3xqMFBAL7GH4XAtYGOil1/oC8oNHtdsuEr4kPoWkqAqenzZrbPIeHxmZZbvSBmId0JyHE7hS944ZvLNRvh+xiGj5CUQfN8/akdck= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770907752620982.3314085702967; Thu, 12 Feb 2026 06:49:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqXw7-0007Tt-Fp; Thu, 12 Feb 2026 09:44:59 -0500 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 1vqXva-0006Yp-OE for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:44:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqXvY-0006IE-DE for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:44:22 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-qtX18ST1PV2qGUZBIWarHg-1; Thu, 12 Feb 2026 09:44:18 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4831192e66aso70119045e9.2 for ; Thu, 12 Feb 2026 06:44:18 -0800 (PST) Received: from [10.60.241.123] (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4835a66fcf7sm56255795e9.7.2026.02.12.06.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 06:44:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770907459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ODhn/b5AvptlCuVZKL5lyPwHbvz25VOUzIhw6xuP1GI=; b=f1wWxqKLoa0jdtV+ZVp4xG6WiC2qJQPaHf6wGAfk8ubCBgmDHlCzngII2R6IdtGXYaZqLD 8YjuSwlIh0ajish7TdLMQ5LRuomRTeY+61QARPkGmAeul1YgU8BNh+SbPxWIuM4oo9nduq Vc5kL0XbOxbpQmx71ACfvXGs+o82rvc= X-MC-Unique: qtX18ST1PV2qGUZBIWarHg-1 X-Mimecast-MFC-AGG-ID: qtX18ST1PV2qGUZBIWarHg_1770907457 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770907457; x=1771512257; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ODhn/b5AvptlCuVZKL5lyPwHbvz25VOUzIhw6xuP1GI=; b=FtBjML2KSMMk9Bh/rmQetk4NyyVAY1VGgt41rpHtqsGmXW95jseLKXInW7Ax9ZXFgS pi/CxNHIryRS9NLW5z4NIkvWMtrd9kt+wD1I4rKl0b4k+iAj8dngxxvUgeFG0DqIfaKH d5rUcd4h+CuMhLvdxPCHb4kVqn8pUB923GGYieYqFZ8UkZFwvZFGYdwLbgStjCYosB5U VI/HkkEjGHXMjIMnzLthRZxZI94GNYCkkmZz7EoZZYrIJuDA/DsDcX0PQRCfjUfdgGeq pabd8P/mmXfS5iUga5T5Q/Bo+hNHfPf8xCVv7xIXGeN09egSFHc96ThkYXNWF6gqvj2g xzSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770907457; x=1771512257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ODhn/b5AvptlCuVZKL5lyPwHbvz25VOUzIhw6xuP1GI=; b=TAKyCfqcNDsyfXyVnMD0egVqVUXzC9dPNnDhcC01BDRwG1G2zVI59jAxUPEWg3u6/y GKLbAkPwj61XGgdy0Yx0Ea8oyofw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804b1-483656ae432mr41831755e9.2.1770907456879; Thu, 12 Feb 2026 06:44:16 -0800 (PST) X-Received: by 2002:a05:600c:4e14:b0:480:1e8f:d15f with SMTP id 5b1f17b1804b1-483656ae432mr41831305e9.2.1770907456373; Thu, 12 Feb 2026 06:44:16 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefan Berger , Stefan Hajnoczi Subject: [PULL 39/41] tests: add /qdev/free-properties test Date: Thu, 12 Feb 2026 15:42:41 +0100 Message-ID: <20260212144244.22579-40-pbonzini@redhat.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260212144244.22579-1-pbonzini@redhat.com> References: <20260212144244.22579-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1770907755758154100 From: Marc-Andr=C3=A9 Lureau Add a simple qdev test to check that allocated properties get freed with the object. This test exhibited array leaks before the fixes. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger Link: https://lore.kernel.org/r/20250429140306.190384-6-marcandre.lureau@re= dhat.com Reviewed-by: Stefan Hajnoczi Link: https://lore.kernel.org/r/20260108230311.584141-6-csomani@redhat.com Signed-off-by: Paolo Bonzini --- tests/unit/test-qdev.c | 96 ++++++++++++++++++++++++++++++++++++++++++ tests/unit/meson.build | 1 + 2 files changed, 97 insertions(+) create mode 100644 tests/unit/test-qdev.c diff --git a/tests/unit/test-qdev.c b/tests/unit/test-qdev.c new file mode 100644 index 00000000000..20eae38e03f --- /dev/null +++ b/tests/unit/test-qdev.c @@ -0,0 +1,96 @@ +#include "qemu/osdep.h" +#include "hw/core/qdev-properties.h" +#include "qom/object.h" +#include "qapi/error.h" +#include "qapi/visitor.h" + + +#define TYPE_MY_DEV "my-dev" +typedef struct MyDev MyDev; +DECLARE_INSTANCE_CHECKER(MyDev, STATIC_TYPE, + TYPE_MY_DEV) + +struct MyDev { + DeviceState parent_obj; + + uint32_t prop_u32; + char *prop_string; + uint32_t *prop_array_u32; + uint32_t prop_array_u32_nb; +}; + +static const Property my_dev_props[] =3D { + DEFINE_PROP_UINT32("u32", MyDev, prop_u32, 100), + DEFINE_PROP_STRING("string", MyDev, prop_string), + DEFINE_PROP_ARRAY("array-u32", MyDev, prop_array_u32_nb, prop_array_u3= 2, + qdev_prop_uint32, uint32_t), +}; + +static void my_dev_class_init(ObjectClass *oc, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D NULL; + device_class_set_props(dc, my_dev_props); +} + +static const TypeInfo my_dev_type_info =3D { + .name =3D TYPE_MY_DEV, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(MyDev), + .class_init =3D my_dev_class_init, +}; + +/* + * Initialize a fake machine, being prepared for future tests. + * + * Realization of anonymous qdev (with no parent object) requires both + * the machine object and its "unattached" container to be at least presen= t. + */ +static void test_init_machine(void) +{ + /* This is a fake machine - it doesn't need to be a machine object */ + Object *machine =3D object_property_add_new_container( + object_get_root(), "machine"); + + /* This container must exist for anonymous qdevs to realize() */ + object_property_add_new_container(machine, "unattached"); +} + +static void test_qdev_free_properties(void) +{ + MyDev *mt; + + mt =3D STATIC_TYPE(object_new(TYPE_MY_DEV)); + object_set_props(OBJECT(mt), &error_fatal, + "string", "something", + "array-u32", "12,13", + NULL); + qdev_realize(DEVICE(mt), NULL, &error_fatal); + + g_assert_cmpuint(mt->prop_u32, =3D=3D, 100); + g_assert_cmpstr(mt->prop_string, =3D=3D, "something"); + g_assert_cmpuint(mt->prop_array_u32_nb, =3D=3D, 2); + g_assert_cmpuint(mt->prop_array_u32[0], =3D=3D, 12); + g_assert_cmpuint(mt->prop_array_u32[1], =3D=3D, 13); + + object_unparent(OBJECT(mt)); + object_unref(mt); +} + + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + module_call_init(MODULE_INIT_QOM); + type_register_static(&my_dev_type_info); + test_init_machine(); + + g_test_add_func("/qdev/free-properties", + test_qdev_free_properties); + + g_test_run(); + + return 0; +} diff --git a/tests/unit/meson.build b/tests/unit/meson.build index bd580290601..41e8b06c339 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -156,6 +156,7 @@ if have_system 'test-qdev-global-props': [qom, hwcore] } endif + tests +=3D {'test-qdev': [qom, hwcore]} endif =20 if have_ga and host_os =3D=3D 'linux' --=20 2.52.0