1 // Copyright 2024, Linaro Limited 2 // Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org> 3 // SPDX-License-Identifier: GPL-2.0-or-later 4 5 use std::ffi::CStr; 6 7 use qemu_api::{ 8 bindings::*, 9 c_str, declare_properties, define_property, 10 definitions::ObjectImpl, 11 device_class::{self, DeviceImpl}, 12 impl_device_class, 13 zeroable::Zeroable, 14 }; 15 16 #[test] 17 fn test_device_decl_macros() { 18 // Test that macros can compile. 19 pub static VMSTATE: VMStateDescription = VMStateDescription { 20 name: c_str!("name").as_ptr(), 21 unmigratable: true, 22 ..Zeroable::ZERO 23 }; 24 25 #[derive(qemu_api_macros::offsets)] 26 #[repr(C)] 27 #[derive(qemu_api_macros::Object)] 28 pub struct DummyState { 29 pub _parent: DeviceState, 30 pub migrate_clock: bool, 31 } 32 33 #[repr(C)] 34 pub struct DummyClass { 35 pub _parent: DeviceClass, 36 } 37 38 declare_properties! { 39 DUMMY_PROPERTIES, 40 define_property!( 41 c_str!("migrate-clk"), 42 DummyState, 43 migrate_clock, 44 unsafe { &qdev_prop_bool }, 45 bool 46 ), 47 } 48 49 impl ObjectImpl for DummyState { 50 type Class = DummyClass; 51 const TYPE_NAME: &'static CStr = c_str!("dummy"); 52 const PARENT_TYPE_NAME: Option<&'static CStr> = Some(device_class::TYPE_DEVICE); 53 } 54 55 impl DeviceImpl for DummyState { 56 fn properties() -> &'static [Property] { 57 &DUMMY_PROPERTIES 58 } 59 fn vmsd() -> Option<&'static VMStateDescription> { 60 Some(&VMSTATE) 61 } 62 } 63 64 impl_device_class!(DummyState); 65 66 unsafe { 67 module_call_init(module_init_type::MODULE_INIT_QOM); 68 object_unref(object_new(DummyState::TYPE_NAME.as_ptr()).cast()); 69 } 70 } 71