1*cde3c425SPaolo Bonzini // Copyright 2024, Linaro Limited 2*cde3c425SPaolo Bonzini // Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org> 3*cde3c425SPaolo Bonzini // SPDX-License-Identifier: GPL-2.0-or-later 4*cde3c425SPaolo Bonzini 5*cde3c425SPaolo Bonzini use core::ffi::CStr; 6*cde3c425SPaolo Bonzini 7*cde3c425SPaolo Bonzini use qemu_api::{ 8*cde3c425SPaolo Bonzini bindings::*, 9*cde3c425SPaolo Bonzini declare_properties, define_property, 10*cde3c425SPaolo Bonzini definitions::{Class, ObjectImpl}, 11*cde3c425SPaolo Bonzini device_class_init, vm_state_description, 12*cde3c425SPaolo Bonzini }; 13*cde3c425SPaolo Bonzini 14*cde3c425SPaolo Bonzini #[test] 15*cde3c425SPaolo Bonzini fn test_device_decl_macros() { 16*cde3c425SPaolo Bonzini // Test that macros can compile. 17*cde3c425SPaolo Bonzini vm_state_description! { 18*cde3c425SPaolo Bonzini VMSTATE, 19*cde3c425SPaolo Bonzini name: c"name", 20*cde3c425SPaolo Bonzini unmigratable: true, 21*cde3c425SPaolo Bonzini } 22*cde3c425SPaolo Bonzini 23*cde3c425SPaolo Bonzini #[repr(C)] 24*cde3c425SPaolo Bonzini #[derive(qemu_api_macros::Object)] 25*cde3c425SPaolo Bonzini pub struct DummyState { 26*cde3c425SPaolo Bonzini pub _parent: DeviceState, 27*cde3c425SPaolo Bonzini pub migrate_clock: bool, 28*cde3c425SPaolo Bonzini } 29*cde3c425SPaolo Bonzini 30*cde3c425SPaolo Bonzini #[repr(C)] 31*cde3c425SPaolo Bonzini pub struct DummyClass { 32*cde3c425SPaolo Bonzini pub _parent: DeviceClass, 33*cde3c425SPaolo Bonzini } 34*cde3c425SPaolo Bonzini 35*cde3c425SPaolo Bonzini declare_properties! { 36*cde3c425SPaolo Bonzini DUMMY_PROPERTIES, 37*cde3c425SPaolo Bonzini define_property!( 38*cde3c425SPaolo Bonzini c"migrate-clk", 39*cde3c425SPaolo Bonzini DummyState, 40*cde3c425SPaolo Bonzini migrate_clock, 41*cde3c425SPaolo Bonzini unsafe { &qdev_prop_bool }, 42*cde3c425SPaolo Bonzini bool 43*cde3c425SPaolo Bonzini ), 44*cde3c425SPaolo Bonzini } 45*cde3c425SPaolo Bonzini 46*cde3c425SPaolo Bonzini device_class_init! { 47*cde3c425SPaolo Bonzini dummy_class_init, 48*cde3c425SPaolo Bonzini props => DUMMY_PROPERTIES, 49*cde3c425SPaolo Bonzini realize_fn => None, 50*cde3c425SPaolo Bonzini legacy_reset_fn => None, 51*cde3c425SPaolo Bonzini vmsd => VMSTATE, 52*cde3c425SPaolo Bonzini } 53*cde3c425SPaolo Bonzini 54*cde3c425SPaolo Bonzini impl ObjectImpl for DummyState { 55*cde3c425SPaolo Bonzini type Class = DummyClass; 56*cde3c425SPaolo Bonzini const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self }; 57*cde3c425SPaolo Bonzini const TYPE_NAME: &'static CStr = c"dummy"; 58*cde3c425SPaolo Bonzini const PARENT_TYPE_NAME: Option<&'static CStr> = Some(TYPE_DEVICE); 59*cde3c425SPaolo Bonzini const ABSTRACT: bool = false; 60*cde3c425SPaolo Bonzini const INSTANCE_INIT: Option<unsafe extern "C" fn(obj: *mut Object)> = None; 61*cde3c425SPaolo Bonzini const INSTANCE_POST_INIT: Option<unsafe extern "C" fn(obj: *mut Object)> = None; 62*cde3c425SPaolo Bonzini const INSTANCE_FINALIZE: Option<unsafe extern "C" fn(obj: *mut Object)> = None; 63*cde3c425SPaolo Bonzini } 64*cde3c425SPaolo Bonzini 65*cde3c425SPaolo Bonzini impl Class for DummyClass { 66*cde3c425SPaolo Bonzini const CLASS_INIT: Option< 67*cde3c425SPaolo Bonzini unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), 68*cde3c425SPaolo Bonzini > = Some(dummy_class_init); 69*cde3c425SPaolo Bonzini const CLASS_BASE_INIT: Option< 70*cde3c425SPaolo Bonzini unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi::c_void), 71*cde3c425SPaolo Bonzini > = None; 72*cde3c425SPaolo Bonzini } 73*cde3c425SPaolo Bonzini 74*cde3c425SPaolo Bonzini unsafe { 75*cde3c425SPaolo Bonzini module_call_init(module_init_type::MODULE_INIT_QOM); 76*cde3c425SPaolo Bonzini object_unref(object_new(DummyState::TYPE_NAME.as_ptr()) as *mut _); 77*cde3c425SPaolo Bonzini } 78*cde3c425SPaolo Bonzini } 79