From 5ced9582da92c0a443cee3370d7ad26c004c3c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Wed, 13 Sep 2023 16:18:41 +0200 Subject: [PATCH 1/2] utils/immut_after_init: remove deprecated doctest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the deprecated documentation for ImmutAfterInitRef::new_from_cell(), which caused a doctest to fail. This method got got removed in order to not depend on a nightly feature. Fixes: 0b9c951122a8 ("svsm: do not depend on nightly const_mut_refs feature") Signed-off-by: Carlos López --- src/utils/immut_after_init.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/utils/immut_after_init.rs b/src/utils/immut_after_init.rs index 69e4862c0..cf5a8861a 100644 --- a/src/utils/immut_after_init.rs +++ b/src/utils/immut_after_init.rs @@ -203,27 +203,8 @@ unsafe impl Sync for ImmutAfterInitCell {} /// } /// ``` /// -/// Also, a `ImmutAfterInitRef` can get initialized by dereferencing another, -/// possibly temporary `ImmutAfterInitRef`, with the temporary again either -/// dereferencing a [`ImmutAfterInitCell`]'s contents, -/// ``` -/// # use svsm::utils::immut_after_init::{ImmutAfterInitCell, ImmutAfterInitRef}; -/// static RX : ImmutAfterInitRef::<'static, i32> = ImmutAfterInitRef::uninit(); -/// -/// fn init_rx(r : ImmutAfterInitRef<'static, i32>) { -/// unsafe { RX.init_from_ref(r.get()) }; -/// } -/// -/// static X : ImmutAfterInitCell = ImmutAfterInitCell::uninit(); -/// -/// fn main() { -/// unsafe { X.init(&123) }; -/// -/// init_rx(ImmutAfterInitRef::new_from_cell(&X)); -/// assert_eq!(*RX, 123); -/// } -/// ``` -/// or a plain value directly: +/// Also, an `ImmutAfterInitRef` can be initialized by obtaining a reference +/// from another `ImmutAfterInitRef`: /// ``` /// # use svsm::utils::immut_after_init::ImmutAfterInitRef; /// static RX : ImmutAfterInitRef::<'static, i32> = ImmutAfterInitRef::uninit(); From 651b3ca3b7bae753cbb23aa7caa7488df742c768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Wed, 13 Sep 2023 16:30:16 +0200 Subject: [PATCH 2/2] test: fix doctests and run in Makefile target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our custom bare-metal allocator (`SvsmAllocator`) does not work during tests, as they run as regular userspace binaries. Thus, we must not set it as the global Rust allocator. To do this, we need a compile-time directive that lets us know we are building doctests and not the regular binary (`cfg(doctests)`), but sadly it is not properly set during test compilation (see rust-lang/rust#45599, rust-lang/rust#67295 and coconut-svsm/svsm#93). In order to bypass this, set the compile time flag ourselves via the RUSTFLAGS environment variable so that tests work. Also add the new invocation to the `test` target in the Makefile. Fixes: coconut-svsm/svsm#93 Fixes: 8cdea8e2a215 ("Cargo manifest: disable doctests") Signed-off-by: Carlos López --- Makefile | 1 + src/mm/alloc.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f0a23b6ab..2a75262da 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ all: svsm.bin test: cargo test --target=x86_64-unknown-linux-gnu + RUSTFLAGS="--cfg doctest" cargo test --target=x86_64-unknown-linux-gnu --doc utils/gen_meta: utils/gen_meta.c cc -O3 -Wall -o $@ $< diff --git a/src/mm/alloc.rs b/src/mm/alloc.rs index 6b3cf6339..6e0d4ae1d 100644 --- a/src/mm/alloc.rs +++ b/src/mm/alloc.rs @@ -1282,7 +1282,7 @@ unsafe impl GlobalAlloc for SvsmAllocator { } } -#[cfg_attr(not(test), global_allocator)] +#[cfg_attr(not(any(test, doctest)), global_allocator)] pub static mut ALLOCATOR: SvsmAllocator = SvsmAllocator::new(); pub fn root_mem_init(pstart: PhysAddr, vstart: VirtAddr, page_count: usize) {