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