All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Juraj Marcin <jmarcin@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	peterx@redhat.com, Fabiano Rosas <farosas@suse.de>,
	Gavin Shan <gshan@redhat.com>, Zhao Liu <zhao1.liu@intel.com>
Subject: [PATCH for-12.0 v2 3/9] rust/migration: Remove vmstate_validate!() macro and test
Date: Thu, 26 Nov 2026 18:16:25 -0500	[thread overview]
Message-ID: <20261126231631.3392756-4-peterx@redhat.com> (raw)
In-Reply-To: <20261126231631.3392756-1-peterx@redhat.com>

From: Zhao Liu <zhao1.liu@intel.com>

We have moved all users (in Rust side) to other API, now they're never
used.

After the related test (originally FOOD) was removed, rename FOOE to
new FOOD test.

Suggested-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20261124095814.437738-4-zhao1.liu@intel.com
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 rust/migration/src/prelude.rs     |  1 -
 rust/migration/src/vmstate.rs     | 17 ------
 rust/tests/tests/vmstate_tests.rs | 93 +++----------------------------
 3 files changed, 8 insertions(+), 103 deletions(-)

diff --git a/rust/migration/src/prelude.rs b/rust/migration/src/prelude.rs
index 797e7ec59d..e2cbbda43e 100644
--- a/rust/migration/src/prelude.rs
+++ b/rust/migration/src/prelude.rs
@@ -16,4 +16,3 @@
 pub use crate::vmstate_of;
 pub use crate::vmstate_subsections;
 pub use crate::vmstate_unused;
-pub use crate::vmstate_validate;
diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs
index 0b05db4e70..ec8b712cbf 100644
--- a/rust/migration/src/vmstate.rs
+++ b/rust/migration/src/vmstate.rs
@@ -384,23 +384,6 @@ macro_rules! vmstate_fields {
     }}
 }
 
-#[doc(alias = "VMSTATE_VALIDATE")]
-#[macro_export]
-macro_rules! vmstate_validate {
-    ($struct_name:ty, $test_name:expr, $test_fn:expr $(,)?) => {
-        $crate::bindings::VMStateField {
-            name: ::std::ffi::CStr::as_ptr($test_name),
-            field_exists: $crate::vmstate_exist_fn!($struct_name, $test_fn),
-            flags: $crate::bindings::VMStateFlags(
-                $crate::bindings::VMStateFlags::VMS_MUST_EXIST.0
-                    | $crate::bindings::VMStateFlags::VMS_NO_STATE.0,
-            ),
-            num: 0, // 0 elements: no data, only run test_fn callback
-            ..::common::zeroable::Zeroable::ZERO
-        }
-    };
-}
-
 /// Helper macro to allow using a struct in [`vmstate_of!`]
 ///
 /// # Safety
diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_tests.rs
index b680cfd3c7..9dbbb848b8 100644
--- a/rust/tests/tests/vmstate_tests.rs
+++ b/rust/tests/tests/vmstate_tests.rs
@@ -411,106 +411,29 @@ fn test_vmstate_macro_array_of_pointer_wrapped() {
 // Test the use cases of the vmstate macro, corresponding to the following C
 // macro variants:
 //   * VMSTATE_FOOD:
-//     - VMSTATE_VALIDATE
-
-// Add more member fields when vmstate_of support "test" parameter.
-struct FooD;
-
-impl FooD {
-    fn validate_food_0(&self, _version_id: u8) -> bool {
-        true
-    }
-
-    fn validate_food_1(_state: &FooD, _version_id: u8) -> bool {
-        false
-    }
-}
-
-fn validate_food_2(_state: &FooD, _version_id: u8) -> bool {
-    true
-}
-
-static VMSTATE_FOOD: VMStateDescription<FooD> = VMStateDescriptionBuilder::<FooD>::new()
-    .name(c"foo_d")
-    .version_id(3)
-    .minimum_version_id(1)
-    .fields(vmstate_fields! {
-        vmstate_validate!(FooD, c"foo_d_0", FooD::validate_food_0),
-        vmstate_validate!(FooD, c"foo_d_1", FooD::validate_food_1),
-        vmstate_validate!(FooD, c"foo_d_2", validate_food_2),
-    })
-    .build();
-
-#[test]
-fn test_vmstate_validate() {
-    let foo_fields: &[VMStateField] =
-        unsafe { slice::from_raw_parts(VMSTATE_FOOD.as_ref().fields, 4) };
-    let mut foo_d = FooD;
-    let foo_d_p = std::ptr::addr_of_mut!(foo_d).cast::<c_void>();
-
-    // 1st VMStateField in VMSTATE_FOOD
-    assert_eq!(
-        unsafe { CStr::from_ptr(foo_fields[0].name) }.to_bytes_with_nul(),
-        b"foo_d_0\0"
-    );
-    assert_eq!(foo_fields[0].offset, 0);
-    assert_eq!(foo_fields[0].num_indirect.size, 0);
-    assert!(foo_fields[0].info.is_null());
-    assert_eq!(foo_fields[0].version_id, 0);
-    assert_eq!(foo_fields[0].size, 0);
-    assert_eq!(foo_fields[0].num, 0);
-    assert_eq!(
-        foo_fields[0].flags.0,
-        VMStateFlags::VMS_NO_STATE.0 | VMStateFlags::VMS_MUST_EXIST.0
-    );
-    assert!(foo_fields[0].vmsd.is_null());
-    assert!(unsafe { foo_fields[0].field_exists.unwrap()(foo_d_p, 0) });
-
-    // 2nd VMStateField in VMSTATE_FOOD
-    assert_eq!(
-        unsafe { CStr::from_ptr(foo_fields[1].name) }.to_bytes_with_nul(),
-        b"foo_d_1\0"
-    );
-    assert!(!unsafe { foo_fields[1].field_exists.unwrap()(foo_d_p, 1) });
-
-    // 3rd VMStateField in VMSTATE_FOOD
-    assert_eq!(
-        unsafe { CStr::from_ptr(foo_fields[2].name) }.to_bytes_with_nul(),
-        b"foo_d_2\0"
-    );
-    assert!(unsafe { foo_fields[2].field_exists.unwrap()(foo_d_p, 2) });
-
-    // The last VMStateField in VMSTATE_FOOD.
-    assert_eq!(foo_fields[3].flags, VMStateFlags::VMS_END);
-}
-
-// =========================== Test VMSTATE_FOOE ===========================
-// Test the use cases of the vmstate macro, corresponding to the following C
-// macro variants:
-//   * VMSTATE_FOOE:
 //     - VMSTATE_VARRAY with a `usize` length
 #[repr(C)]
 #[derive(Default)]
-struct FooE {
+struct FooD {
     arr: [u8; FOO_ARRAY_MAX],
     num: usize,
 }
 
-static VMSTATE_FOOE: VMStateDescription<FooE> = VMStateDescriptionBuilder::<FooE>::new()
-    .name(c"foo_e")
+static VMSTATE_FOOD: VMStateDescription<FooD> = VMStateDescriptionBuilder::<FooD>::new()
+    .name(c"foo_d")
     .version_id(1)
     .minimum_version_id(1)
     .fields(vmstate_fields! {
-        vmstate_of!(FooE, arr[0 .. num]),
+        vmstate_of!(FooD, arr[0 .. num]),
     })
     .build();
 
 #[test]
 fn test_vmstate_varray_usize() {
     let foo_fields: &[VMStateField] =
-        unsafe { slice::from_raw_parts(VMSTATE_FOOE.as_ref().fields, 2) };
+        unsafe { slice::from_raw_parts(VMSTATE_FOOD.as_ref().fields, 2) };
 
-    // 1st VMStateField ("arr") in VMSTATE_FOOE
+    // 1st VMStateField ("arr") in VMSTATE_FOOD
     assert_eq!(
         unsafe { CStr::from_ptr(foo_fields[0].name) }.to_bytes_with_nul(),
         b"arr\0"
@@ -518,7 +441,7 @@ fn test_vmstate_varray_usize() {
     assert_eq!(foo_fields[0].offset, 0);
     assert_eq!(
         foo_fields[0].num_indirect.offset,
-        std::mem::offset_of!(FooE, num) as u32
+        std::mem::offset_of!(FooD, num) as u32
     );
     assert_eq!(foo_fields[0].num_indirect.size, size_of::<usize>() as u8);
     assert_eq!(foo_fields[0].info, unsafe { &vmstate_info_uint8 });
@@ -529,6 +452,6 @@ fn test_vmstate_varray_usize() {
     assert!(foo_fields[0].vmsd.is_null());
     assert!(foo_fields[0].field_exists.is_none());
 
-    // The last VMStateField in VMSTATE_FOOE.
+    // The last VMStateField in VMSTATE_FOOD.
     assert_eq!(foo_fields[1].flags, VMStateFlags::VMS_END);
 }
-- 
2.56.0



  parent reply	other threads:[~2026-11-26 23:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 23:16 [PATCH for-12.0 v2 0/9] migration: Remove VMSTATE_VALIDATE() and VMS_MUST_EXIST Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 1/9] rust/migration: Allow usize as the length of a varray Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 2/9] rust/hpet: Move vmstate_validate!() check into post_load Peter Xu
2026-11-26 23:16 ` Peter Xu [this message]
2026-11-26 23:16 ` [PATCH for-12.0 v2 4/9] pcie/aer: Remove the usage of VMSTATE_VALIDATE() Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 5/9] hw/gpio/zaurus: Move VMSTATE_VALIDATE() check into post_load_errp() Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 6/9] hpet: Move VMSTATE_VALIDATE() check into post_load Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 7/9] arm/machine: Convert cpu_post_load() to take Error** Peter Xu
2026-11-27 13:22   ` Fabiano Rosas
2026-11-27 14:23     ` Peter Xu
2026-11-27 14:44       ` Peter Maydell
2026-11-27 17:00         ` Eric Auger
2026-11-26 23:16 ` [PATCH for-12.0 v2 8/9] arm/machine: Move all VMSTATE_VALIDATE() usages into post_load Peter Xu
2026-11-27 13:41   ` Fabiano Rosas
2026-11-27 13:50     ` Peter Maydell
2026-11-27 14:29     ` Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 9/9] migration: Drop VMSTATE_VALIDATE() and VMS_MUST_EXIST Peter Xu
2026-11-27 14:16   ` Fabiano Rosas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126231631.3392756-4-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=farosas@suse.de \
    --cc=gshan@redhat.com \
    --cc=jmarcin@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.