[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 01/10] rust: qemu-api: add sub-subclass to the integration tests
From: |
Paolo Bonzini |
Subject: |
[PATCH 01/10] rust: qemu-api: add sub-subclass to the integration tests |
Date: |
Fri, 17 Jan 2025 20:39:54 +0100 |
From: Zhao Liu <zhao1.liu@intel.com>
missing signed-off-by from zhao
---
rust/qemu-api/tests/tests.rs | 56 ++++++++++++++++++++++++++++++++++--
1 file changed, 53 insertions(+), 3 deletions(-)
diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs
index 526c3f4f8ea..5c3e75ed3d5 100644
--- a/rust/qemu-api/tests/tests.rs
+++ b/rust/qemu-api/tests/tests.rs
@@ -14,8 +14,8 @@
cell::{self, BqlCell},
declare_properties, define_property,
prelude::*,
- qdev::{DeviceImpl, DeviceState, Property},
- qom::{ObjectImpl, ParentField},
+ qdev::{DeviceClass, DeviceImpl, DeviceState, Property},
+ qom::{ClassInitImpl, ObjectImpl, ParentField},
vmstate::VMStateDescription,
zeroable::Zeroable,
};
@@ -37,6 +37,10 @@ pub struct DummyState {
qom_isa!(DummyState: Object, DeviceState);
+pub struct DummyClass {
+ parent_class: <DeviceState as ObjectType>::Class,
+}
+
declare_properties! {
DUMMY_PROPERTIES,
define_property!(
@@ -49,7 +53,7 @@ pub struct DummyState {
}
unsafe impl ObjectType for DummyState {
- type Class = <DeviceState as ObjectType>::Class;
+ type Class = DummyClass;
const TYPE_NAME: &'static CStr = c_str!("dummy");
}
@@ -67,6 +71,51 @@ fn vmsd() -> Option<&'static VMStateDescription> {
}
}
+// `impl<T> ClassInitImpl<DummyClass> for T` doesn't work since it violates
+// orphan rule.
+impl ClassInitImpl<DummyClass> for DummyState {
+ fn class_init(klass: &mut DummyClass) {
+ <Self as ClassInitImpl<DeviceClass>>::class_init(&mut
klass.parent_class);
+ }
+}
+
+#[derive(qemu_api_macros::offsets)]
+#[repr(C)]
+#[derive(qemu_api_macros::Object)]
+pub struct DummyChildState {
+ parent: ParentField<DummyState>,
+}
+
+qom_isa!(DummyChildState: Object, DeviceState, DummyState);
+
+pub struct DummyChildClass {
+ parent_class: <DummyState as ObjectType>::Class,
+}
+
+unsafe impl ObjectType for DummyChildState {
+ type Class = DummyChildClass;
+ const TYPE_NAME: &'static CStr = c_str!("dummy_child");
+}
+
+impl ObjectImpl for DummyChildState {
+ type ParentType = DummyState;
+ const ABSTRACT: bool = false;
+}
+
+impl DeviceImpl for DummyChildState {}
+
+impl ClassInitImpl<DummyClass> for DummyChildState {
+ fn class_init(klass: &mut DummyClass) {
+ <Self as ClassInitImpl<DeviceClass>>::class_init(&mut
klass.parent_class);
+ }
+}
+
+impl ClassInitImpl<DummyChildClass> for DummyChildState {
+ fn class_init(klass: &mut DummyChildClass) {
+ <Self as ClassInitImpl<DummyClass>>::class_init(&mut
klass.parent_class);
+ }
+}
+
fn init_qom() {
static ONCE: BqlCell<bool> = BqlCell::new(false);
@@ -85,6 +134,7 @@ fn test_object_new() {
init_qom();
unsafe {
object_unref(object_new(DummyState::TYPE_NAME.as_ptr()).cast());
+ object_unref(object_new(DummyChildState::TYPE_NAME.as_ptr()).cast());
}
}
--
2.47.1
- [RFC PATCH 00/10] rust: remaining part of qdev bindings, Paolo Bonzini, 2025/01/17
- [PATCH 01/10] rust: qemu-api: add sub-subclass to the integration tests,
Paolo Bonzini <=
- [PATCH 02/10] rust: qom: add reference counting functionality, Paolo Bonzini, 2025/01/17
- [PATCH 03/10] rust: qom: add object creation functionality, Paolo Bonzini, 2025/01/17
- [PATCH 04/10] rust: callbacks: allow passing optional callbacks as (), Paolo Bonzini, 2025/01/17
- [PATCH 06/10] rust: qom: allow initializing interface vtables, Paolo Bonzini, 2025/01/17
- [PATCH 07/10] rust: qdev: make ObjectImpl a supertrait of DeviceImpl, Paolo Bonzini, 2025/01/17
- [PATCH 05/10] rust: qdev: add clock creation, Paolo Bonzini, 2025/01/17
- [PATCH 09/10] rust: bindings: add Sync markers to types referred to by MemoryRegionOps, Paolo Bonzini, 2025/01/17
- [PATCH 08/10] rust: qdev: switch from legacy reset to Resettable, Paolo Bonzini, 2025/01/17
- [PATCH 10/10] rust: bindings for MemoryRegionOps, Paolo Bonzini, 2025/01/17