summary refs log tree commit diff stats
path: root/rust/qemu-api/tests/tests.rs (follow)
Commit message (Collapse)AuthorAgeFilesLines
* rust: qom: change the parent type to an associated typePaolo Bonzini2024-12-111-2/+1
| | | | | | | | Avoid duplicated code to retrieve the QOM type strings from the Rust type. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: qom: split ObjectType from ObjectImpl traitPaolo Bonzini2024-12-111-8/+9
| | | | | | | | | | | | | | | | | | Define a separate trait for fields that also applies to classes that are defined by C code. This makes it possible to add metadata to core classes, which has multiple uses: - it makes it possible to access the parent struct's TYPE_* for types that are defined in Rust code, and to avoid repeating it in every subclass - implementors of ObjectType will be allowed to implement the IsA<> trait and therefore to perform typesafe casts from one class to another. - in the future, an ObjectType could be created with Foo::new() in a type-safe manner, without having to pass a TYPE_* constant. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: qdev: move device_class_init! body to generic function, ClassInitImpl ↵Paolo Bonzini2024-12-101-17/+13
| | | | | | | | | | | | | | | | | | | implementation to macro Use a trait to access the former parameters to device_class_init!. This allows hiding the details of the class_init implementation behind a generic function and makes higher-level functionality available from qemu_api. The implementation of ClassInitImpl is then the same for all devices and is easily macroized. Later on, we can remove the need to implement ClassInitImpl by hand for all device types, and stop making rust_device_class_init<>() public. While at it, document the members of DeviceImpl. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: qom: move ClassInitImpl to the instance sidePaolo Bonzini2024-12-101-1/+1
| | | | | | | | | | | | | Put all traits on the instance struct, which makes it possible to reuse class structs if no new virtual methods or class fields are added. This is almost always the case for devices (because they are leaf classes), which is the primary use case for Rust. This is also simpler: soon we will find the implemented methods without macros, and this removes the need to go from the class struct to the instance struct to find the implementation of the *Impl traits. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: qom: convert type_info! macro to an associated constPaolo Bonzini2024-12-101-1/+0
| | | | | | | | type_info! is only used in the definition of ObjectImpl::TYPE_INFO, and in fact in all of them. Pull type_info!'s definition into the ObjectImpl trait, thus simplifying the external interface of qemu_api::definitions. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: qom: rename Class trait to ClassInitImplPaolo Bonzini2024-12-101-2/+2
| | | | | | While at it, document it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: qom: add default definitions for ObjectImplPaolo Bonzini2024-12-101-4/+0
| | | | | | Remove a bunch of duplicate const definitions. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: fix a couple style issues from clippyPaolo Bonzini2024-12-101-1/+1
| | | | | | | | | | These are reported as clippy::semicolon_inside_block and clippy::as_ptr_cast_mut. clippy::semicolon_inside_block can be configured not to lint single-line blocks; just go with the default. Reviewed-by: Junjie Mao <junjie.mao@hotmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: do not use --generate-cstrPaolo Bonzini2024-11-051-2/+2
| | | | | | | | --generate-cstr is a good idea and generally the right thing to do, but it is not available in Debian 12 and Ubuntu 22.04. Work around the absence. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: introduce alternative implementation of offset_of!Junjie Mao2024-11-051-0/+1
| | | | | | | | | | | | | | | | | | | | | offset_of! was stabilized in Rust 1.77.0. Use an alternative implemenation that was found on the Rust forums, and whose author agreed to license as MIT for use in QEMU. The alternative allows only one level of field access, but apart from this can be used just by replacing core::mem::offset_of! with qemu_api::offset_of!. The actual implementation of offset_of! is done in a declarative macro, but for simplicity and to avoid introducing an extra level of indentation, the trigger is a procedural macro #[derive(offsets)]. The procedural macro is perhaps a bit overengineered, but it helps introducing some idioms that will be useful in the future as well. Signed-off-by: Junjie Mao <junjie.mao@hotmail.com> Co-developed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: introduce a c_str macroPaolo Bonzini2024-11-051-4/+4
| | | | | | | | | This allows CStr constants to be defined easily on Rust 1.63.0, while checking that there are no embedded NULs. c"" literals were only stabilized in Rust 1.77.0. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: use std::os::raw instead of core::ffiPaolo Bonzini2024-11-051-5/+4
| | | | | | | | | | core::ffi::c_* types were introduced in Rust 1.64.0. Use the older types in std::os::raw, which are now aliases of the types in core::ffi. There is no need to compile QEMU as no_std, so this is acceptable as long as we support a version of Debian with Rust 1.63.0. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: add definitions for vmstateManos Pitsidianakis2024-11-051-5/+6
| | | | | | | | | | | | | | | | | | | | | | | Add a new qemu_api module, `vmstate`. Declare a bunch of Rust macros declared that are equivalent in spirit to the C macros in include/migration/vmstate.h. For example the Rust of equivalent of the C macro: VMSTATE_UINT32(field_name, struct_name) is: vmstate_uint32!(field_name, StructName) This breathtaking development will allow us to reach feature parity between the Rust and C pl011 implementations. Extracted from a patch by Manos Pitsidianakis (https://lore.kernel.org/qemu-devel/20241024-rust-round-2-v1-4-051e7a25b978@linaro.org/). Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* rust: build integration test for the qemu_api cratePaolo Bonzini2024-11-051-0/+78
Adjust the integration test to compile with a subset of QEMU object files, and make it actually create an object of the class it defines. Follow the Rust filesystem conventions, where tests go in tests/ if they use the library in the same way any other code would. Reviewed-by: Junjie Mao <junjie.mao@hotmail.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>