tests.rs 1.8 KB

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