From nobody Sun Sep 28 17:04:52 2025 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=1758706400; cv=none; d=zohomail.com; s=zohoarc; b=JWRl2senom8JdNlbZp77YLVfdyNhQ5/kNPJS4NY7IKlF8A+QPjJRTpT1714GXmrymhZ4IY0gYgNpJOEHFt0DhwoYo4USoJZfmPoClZkouLq6pQaRwxlnRkPUrOwWVIU4HBnP+JJuADZ59CRj6LgSsvRQecd7tdcpTvpqf5QP4iI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758706400; 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=HXmvPGZW6Xy2j6d5SQMF9drQH62wek/K3jL06MV925U=; b=n5PQNGGryvVFkuWFJyRFyrqK2Fglth+6sK4jaEgrQHHyMxUrbwiI2ha8AFZ1wio9l/2ecXujlx0RiXcH6L+p+Liloj3pEsYNpAaorZ4K26tkDkNUk6EVZUjM0yiOf4/y57rIVofheijLEljjp7aG14h87aKXuqOsqDtkXduWjZE= 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 1758706400691460.21832692303497; Wed, 24 Sep 2025 02:33:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Loy-0005G0-5V; Wed, 24 Sep 2025 05:29:56 -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 1v1Lov-0005EH-07 for qemu-devel@nongnu.org; Wed, 24 Sep 2025 05:29:53 -0400 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 1v1Loq-0004pJ-8r for qemu-devel@nongnu.org; Wed, 24 Sep 2025 05:29:52 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-0kUguhR8MUiV5kId6M3o6w-1; Wed, 24 Sep 2025 05:29:41 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-b2e6b2bb443so264352166b.2 for ; Wed, 24 Sep 2025 02:29:41 -0700 (PDT) Received: from [192.168.10.48] ([176.206.127.188]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-62fa5f27640sm12429827a12.39.2025.09.24.02.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Sep 2025 02:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758706183; h=from:from:reply-to:subject:subject: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=HXmvPGZW6Xy2j6d5SQMF9drQH62wek/K3jL06MV925U=; b=MysXxtF5Y0+cGfPUIIjrt9yPAsP792F1KwMqWp0WZnKBSKPZJPkesIUZR431JArcuO/uEd dmnuZsNK2ryPjS4B87X9U6c3idYTRsJW1Rm0BqpKYcsF9aUPZVu66m4EIg0E6topBdlfM5 C83mSdU9k2GV17IzpmJhWI7c8/M6Xgc= X-MC-Unique: 0kUguhR8MUiV5kId6M3o6w-1 X-Mimecast-MFC-AGG-ID: 0kUguhR8MUiV5kId6M3o6w_1758706180 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758706180; x=1759310980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HXmvPGZW6Xy2j6d5SQMF9drQH62wek/K3jL06MV925U=; b=Ca9jqOA/LOXr7CK9XP9lo/HBe9KjcjuC+s5tKefO6SZaGMX+Z6wzRtCbxtLEQQCx7j jv1fBx71hLjtwXXs8gjKDqxoN23x8slcdRhUEMGd/K8RisuQ0Ci5xb4opj3yLNpQXICL Erf8WHdZpzfCc4geLx6iD78xswYGVAdpX/Y63so4aalTcKzdPwRJDCEhfOH+eM9BUtYc C9IeDb0Wa1az/nC9UhrmXs6ChagugSZyWC/nEZfgKIP3/lNCm7t+vJZaYYtcDPhXrIYN B6zG2iFJ3nwMPnq2GMNi6c7m4RkYwfnYpNkd64WkqIN8ymFZeAPDirqMKX3KY9VVvBVZ eMzA== X-Gm-Message-State: AOJu0Yy8hCa6kmoYxo9VA1OgKdEstSyKJAUOy5SSWHsuGvF5zxlKqoSi 4ZUcaqfzR0u+7j+wfmfjozqXmfGoMLeT3z5z6N2bkLsty2dI1jFdR1UEbMuzujj1NzpfLg7RM6K 8M92ioNH7o1jkeG1q+oEngoRJcSmKd6MRCAGQMkfdMCm4bXJVJIyNxB2jRSNCispaL+LtEkPB2W N294UH9LE2Lahn42vOa46Ll2IOtDzne7CcZz4IDQ2a X-Gm-Gg: ASbGncs33obArk0fkcdtmRjj6ZJzBa1rrlIS6Jg7bmHNWOHiPrxwW0X2zKRD7vuqfxW kMZheYmEiUOenVKWbRyei6GCRnScJYuNJFU3N462IYW2XGnueo8b7qNDC68hXULB/2NCMSuEEpV Z6CoJIIp5Wm+e7mTo0W++B6n2Y2O6djSoZKmh6jMAXKhn9gUWO3bd4Huxaz2SFQtva+aCjViZvm YSz20wTEQamXdWJC4DOJopgOsEx7wvagUJsDDPtu/CBRxA3ZXowj97urr2Nysie06BP8D5hTxEW mPza2HM4dA8t71fp59LZuF+XU6o3dDKebhtjC0ObfgI9noQsJy5e2EnjofzKXaHEKI9I67fcfdJ kMJrY3YeoUqn1wHffntl64NMkcMZKHo/teVGCcbiDUTj04A== X-Received: by 2002:a17:906:4fca:b0:ae3:b2b7:7f2f with SMTP id a640c23a62f3a-b302a36d276mr638233866b.40.1758706179755; Wed, 24 Sep 2025 02:29:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcVaNEYDYvuMwc5KljUL2ILfOCZq9WbaTbv8PpkQPjvlWw7PbjtCqBlFk/hyGs+i+Cp1gw3A== X-Received: by 2002:a17:906:4fca:b0:ae3:b2b7:7f2f with SMTP id a640c23a62f3a-b302a36d276mr638230866b.40.1758706179290; Wed, 24 Sep 2025 02:29:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 15/29] rust/qdev: Test bit property for #property Date: Wed, 24 Sep 2025 11:28:35 +0200 Message-ID: <20250924092850.42047-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250924092850.42047-1-pbonzini@redhat.com> References: <20250924092850.42047-1-pbonzini@redhat.com> MIME-Version: 1.0 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, 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_H5=0.001, RCVD_IN_MSPIKE_WL=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: 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: 1758706403067116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu There's a diference between Rust and C: Though C macro (e.g., DEFINE_PROP_BIT or DEFINE_PROP_BIT64) always requires default value, Rust side allows to omit this "default" field in #property, and provides a default value ("0" - false) for this field. This minor difference does not break user habits and should be acceptable. Therefore, the test cases also cover this scenario. Signed-off-by: Zhao Liu Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20250920160520.3699591-10-zhao1.liu@intel.c= om --- rust/qemu-macros/src/tests.rs | 99 +++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/rust/qemu-macros/src/tests.rs b/rust/qemu-macros/src/tests.rs index ec137132ae7..ac998d20e30 100644 --- a/rust/qemu-macros/src/tests.rs +++ b/rust/qemu-macros/src/tests.rs @@ -89,6 +89,19 @@ struct DummyState { "Duplicate argument", "Already used here", ); + derive_compile_fail!( + derive_device_or_error, + quote! { + #[repr(C)] + #[derive(Device)] + struct DummyState { + #[property(bit =3D 0, bit =3D 1)] + flags: u32, + } + }, + "Duplicate argument", + "Already used here", + ); // Check that the field name is preserved when `rename` isn't used: derive_compile!( derive_device_or_error, @@ -145,6 +158,92 @@ unsafe impl ::hwcore::DevicePropertiesImpl for DummySt= ate { } } ); + // Check that `bit` value is used for the bit property without default + // value (note: though C macro (e.g., DEFINE_PROP_BIT) always requires + // default value, Rust side allows to default this field to "0"): + derive_compile!( + derive_device_or_error, + quote! { + #[repr(C)] + #[derive(Device)] + pub struct DummyState { + parent: ParentField, + #[property(bit =3D 3)] + flags: u32, + } + }, + quote! { + unsafe impl ::hwcore::DevicePropertiesImpl for DummyState { + const PROPERTIES: &'static [::hwcore::bindings::Property] = =3D &[ + ::hwcore::bindings::Property { + name: ::std::ffi::CStr::as_ptr(c"flags"), + info: ::BIT_INFO, + offset: ::core::mem::offset_of!(DummyState, flags)= as isize, + bitnr: 3, + set_default: false, + defval: ::hwcore::bindings::Property__bindgen_ty_1= { u: 0 as u64 }, + ..::common::Zeroable::ZERO + } + ]; + } + } + ); + // Check that `bit` value is used for the bit property when used: + derive_compile!( + derive_device_or_error, + quote! { + #[repr(C)] + #[derive(Device)] + pub struct DummyState { + parent: ParentField, + #[property(bit =3D 3, default =3D true)] + flags: u32, + } + }, + quote! { + unsafe impl ::hwcore::DevicePropertiesImpl for DummyState { + const PROPERTIES: &'static [::hwcore::bindings::Property] = =3D &[ + ::hwcore::bindings::Property { + name: ::std::ffi::CStr::as_ptr(c"flags"), + info: ::BIT_INFO, + offset: ::core::mem::offset_of!(DummyState, flags)= as isize, + bitnr: 3, + set_default: true, + defval: ::hwcore::bindings::Property__bindgen_ty_1= { u: true as u64 }, + ..::common::Zeroable::ZERO + } + ]; + } + } + ); + // Check that `bit` value is used for the bit property with rename whe= n used: + derive_compile!( + derive_device_or_error, + quote! { + #[repr(C)] + #[derive(Device)] + pub struct DummyState { + parent: ParentField, + #[property(rename =3D "msi", bit =3D 3, default =3D false)] + flags: u64, + } + }, + quote! { + unsafe impl ::hwcore::DevicePropertiesImpl for DummyState { + const PROPERTIES: &'static [::hwcore::bindings::Property] = =3D &[ + ::hwcore::bindings::Property { + name: ::std::ffi::CStr::as_ptr(c"msi"), + info: ::BIT_INFO, + offset: ::core::mem::offset_of!(DummyState, flags)= as isize, + bitnr: 3, + set_default: true, + defval: ::hwcore::bindings::Property__bindgen_ty_1= { u: false as u64 }, + ..::common::Zeroable::ZERO + } + ]; + } + } + ); } =20 #[test] --=20 2.51.0