diff --git a/components/patina_acpi/src/acpi.rs b/components/patina_acpi/src/acpi.rs index cdec7c984..aa0ef98cd 100644 --- a/components/patina_acpi/src/acpi.rs +++ b/components/patina_acpi/src/acpi.rs @@ -813,8 +813,6 @@ where #[cfg(test)] mod tests { - extern crate std; - use crate::signature::MAX_INITIAL_ENTRIES; use super::*; diff --git a/components/patina_acpi/src/service.rs b/components/patina_acpi/src/service.rs index 56457b725..6def1b1a8 100644 --- a/components/patina_acpi/src/service.rs +++ b/components/patina_acpi/src/service.rs @@ -168,9 +168,9 @@ pub(crate) trait AcpiProvider { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - use alloc::boxed::Box; use core::mem; use patina::component::service::memory::StdMemoryManager; + use std::boxed::Box; use crate::acpi_table::AcpiFadt; diff --git a/components/patina_adv_logger/src/lib.rs b/components/patina_adv_logger/src/lib.rs index e198f08f0..89393e995 100644 --- a/components/patina_adv_logger/src/lib.rs +++ b/components/patina_adv_logger/src/lib.rs @@ -8,7 +8,7 @@ #![deny(missing_docs)] #![cfg_attr(coverage, feature(coverage_attribute))] -#[cfg(any(feature = "alloc", test, doc))] +#[cfg(any(feature = "alloc", doc))] extern crate alloc; mod memory_log; diff --git a/components/patina_adv_logger/src/logger.rs b/components/patina_adv_logger/src/logger.rs index 4699c7e96..f17996018 100644 --- a/components/patina_adv_logger/src/logger.rs +++ b/components/patina_adv_logger/src/logger.rs @@ -351,7 +351,6 @@ where mod tests { use core::{ffi::c_void, ptr}; - use alloc::boxed::Box; use log::Log; use patina::standard::efi; use patina::{ @@ -360,6 +359,7 @@ mod tests { peripheral::serial::uart::UartNull, pi::hob::{GUID_EXTENSION, GuidHob, HobHeader}, }; + use std::boxed::Box; use crate::{ logger::{AdvancedLogger, TargetFilter}, diff --git a/components/patina_adv_logger/src/memory_log.rs b/components/patina_adv_logger/src/memory_log.rs index bde572418..c776ea2f6 100644 --- a/components/patina_adv_logger/src/memory_log.rs +++ b/components/patina_adv_logger/src/memory_log.rs @@ -423,9 +423,9 @@ impl AdvLoggerMessageEntry { const TEST_DATA_SIZE: usize = 128; #[cfg(test)] -pub(crate) fn create_buffer_v5(timer_frequency: u64, hw_port_disabled: bool) -> alloc::boxed::Box<[u8]> { +pub(crate) fn create_buffer_v5(timer_frequency: u64, hw_port_disabled: bool) -> std::boxed::Box<[u8]> { let header_size = size_of::(); - let mut buffer = alloc::vec![0_u8; header_size + TEST_DATA_SIZE].into_boxed_slice(); + let mut buffer = std::vec![0_u8; header_size + TEST_DATA_SIZE].into_boxed_slice(); let header = AdvLoggerInfoV5 { signature: AdvLoggerInfo::SIGNATURE, version: ADV_LOGGER_INFO_VERSION_V5, @@ -457,9 +457,9 @@ pub(crate) fn create_buffer_v5(timer_frequency: u64, hw_port_disabled: bool) -> } #[cfg(test)] -pub(crate) fn create_buffer_v6(timer_frequency: u64, new_address: u64) -> alloc::boxed::Box<[u8]> { +pub(crate) fn create_buffer_v6(timer_frequency: u64, new_address: u64) -> std::boxed::Box<[u8]> { let header_size = size_of::(); - let mut buffer = alloc::vec![0_u8; header_size + TEST_DATA_SIZE].into_boxed_slice(); + let mut buffer = std::vec![0_u8; header_size + TEST_DATA_SIZE].into_boxed_slice(); let header = AdvLoggerInfoV6 { v5: AdvLoggerInfoV5 { signature: AdvLoggerInfo::SIGNATURE, diff --git a/components/patina_adv_logger/src/reader.rs b/components/patina_adv_logger/src/reader.rs index a7816797d..1f3705484 100644 --- a/components/patina_adv_logger/src/reader.rs +++ b/components/patina_adv_logger/src/reader.rs @@ -154,7 +154,6 @@ impl<'a> Iterator for AdvLogIterator<'a> { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; use core::{mem::size_of, sync::atomic::Ordering}; use super::*; diff --git a/components/patina_adv_logger/src/writer.rs b/components/patina_adv_logger/src/writer.rs index f495b2a55..212c537d7 100644 --- a/components/patina_adv_logger/src/writer.rs +++ b/components/patina_adv_logger/src/writer.rs @@ -192,10 +192,9 @@ impl AdvancedLogWriter { #[cfg(all(test, feature = "reader"))] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; - use alloc::boxed::Box; use core::{mem::size_of, sync::atomic::Ordering}; use efi::PhysicalAddress; + use std::boxed::Box; use super::*; use crate::{memory_log::*, reader::AdvancedLogReader}; diff --git a/components/patina_mm/src/component/communicator/comm_buffer_update.rs b/components/patina_mm/src/component/communicator/comm_buffer_update.rs index df7b6e713..d197b337c 100644 --- a/components/patina_mm/src/component/communicator/comm_buffer_update.rs +++ b/components/patina_mm/src/component/communicator/comm_buffer_update.rs @@ -277,7 +277,7 @@ mod tests { }; use patina::uefi::boot_services::StandardBootServices; - use alloc::boxed::Box; + use std::boxed::Box; /// Helper to create a test protocol notify context without boot services fn create_test_context(updatable_buffer_id: u8) -> Box { diff --git a/components/patina_mm/tests/patina_mm_integration/common/framework.rs b/components/patina_mm/tests/patina_mm_integration/common/framework.rs index 26954510f..be3599620 100644 --- a/components/patina_mm/tests/patina_mm_integration/common/framework.rs +++ b/components/patina_mm/tests/patina_mm_integration/common/framework.rs @@ -12,9 +12,8 @@ //! SPDX-License-Identifier: Apache-2.0 use crate::patina_mm_integration::common::{constants::*, handlers::*, message_parser::*}; -extern crate alloc; -use alloc::{boxed::Box, string::String, vec::Vec}; use patina::BinaryGuid; +use std::{boxed::Box, string::String, vec::Vec}; use std::{ collections::HashMap, sync::{ diff --git a/components/patina_mm/tests/patina_mm_integration/common/handlers.rs b/components/patina_mm/tests/patina_mm_integration/common/handlers.rs index b24113c10..c4c52e841 100644 --- a/components/patina_mm/tests/patina_mm_integration/common/handlers.rs +++ b/components/patina_mm/tests/patina_mm_integration/common/handlers.rs @@ -19,8 +19,7 @@ use crate::patina_mm_integration::common::constants::*; use patina::standard::efi; -extern crate alloc; -use alloc::{string::String, vec::Vec}; +use std::{string::String, vec::Vec}; pub use zerocopy::IntoBytes; pub use patina::management_mode::protocol::{ diff --git a/components/patina_mm/tests/patina_mm_integration/common/message_parser.rs b/components/patina_mm/tests/patina_mm_integration/common/message_parser.rs index b79c27661..77b86cd12 100644 --- a/components/patina_mm/tests/patina_mm_integration/common/message_parser.rs +++ b/components/patina_mm/tests/patina_mm_integration/common/message_parser.rs @@ -10,9 +10,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 -extern crate alloc; -#[allow(unused_imports)] // Used in test module within this file -use alloc::vec::Vec; use patina::BinaryGuid; /// Error types for MM message parsing operations diff --git a/components/patina_mm/tests/patina_mm_integration/common/real_component_framework.rs b/components/patina_mm/tests/patina_mm_integration/common/real_component_framework.rs index a9ea28ed5..05da507c6 100644 --- a/components/patina_mm/tests/patina_mm_integration/common/real_component_framework.rs +++ b/components/patina_mm/tests/patina_mm_integration/common/real_component_framework.rs @@ -16,12 +16,12 @@ use crate::patina_mm_integration::common::{constants::*, handlers::*}; -extern crate alloc; -use alloc::{boxed::Box, vec::Vec}; use patina::Guid; use std::{ + boxed::Box, collections::BTreeMap, sync::{Arc, Mutex}, + vec::Vec, }; // Import the real patina_mm components and services diff --git a/components/patina_mm/tests/patina_mm_integration/tests_root.rs b/components/patina_mm/tests/patina_mm_integration/tests_root.rs index 17c8315cc..8e30560ba 100644 --- a/components/patina_mm/tests/patina_mm_integration/tests_root.rs +++ b/components/patina_mm/tests/patina_mm_integration/tests_root.rs @@ -31,8 +31,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 -extern crate alloc; - // Common utilities available to all test modules mod common; diff --git a/components/patina_performance/src/component/performance.rs b/components/patina_performance/src/component/performance.rs index 7618b9520..3c0fa3fad 100644 --- a/components/patina_performance/src/component/performance.rs +++ b/components/patina_performance/src/component/performance.rs @@ -525,7 +525,6 @@ mod tests { }; use patina::standard::efi; - use alloc::sync::Arc; use patina::{ c_ptr::{CMutPtr, CPtr}, component::service::{IntoService, Service}, @@ -537,6 +536,7 @@ mod tests { uefi::{boot_services::MockBootServices, runtime_services::MockRuntimeServices}, }; use patina_mm::component::communicator::{MmCommunication, Status}; + use std::sync::Arc; // Some constants shared between tests const TEST_EVENT_HANDLE: efi::Event = 1_usize as efi::Event; @@ -760,7 +760,7 @@ mod tests { boot_services.expect_close_event().once().return_const(Ok(())); // The component allocates the publishing buffer itself; hand back a real leaked page-sized buffer. - let leaked_buffer = Box::leak(alloc::vec![0u8; UEFI_PAGE_SIZE].into_boxed_slice()); + let leaked_buffer = Box::leak(std::vec![0u8; UEFI_PAGE_SIZE].into_boxed_slice()); let leaked_buffer_addr = leaked_buffer.as_mut_ptr() as usize; boot_services.expect_allocate_pages().once().returning(move |_, _, _| Ok(leaked_buffer_addr)); diff --git a/components/patina_samples/src/lib.rs b/components/patina_samples/src/lib.rs index 75c04e863..ff70b88f3 100644 --- a/components/patina_samples/src/lib.rs +++ b/components/patina_samples/src/lib.rs @@ -15,9 +15,11 @@ //! //! SPDX-License-Identifier: Apache-2.0 //! -#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(all(not(feature = "std"), not(test)), no_std)] #![deny(missing_docs)] #![cfg_attr(coverage, feature(coverage_attribute))] #![cfg_attr(coverage, coverage(off))] // Disable all coverage instrumentation for sample code +extern crate alloc; + pub mod component; pub mod smbios_platform; diff --git a/components/patina_samples/src/smbios_platform.rs b/components/patina_samples/src/smbios_platform.rs index 7d1cf292e..dd2c546c9 100644 --- a/components/patina_samples/src/smbios_platform.rs +++ b/components/patina_samples/src/smbios_platform.rs @@ -28,8 +28,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 -extern crate alloc; - use alloc::{string::String, vec}; use patina::{ component::{component, service::Service}, diff --git a/components/patina_smbios/src/component.rs b/components/patina_smbios/src/component.rs index ae319b1e2..2500f2899 100644 --- a/components/patina_smbios/src/component.rs +++ b/components/patina_smbios/src/component.rs @@ -8,7 +8,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 -extern crate alloc; use crate::{ error::SmbiosError, manager::SmbiosManager, @@ -143,7 +142,6 @@ impl SmbiosProvider { #[cfg(test)] mod tests { use super::*; - extern crate std; #[test] fn test_smbios_provider_new() { diff --git a/components/patina_smbios/src/error.rs b/components/patina_smbios/src/error.rs index 0ad7b63b4..9f4f74884 100644 --- a/components/patina_smbios/src/error.rs +++ b/components/patina_smbios/src/error.rs @@ -121,7 +121,6 @@ mod tests { #[test] fn test_smbios_error_all_variants() { - extern crate std; use std::vec; // Test all error variants for completeness diff --git a/components/patina_smbios/src/lib.rs b/components/patina_smbios/src/lib.rs index c6ae9137e..7efd5e4b5 100644 --- a/components/patina_smbios/src/lib.rs +++ b/components/patina_smbios/src/lib.rs @@ -313,6 +313,8 @@ #![deny(missing_docs)] #![cfg_attr(coverage, feature(coverage_attribute))] +extern crate alloc; + // SMBIOS tables require little-endian byte order. The SmbiosRecord derive macro // uses zerocopy::IntoBytes::as_bytes() which returns native byte order. #[cfg(not(target_endian = "little"))] diff --git a/components/patina_smbios/src/manager.rs b/components/patina_smbios/src/manager.rs index 3749187fc..9da20e8e7 100644 --- a/components/patina_smbios/src/manager.rs +++ b/components/patina_smbios/src/manager.rs @@ -12,8 +12,6 @@ //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; - use patina::protocol::ProtocolInterface; mod core; diff --git a/components/patina_smbios/src/manager/core.rs b/components/patina_smbios/src/manager/core.rs index 50718b35e..9867adb3a 100644 --- a/components/patina_smbios/src/manager/core.rs +++ b/components/patina_smbios/src/manager/core.rs @@ -10,8 +10,6 @@ //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; - use alloc::{boxed::Box, collections::BTreeSet, string::String, vec::Vec}; use core::cell::RefCell; use patina::standard::efi::{Handle, PhysicalAddress}; @@ -755,14 +753,13 @@ impl SmbiosManager { #[cfg(test)] mod tests { use super::*; - extern crate std; - use std::{vec, vec::Vec}; - use crate::{ error::SmbiosError, service::{SMBIOS_HANDLE_PI_RESERVED, SMBIOS_STRING_MAX_LENGTH, SmbiosHandle, SmbiosTableHeader}, }; + use patina::component::service::memory::StdMemoryManager; use patina::standard::efi; + use std::{boxed::Box, vec, vec::Vec}; use zerocopy::IntoBytes; /// Test helper: Build a simple SMBIOS record with the given header and strings @@ -1771,10 +1768,6 @@ mod tests { #[test] fn test_allocate_buffers() { - use patina::component::service::memory::StdMemoryManager; - extern crate std; - use std::boxed::Box; - let manager = SmbiosManager::new(3, 9).expect("failed to create manager"); let memory_manager: &'static dyn patina::component::service::memory::MemoryManager = Box::leak(Box::new(StdMemoryManager::new())); @@ -1798,10 +1791,6 @@ mod tests { #[test] fn test_allocate_buffers_idempotent() { - use patina::component::service::memory::StdMemoryManager; - extern crate std; - use std::boxed::Box; - let manager = SmbiosManager::new(3, 9).expect("failed to create manager"); let memory_manager: &'static dyn patina::component::service::memory::MemoryManager = Box::leak(Box::new(StdMemoryManager::new())); @@ -1822,10 +1811,6 @@ mod tests { #[test] fn test_build_table_data() { - use patina::component::service::memory::StdMemoryManager; - extern crate std; - use std::boxed::Box; - let manager = SmbiosManager::new(3, 9).expect("failed to create manager"); let memory_manager: &'static dyn patina::component::service::memory::MemoryManager = Box::leak(Box::new(StdMemoryManager::new())); @@ -1865,10 +1850,6 @@ mod tests { #[test] fn test_build_table_data_copies_records_correctly() { - use patina::component::service::memory::StdMemoryManager; - extern crate std; - use std::boxed::Box; - let manager = SmbiosManager::new(3, 9).expect("failed to create manager"); let memory_manager: &'static dyn patina::component::service::memory::MemoryManager = Box::leak(Box::new(StdMemoryManager::new())); @@ -1899,10 +1880,6 @@ mod tests { #[test] fn test_build_table_data_no_records_error() { - use patina::component::service::memory::StdMemoryManager; - extern crate std; - use std::boxed::Box; - let manager = SmbiosManager::new(3, 9).expect("failed to create manager"); let memory_manager: &'static dyn patina::component::service::memory::MemoryManager = Box::leak(Box::new(StdMemoryManager::new())); diff --git a/components/patina_smbios/src/manager/protocol.rs b/components/patina_smbios/src/manager/protocol.rs index 193b8eb2e..874d34cd3 100644 --- a/components/patina_smbios/src/manager/protocol.rs +++ b/components/patina_smbios/src/manager/protocol.rs @@ -13,8 +13,6 @@ //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; - use core::ffi::c_char; use alloc::string::ToString; @@ -360,7 +358,6 @@ impl SmbiosProtocol { mod tests { use super::*; use crate::{error::SmbiosError, manager::SmbiosManager}; - extern crate std; use std::vec::Vec; fn create_test_bios_info_record() -> Vec { diff --git a/components/patina_smbios/src/manager/record.rs b/components/patina_smbios/src/manager/record.rs index b1008e925..d338c515a 100644 --- a/components/patina_smbios/src/manager/record.rs +++ b/components/patina_smbios/src/manager/record.rs @@ -10,8 +10,6 @@ //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; - use alloc::vec::Vec; use crate::service::SmbiosTableHeader; @@ -40,7 +38,6 @@ impl SmbiosRecord { #[cfg(test)] mod tests { use super::*; - extern crate std; use std::vec; use patina::standard::efi; diff --git a/components/patina_smbios/src/service.rs b/components/patina_smbios/src/service.rs index e0e4f26bf..0e83c599e 100644 --- a/components/patina_smbios/src/service.rs +++ b/components/patina_smbios/src/service.rs @@ -10,7 +10,6 @@ //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; use alloc::vec::Vec; use core::cell::Ref; pub use patina::standard::efi::industry::smbios::{ @@ -343,9 +342,6 @@ impl SmbiosExt for patina::component::service::Service { #[cfg(test)] mod tests { use super::*; - extern crate alloc; - extern crate std; - use alloc::string::String; use std::format; use crate::{ @@ -417,8 +413,8 @@ mod tests { #[test] fn test_smbios_records_iter_basic() { use crate::manager::SmbiosRecord; - use alloc::vec; use core::cell::RefCell; + use std::vec; let records = RefCell::new(vec![ SmbiosRecord::new(SmbiosTableHeader::new(0, 24, 0x0001), None, vec![], 0), @@ -444,8 +440,8 @@ mod tests { #[test] fn test_smbios_records_iter_with_filter() { use crate::manager::SmbiosRecord; - use alloc::vec; use core::cell::RefCell; + use std::vec; let records = RefCell::new(vec![ SmbiosRecord::new(SmbiosTableHeader::new(0, 24, 0x0001), None, vec![], 0), @@ -472,8 +468,8 @@ mod tests { #[test] fn test_smbios_records_iter_empty() { use crate::manager::SmbiosRecord; - use alloc::vec; use core::cell::RefCell; + use std::vec; let records: RefCell> = RefCell::new(vec![]); let borrowed = records.borrow(); @@ -485,8 +481,8 @@ mod tests { #[test] fn test_smbios_records_iter_no_match_filter() { use crate::manager::SmbiosRecord; - use alloc::vec; use core::cell::RefCell; + use std::vec; let records = RefCell::new(vec![ SmbiosRecord::new(SmbiosTableHeader::new(0, 24, 0x0001), None, vec![], 0), @@ -588,8 +584,8 @@ mod tests { #[test] fn test_mock_smbios_service_add_record_integration() { - use alloc::vec; use patina::component::service::Service; + use std::vec; // Create a test record let record = Type127EndOfTable { header: SmbiosTableHeader::new(127, 4, 0xFFFE), string_pool: vec![] }; @@ -625,8 +621,8 @@ mod tests { #[test] fn test_mock_add_record_extension_trait_pattern() { - use alloc::vec; use patina::component::service::Service; + use std::vec; // Create a test record let record = Type127EndOfTable { header: SmbiosTableHeader::new(127, 4, 0xFFFE), string_pool: vec![] }; @@ -655,8 +651,8 @@ mod tests { #[test] fn test_mock_add_record_with_error() { - use alloc::vec; use patina::component::service::Service; + use std::vec; // Mock that returns an error let mock = MockSmbios { @@ -677,8 +673,8 @@ mod tests { #[test] fn test_mock_multiple_record_types() { - use alloc::{string::String, vec}; use patina::component::service::Service; + use std::{string::String, vec}; // Test that mock can handle different record types let type0 = Type0PlatformFirmwareInformation { @@ -724,8 +720,8 @@ mod tests { #[test] fn test_service_mock_pattern() { - use alloc::vec; use patina::component::service::Service; + use std::vec; // Create a mock service using the standard Service::mock pattern let mock = MockSmbios { version: (3, 6), add_from_bytes_result: Ok(0xBEEF), expected_bytes: None }; @@ -746,8 +742,8 @@ mod tests { #[test] fn test_service_mock_with_extension_trait() { - use alloc::vec; use patina::component::service::Service; + use std::vec; // Create test record let record = Type127EndOfTable { header: SmbiosTableHeader::new(127, 4, 0xFFFE), string_pool: vec![] }; diff --git a/components/patina_smbios/src/smbios_record.rs b/components/patina_smbios/src/smbios_record.rs index f7937a446..ce731451c 100644 --- a/components/patina_smbios/src/smbios_record.rs +++ b/components/patina_smbios/src/smbios_record.rs @@ -234,7 +234,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 -extern crate alloc; use crate::{ error::SmbiosError, service::{SMBIOS_HANDLE_PI_RESERVED, SMBIOS_STRING_MAX_LENGTH, SmbiosTableHeader}, @@ -805,7 +804,7 @@ impl Default for Type127EndOfTable { mod tests { use super::*; use crate::{service::SMBIOS_STRING_MAX_LENGTH, smbios_types}; - use alloc::vec; + use std::vec; #[test] fn test_type0_new() { diff --git a/components/patina_smbios/src/smbios_types.rs b/components/patina_smbios/src/smbios_types.rs index 013b1cf8a..804eb9628 100644 --- a/components/patina_smbios/src/smbios_types.rs +++ b/components/patina_smbios/src/smbios_types.rs @@ -14,8 +14,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 -extern crate alloc; - use bitfield_struct::bitfield; use zerocopy::{Immutable, IntoBytes, KnownLayout}; diff --git a/components/patina_test/src/__private_api.rs b/components/patina_test/src/__private_api.rs index b21e472ed..f0e1482f6 100644 --- a/components/patina_test/src/__private_api.rs +++ b/components/patina_test/src/__private_api.rs @@ -170,8 +170,6 @@ where mod tests { use super::*; - extern crate std; - #[test] fn test_should_run() { let test_case = TestCase { @@ -183,10 +181,10 @@ mod tests { func: |_| Ok(true), }; - std::assert!(test_case.should_run(&[Filter::include("test")])); - std::assert!(test_case.should_run(&[Filter::include("t")])); - std::assert!(test_case.should_run(&[])); - std::assert!(!test_case.should_run(&[Filter::include("not")])); + assert!(test_case.should_run(&[Filter::include("test")])); + assert!(test_case.should_run(&[Filter::include("t")])); + assert!(test_case.should_run(&[])); + assert!(!test_case.should_run(&[Filter::include("not")])); } #[test] @@ -200,7 +198,7 @@ mod tests { func: |_| Ok(true), }; - std::assert!(test_case.should_run(&[])); + assert!(test_case.should_run(&[])); } #[test] @@ -215,13 +213,13 @@ mod tests { }; // Exclude filter matches - should not run - std::assert!(!test_case.should_run(&[Filter::exclude("test_case")])); + assert!(!test_case.should_run(&[Filter::exclude("test_case")])); // Exclude filter does not match - should run - std::assert!(test_case.should_run(&[Filter::exclude("other")])); + assert!(test_case.should_run(&[Filter::exclude("other")])); // Include filter matches but exclude filter also matches - should not run - std::assert!(!test_case.should_run(&[Filter::include("my_crate"), Filter::exclude("test_case")])); + assert!(!test_case.should_run(&[Filter::include("my_crate"), Filter::exclude("test_case")])); // Include filter matches and exclude filter does not match - should run - std::assert!(test_case.should_run(&[Filter::include("my_crate"), Filter::exclude("other")])); + assert!(test_case.should_run(&[Filter::include("my_crate"), Filter::exclude("other")])); } #[test] @@ -248,11 +246,11 @@ mod tests { // Test that a passing test passes let result = test_case_pass.run(&mut storage, true); - std::assert_eq!(result, Ok(())); + assert_eq!(result, Ok(())); // Test that a failing test fails let result = test_case_fail.run(&mut storage, true); - std::assert_eq!(result, Err("Failed to install protocol interface")); + assert_eq!(result, Err("Failed to install protocol interface")); } #[test] @@ -278,11 +276,11 @@ mod tests { // Test that a test that passes, should fail because its expected to fail let result = test_case_pass.run(&mut storage, true); - std::assert_eq!(result, Err("Test passed when it should have failed")); + assert_eq!(result, Err("Test passed when it should have failed")); // Test that a test that fails, should pass because its expected to fail let result = test_case_fail.run(&mut storage, true); - std::assert_eq!(result, Ok(())); + assert_eq!(result, Ok(())); } #[test] @@ -300,7 +298,7 @@ mod tests { }; let result = test_case.run(&mut storage, false); - std::assert_eq!(result, Ok(())); + assert_eq!(result, Ok(())); // Test that a test that fails with an unexpected message, should fail let test_case = TestCase { @@ -313,7 +311,7 @@ mod tests { }; let result = test_case.run(&mut storage, false); - std::assert_eq!(result, Err("Failed to install protocol interface")); + assert_eq!(result, Err("Failed to install protocol interface")); } #[test] diff --git a/components/patina_test/src/component.rs b/components/patina_test/src/component.rs index 156a78569..f8f85eb90 100644 --- a/components/patina_test/src/component.rs +++ b/components/patina_test/src/component.rs @@ -143,8 +143,6 @@ impl TestRunner { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] pub(crate) mod tests { - extern crate std; - use super::*; use crate::alloc::{boxed::Box, format}; @@ -354,7 +352,7 @@ pub(crate) mod tests { // This test is filtered out, so it should not even show up in the results. assert!(!output.contains("test_that_fails")); // This test is not filtered out, but never run, so should log as such. - std::println!("{output}"); + println!("{output}"); assert!(output.contains("event_triggered_test ... not triggered")); } } diff --git a/components/patina_test/src/lib.rs b/components/patina_test/src/lib.rs index d17f73770..7bc3542a9 100644 --- a/components/patina_test/src/lib.rs +++ b/components/patina_test/src/lib.rs @@ -3,7 +3,7 @@ "## License\n\n", " Copyright (c) Microsoft Corporation.\n\n", )] -#![no_std] +#![cfg_attr(not(test), no_std)] #![deny(missing_docs)] #![cfg_attr(coverage, feature(coverage_attribute))] extern crate alloc; diff --git a/components/patina_test/src/service.rs b/components/patina_test/src/service.rs index 6644c491a..74bfcfb84 100644 --- a/components/patina_test/src/service.rs +++ b/components/patina_test/src/service.rs @@ -309,12 +309,11 @@ impl Display for Recorder { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; - use core::mem::MaybeUninit; use super::*; - use crate::{alloc::format, component::tests::*}; + use crate::component::tests::*; + use std::format; #[test] fn test_recorder_records_results() { @@ -357,7 +356,7 @@ mod tests { recorder.update_record(test_data); let output = format!("{}", *recorder); - std::println!("{output}"); + println!("{output}"); assert!(output.contains("test ... ok (1 passes)")); } diff --git a/core/patina_debugger/src/lib.rs b/core/patina_debugger/src/lib.rs index 4e68d1012..36cc87ad5 100644 --- a/core/patina_debugger/src/lib.rs +++ b/core/patina_debugger/src/lib.rs @@ -117,7 +117,7 @@ mod memory; mod system; mod transport; -#[cfg(any(feature = "alloc", test))] +#[cfg(feature = "alloc")] extern crate alloc; pub use debugger::PatinaDebugger; diff --git a/core/patina_debugger/src/system/no_alloc.rs b/core/patina_debugger/src/system/no_alloc.rs index 0b6d51adb..96e0dfd36 100644 --- a/core/patina_debugger/src/system/no_alloc.rs +++ b/core/patina_debugger/src/system/no_alloc.rs @@ -65,9 +65,6 @@ impl SystemStateTrait for SystemState { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate alloc; - use alloc::string::String; - use super::*; #[test] diff --git a/core/patina_internal_core/src/collections/bst.rs b/core/patina_internal_core/src/collections/bst.rs index bf4906692..829a70500 100644 --- a/core/patina_internal_core/src/collections/bst.rs +++ b/core/patina_internal_core/src/collections/bst.rs @@ -901,7 +901,6 @@ mod tests { #[cfg(test)] #[allow(clippy::undocumented_unsafe_blocks)] mod fuzz_tests { - extern crate std; use crate::collections::{Bst, node_size}; use rand::{ RngExt, diff --git a/core/patina_internal_core/src/collections/rbt.rs b/core/patina_internal_core/src/collections/rbt.rs index 6738c41ec..612ec43be 100644 --- a/core/patina_internal_core/src/collections/rbt.rs +++ b/core/patina_internal_core/src/collections/rbt.rs @@ -919,8 +919,6 @@ where #[cfg_attr(coverage, coverage(off))] #[allow(clippy::undocumented_unsafe_blocks)] mod tests { - extern crate std; - use super::*; use crate::collections::node_size; @@ -1844,7 +1842,6 @@ mod tests { #[cfg(test)] #[allow(clippy::undocumented_unsafe_blocks)] mod fuzz_tests { - extern crate std; use crate::collections::{Rbt, node_size}; use rand::{ RngExt, diff --git a/core/patina_internal_core/src/collections/sorted_slice.rs b/core/patina_internal_core/src/collections/sorted_slice.rs index 3bc028072..52be99c68 100644 --- a/core/patina_internal_core/src/collections/sorted_slice.rs +++ b/core/patina_internal_core/src/collections/sorted_slice.rs @@ -209,10 +209,8 @@ where #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; use super::*; - extern crate alloc; - use alloc::vec::Vec; + use std::vec::Vec; #[test] fn test_init_state_of_new_sorted_slice() { diff --git a/core/patina_internal_core/src/depex.rs b/core/patina_internal_core/src/depex.rs index bd3280d39..686229f48 100644 --- a/core/patina_internal_core/src/depex.rs +++ b/core/patina_internal_core/src/depex.rs @@ -384,11 +384,10 @@ impl Iterator for DepexParser { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; - use alloc::vec; use core::str::FromStr; use patina::standard::efi; use std::println; + use std::vec; use uuid::Uuid; use super::*; diff --git a/core/patina_internal_core/src/lib.rs b/core/patina_internal_core/src/lib.rs index a24228f1f..893cab645 100644 --- a/core/patina_internal_core/src/lib.rs +++ b/core/patina_internal_core/src/lib.rs @@ -11,7 +11,7 @@ //! //! SPDX-License-Identifier: Apache-2.0 //! -#![no_std] +#![cfg_attr(not(test), no_std)] #![cfg_attr(coverage, feature(coverage_attribute))] extern crate alloc; diff --git a/core/patina_internal_cpu/Cargo.toml b/core/patina_internal_cpu/Cargo.toml index 882bcb46b..565ffcff5 100644 --- a/core/patina_internal_cpu/Cargo.toml +++ b/core/patina_internal_cpu/Cargo.toml @@ -17,7 +17,7 @@ features = ["std"] [dependencies] log = { workspace = true } -patina = { workspace = true, features = ["alloc", "core"] } +patina = { workspace = true, features = ["core"] } spin = { workspace = true, features = ["rwlock"] } patina_paging = { workspace = true } cfg-if = { workspace = true } diff --git a/core/patina_internal_cpu/src/interrupts/exception_handling.rs b/core/patina_internal_cpu/src/interrupts/exception_handling.rs index ed5f8b676..1b6d6eddc 100644 --- a/core/patina_internal_cpu/src/interrupts/exception_handling.rs +++ b/core/patina_internal_cpu/src/interrupts/exception_handling.rs @@ -119,8 +119,6 @@ extern "efiapi" fn exception_handler(exception_type: usize, context: &mut Except #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; - use patina::pi::protocol::cpu_arch::EfiSystemContext; use super::*; diff --git a/core/patina_internal_cpu/src/interrupts/x64/interrupt_manager.rs b/core/patina_internal_cpu/src/interrupts/x64/interrupt_manager.rs index 307432e4a..6d50a0bfa 100644 --- a/core/patina_internal_cpu/src/interrupts/x64/interrupt_manager.rs +++ b/core/patina_internal_cpu/src/interrupts/x64/interrupt_manager.rs @@ -241,8 +241,6 @@ fn dump_pte(cr2: u64) { #[cfg_attr(coverage, coverage(off))] #[cfg(test)] mod test { - extern crate std; - use serial_test::serial; use super::*; diff --git a/core/patina_internal_cpu/src/paging/null.rs b/core/patina_internal_cpu/src/paging/null.rs index a5be2cb72..78c406401 100644 --- a/core/patina_internal_cpu/src/paging/null.rs +++ b/core/patina_internal_cpu/src/paging/null.rs @@ -8,7 +8,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 //! -use alloc::boxed::Box; use patina_paging::{CacheAttributeValue, MemoryAttributes, PtError}; use crate::paging::PatinaPageTable; diff --git a/patina_dxe_core/src/allocator.rs b/patina_dxe_core/src/allocator.rs index cda543f50..ca62b1c96 100644 --- a/patina_dxe_core/src/allocator.rs +++ b/patina_dxe_core/src/allocator.rs @@ -22,7 +22,6 @@ use core::{ slice::{self, from_raw_parts_mut}, }; -extern crate alloc; use alloc::{boxed::Box, collections::BTreeMap, vec::Vec}; use patina::function; diff --git a/patina_dxe_core/src/allocator/fixed_size_block_allocator.rs b/patina_dxe_core/src/allocator/fixed_size_block_allocator.rs index 7a906521e..03a1feb9b 100644 --- a/patina_dxe_core/src/allocator/fixed_size_block_allocator.rs +++ b/patina_dxe_core/src/allocator/fixed_size_block_allocator.rs @@ -10,7 +10,6 @@ //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; use super::{AllocationStatistics, AllocationStrategy, DEFAULT_ALLOCATION_STRATEGY, PageAllocator}; use crate::{gcd::SpinLockedGcd, tpl_mutex}; @@ -843,16 +842,15 @@ impl PageAllocator for SpinLockedFixedSizeBlockAllocator { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; use crate::{ allocator::{ DEFAULT_ALLOCATION_STRATEGY, DEFAULT_PAGE_ALLOCATION_GRANULARITY, HIGH_TRAFFIC_ALLOC_MIN_EXPANSION, }, gcd, test_support, }; - use alloc::vec::Vec; use core::{alloc::GlobalAlloc, ffi::c_void, panic}; use std::alloc::System; + use std::vec::Vec; use patina::{ uefi_pages_to_size, {SIZE_64KB, UEFI_PAGE_SHIFT, UEFI_PAGE_SIZE}, diff --git a/patina_dxe_core/src/allocator/uefi_allocator.rs b/patina_dxe_core/src/allocator/uefi_allocator.rs index ab0f7a795..4c5a2f1e9 100644 --- a/patina_dxe_core/src/allocator/uefi_allocator.rs +++ b/patina_dxe_core/src/allocator/uefi_allocator.rs @@ -272,7 +272,6 @@ where #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; use core::cmp::max; use std::alloc::{GlobalAlloc, System}; diff --git a/patina_dxe_core/src/allocator/usage_tests/uefi_memory_map.rs b/patina_dxe_core/src/allocator/usage_tests/uefi_memory_map.rs index 1d8c1a989..7bd66d5e8 100644 --- a/patina_dxe_core/src/allocator/usage_tests/uefi_memory_map.rs +++ b/patina_dxe_core/src/allocator/usage_tests/uefi_memory_map.rs @@ -145,7 +145,6 @@ mod tests { allocator::{get_memory_map, init_memory_support, reset_allocators}, test_support, }; - use alloc::vec::Vec; use patina::standard::efi; use patina::{ BinaryGuid, @@ -158,6 +157,7 @@ mod tests { }; use serial_test::serial; use std::panic::RefUnwindSafe; + use std::vec::Vec; const ZERO: BinaryGuid = BinaryGuid::ZERO; diff --git a/patina_dxe_core/src/component_dispatcher.rs b/patina_dxe_core/src/component_dispatcher.rs index d7e922b81..16e7924e5 100644 --- a/patina_dxe_core/src/component_dispatcher.rs +++ b/patina_dxe_core/src/component_dispatcher.rs @@ -8,8 +8,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; - use crate::tpl_mutex::TplMutex; use patina::standard::efi; use patina::{ diff --git a/patina_dxe_core/src/config_tables/memory_attributes_table.rs b/patina_dxe_core/src/config_tables/memory_attributes_table.rs index d8ac9d475..e872706cf 100644 --- a/patina_dxe_core/src/config_tables/memory_attributes_table.rs +++ b/patina_dxe_core/src/config_tables/memory_attributes_table.rs @@ -6,7 +6,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; use alloc::vec::Vec; #[cfg(not(test))] @@ -251,7 +250,6 @@ pub fn core_install_memory_attributes_table() { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; use super::*; use crate::{ diff --git a/patina_dxe_core/src/decompress.rs b/patina_dxe_core/src/decompress.rs index be69cdc1a..20e45d02c 100644 --- a/patina_dxe_core/src/decompress.rs +++ b/patina_dxe_core/src/decompress.rs @@ -6,8 +6,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; - use core::ffi::c_void; use alloc::boxed::Box; diff --git a/patina_dxe_core/src/event_db.rs b/patina_dxe_core/src/event_db.rs index 51ea65a3c..b1051edf8 100644 --- a/patina_dxe_core/src/event_db.rs +++ b/patina_dxe_core/src/event_db.rs @@ -10,8 +10,6 @@ //! #![warn(missing_docs)] -extern crate alloc; - use alloc::{ collections::{BTreeMap, BTreeSet}, vec::Vec, @@ -843,12 +841,11 @@ unsafe impl Sync for SpinLockedEventDb {} #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; use core::{iter, str::FromStr}; - use alloc::{vec, vec::Vec}; use patina::Guid; use patina::standard::efi; + use std::{vec, vec::Vec}; use uuid::Uuid; use crate::test_support; diff --git a/patina_dxe_core/src/gcd/spin_locked_gcd.rs b/patina_dxe_core/src/gcd/spin_locked_gcd.rs index e88f5c7a8..1f87bea5a 100644 --- a/patina_dxe_core/src/gcd/spin_locked_gcd.rs +++ b/patina_dxe_core/src/gcd/spin_locked_gcd.rs @@ -3074,9 +3074,9 @@ mod tests { use crate::test_support::{self, MockPageTable, MockPageTableWrapper}; use super::*; - use alloc::vec::Vec; use patina::pi::dxe_services::GcdMemoryType; use patina::standard::efi; + use std::vec::Vec; use std::{alloc::GlobalAlloc, cell::RefCell, rc::Rc}; const DXE_CORE_PE_HEADER_DATA: [u8; 1057] = [ diff --git a/patina_dxe_core/src/pecoff.rs b/patina_dxe_core/src/pecoff.rs index 5a39b77d9..5aece3506 100644 --- a/patina_dxe_core/src/pecoff.rs +++ b/patina_dxe_core/src/pecoff.rs @@ -6,8 +6,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; - use alloc::{ format, string::{String, ToString}, @@ -556,7 +554,6 @@ mod tests { use crate::test_support; use super::*; - extern crate std; use std::vec; diff --git a/patina_dxe_core/src/pecoff/error.rs b/patina_dxe_core/src/pecoff/error.rs index fae1be965..93900a9d0 100644 --- a/patina_dxe_core/src/pecoff/error.rs +++ b/patina_dxe_core/src/pecoff/error.rs @@ -46,12 +46,9 @@ impl From for Error { mod tests { use super::*; - extern crate alloc; extern crate scroll; - extern crate std; - - use alloc::string::ToString; use std::format; + use std::string::ToString; #[test] fn test_convert_error() { diff --git a/patina_dxe_core/src/performance.rs b/patina_dxe_core/src/performance.rs index 9dab45c00..7370e3fac 100644 --- a/patina_dxe_core/src/performance.rs +++ b/patina_dxe_core/src/performance.rs @@ -809,7 +809,7 @@ mod tests { guid: efi::Guid, } - let node = alloc::boxed::Box::new(FwFilePathNode { + let node = std::boxed::Box::new(FwFilePathNode { header: efi::protocols::device_path::Protocol { r#type: TYPE_MEDIA, sub_type: Media::SUBTYPE_PIWG_FIRMWARE_FILE, @@ -817,9 +817,9 @@ mod tests { }, guid: file_guid, }); - let node_ptr = alloc::boxed::Box::into_raw(node) as *mut efi::protocols::device_path::Protocol; + let node_ptr = std::boxed::Box::into_raw(node) as *mut efi::protocols::device_path::Protocol; - let loaded_image = alloc::boxed::Box::new(efi::protocols::loaded_image::Protocol { + let loaded_image = std::boxed::Box::new(efi::protocols::loaded_image::Protocol { revision: efi::protocols::loaded_image::REVISION, parent_handle: ptr::null_mut(), system_table: ptr::null_mut(), @@ -834,7 +834,7 @@ mod tests { image_data_type: efi::BOOT_SERVICES_DATA, unload: None, }); - let loaded_image_ptr = alloc::boxed::Box::into_raw(loaded_image) as *mut core::ffi::c_void; + let loaded_image_ptr = std::boxed::Box::into_raw(loaded_image) as *mut core::ffi::c_void; let (handle, _) = PROTOCOL_DB .install_protocol_interface(None, efi::protocols::loaded_image::PROTOCOL_GUID, loaded_image_ptr) @@ -934,7 +934,7 @@ mod tests { // published_table_size reports a non-zero size, and publish_table writes into a large-enough buffer. let size = perf.published_table_size().unwrap(); assert!(size > 0); - let buffer: &'static mut [u8] = alloc::boxed::Box::leak(alloc::vec![0u8; size].into_boxed_slice()); + let buffer: &'static mut [u8] = std::boxed::Box::leak(std::vec![0u8; size].into_boxed_slice()); perf.publish_table(buffer).unwrap(); }) .unwrap(); @@ -948,7 +948,7 @@ mod tests { assert_eq!(perf.published_table_size().unwrap_err(), Error::Efi(EfiError::AccessDenied)); - let buffer: &'static mut [u8] = alloc::boxed::Box::leak(alloc::vec![0u8; 64].into_boxed_slice()); + let buffer: &'static mut [u8] = std::boxed::Box::leak(std::vec![0u8; 64].into_boxed_slice()); assert_eq!(perf.publish_table(buffer).unwrap_err(), Error::Efi(EfiError::AccessDenied)); // A re-entrant record add cannot acquire the held table lock and drops the record. @@ -1041,7 +1041,7 @@ mod tests { let image_handle = install_loaded_image_with_fw_path(node_length, file_guid); // A separate handle carries only a driver-binding protocol referencing the image handle above. - let driver_binding = alloc::boxed::Box::new(efi::protocols::driver_binding::Protocol { + let driver_binding = std::boxed::Box::new(efi::protocols::driver_binding::Protocol { supported: stub_supported, start: stub_start, stop: stub_stop, @@ -1049,7 +1049,7 @@ mod tests { image_handle, driver_binding_handle: ptr::null_mut(), }); - let driver_binding_ptr = alloc::boxed::Box::into_raw(driver_binding) as *mut core::ffi::c_void; + let driver_binding_ptr = std::boxed::Box::into_raw(driver_binding) as *mut core::ffi::c_void; let (db_handle, _) = PROTOCOL_DB .install_protocol_interface(None, efi::protocols::driver_binding::PROTOCOL_GUID, driver_binding_ptr) .unwrap(); diff --git a/patina_dxe_core/src/performance/table.rs b/patina_dxe_core/src/performance/table.rs index 881573f43..a5299a3a8 100644 --- a/patina_dxe_core/src/performance/table.rs +++ b/patina_dxe_core/src/performance/table.rs @@ -224,7 +224,7 @@ mod tests { #[test] fn test_serialize_into() { - let buffer: &'static mut [u8] = alloc::boxed::Box::leak(alloc::vec![0u8; 1000].into_boxed_slice()); + let buffer: &'static mut [u8] = std::boxed::Box::leak(std::vec![0u8; 1000].into_boxed_slice()); let address = buffer.as_ptr() as usize; let mut fbpt = Fbpt::new(); @@ -275,7 +275,7 @@ mod tests { #[test] fn test_performance_table_well_written_in_memory() { - let buffer: &'static mut [u8] = alloc::boxed::Box::leak(alloc::vec![0u8; 1000].into_boxed_slice()); + let buffer: &'static mut [u8] = std::boxed::Box::leak(std::vec![0u8; 1000].into_boxed_slice()); let address = buffer.as_ptr() as usize; let mut fbpt = Fbpt::new(); diff --git a/patina_dxe_core/src/pi_dispatcher/debug_image_info_table.rs b/patina_dxe_core/src/pi_dispatcher/debug_image_info_table.rs index 84a56de02..3ab904de4 100644 --- a/patina_dxe_core/src/pi_dispatcher/debug_image_info_table.rs +++ b/patina_dxe_core/src/pi_dispatcher/debug_image_info_table.rs @@ -535,7 +535,7 @@ mod tests { fn test_grow_error_display_alloc_failed_msg() { with_locked_state(|| { let error = GrowError::AllocFailed; - let msg = alloc::format!("{error}"); + let msg = std::format!("{error}"); assert_eq!(msg, "allocation returned null"); }); } @@ -546,7 +546,7 @@ mod tests { // Note: Zero alignment will result in a LayoutError. let layout_err = Layout::from_size_align(1, 0).unwrap_err(); let error = GrowError::InvalidLayout(layout_err); - let msg = alloc::format!("{error}"); + let msg = std::format!("{error}"); assert!(msg.starts_with("invalid layout:")); }); } @@ -555,12 +555,12 @@ mod tests { fn test_grow_error_debug_msgs() { with_locked_state(|| { let error = GrowError::AllocFailed; - let msg = alloc::format!("{error:?}"); + let msg = std::format!("{error:?}"); assert_eq!(msg, "AllocFailed"); let layout_err = Layout::from_size_align(1, 0).unwrap_err(); let error = GrowError::from(layout_err); - let msg = alloc::format!("{error:?}"); + let msg = std::format!("{error:?}"); assert!(msg.starts_with("InvalidLayout(")); }); } diff --git a/patina_dxe_core/src/pi_dispatcher/fv.rs b/patina_dxe_core/src/pi_dispatcher/fv.rs index 30ded2756..cd87bd279 100644 --- a/patina_dxe_core/src/pi_dispatcher/fv.rs +++ b/patina_dxe_core/src/pi_dispatcher/fv.rs @@ -899,14 +899,13 @@ pub fn device_path_bytes_for_fv_file(fv_handle: efi::Handle, file_name: efi::Gui #[cfg_attr(coverage, coverage(off))] mod tests { use super::*; + use crate::test_collateral; use crate::{MockComponentInfo, MockCpuInfo, MockMemoryInfo, test_support}; use patina::pi::{ BootMode, hob::{self, Hob, HobList}, }; use patina_ffs_extractors::CompositeSectionExtractor; - extern crate alloc; - use crate::test_collateral; use std::{ alloc::{Layout, alloc, dealloc}, ffi::c_void, diff --git a/patina_dxe_core/src/pi_dispatcher/image.rs b/patina_dxe_core/src/pi_dispatcher/image.rs index 32702332d..b562b7037 100644 --- a/patina_dxe_core/src/pi_dispatcher/image.rs +++ b/patina_dxe_core/src/pi_dispatcher/image.rs @@ -1592,7 +1592,6 @@ impl Buffer { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; use super::*; use crate::{ Core, MockPlatformInfo, @@ -1615,6 +1614,7 @@ mod tests { hob::{HobList, MemoryAllocationHeader, MemoryAllocationModule}, }, }; + use std::alloc::{Layout, alloc}; use std::{fs::File, io::Read, ptr::NonNull, slice::from_raw_parts}; #[cfg(target_arch = "aarch64")] @@ -2667,8 +2667,7 @@ mod tests { // Manually construct PrivateImageData with minimal required fields const LEN: usize = 0x2000; // SAFETY: Allocate a page-aligned test buffer and treat it as a raw image backing store. - let fake_buffer = - unsafe { alloc::alloc::alloc(alloc::alloc::Layout::from_size_align(LEN, 0x1000).unwrap()) }; + let fake_buffer = unsafe { alloc(Layout::from_size_align(LEN, 0x1000).unwrap()) }; // SAFETY: fake_buffer points to LEN bytes we just allocated and is valid for mutable slice creation. let slice = unsafe { core::slice::from_raw_parts_mut(fake_buffer, LEN) }; diff --git a/patina_dxe_core/src/pi_dispatcher/section_decompress.rs b/patina_dxe_core/src/pi_dispatcher/section_decompress.rs index 5b19b6203..cb2335c54 100644 --- a/patina_dxe_core/src/pi_dispatcher/section_decompress.rs +++ b/patina_dxe_core/src/pi_dispatcher/section_decompress.rs @@ -1,7 +1,5 @@ //! A section extractor that provides UEFI decompression functionality with an additional custom extractor //! implementation. -extern crate alloc; - use alloc::vec; use patina::{ pi::fw_fs::{self, ffs}, diff --git a/patina_dxe_core/src/protocol_db.rs b/patina_dxe_core/src/protocol_db.rs index f6df2d2a9..353b50853 100644 --- a/patina_dxe_core/src/protocol_db.rs +++ b/patina_dxe_core/src/protocol_db.rs @@ -8,8 +8,6 @@ //! //! SPDX-License-Identifier: Apache-2.0 //! -extern crate alloc; - use alloc::{ collections::{BTreeMap, BTreeSet}, vec, @@ -880,7 +878,6 @@ unsafe impl Sync for SpinLockedProtocolDb {} #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; use core::str::FromStr; use std::println; diff --git a/patina_dxe_core/src/runtime.rs b/patina_dxe_core/src/runtime.rs index 19653b937..9a1b5c024 100644 --- a/patina_dxe_core/src/runtime.rs +++ b/patina_dxe_core/src/runtime.rs @@ -239,10 +239,7 @@ mod tests { with_locked_state(|| { let block = RelocationBlock { block_header: crate::pecoff::relocation::BaseRelocationBlockHeader { page_rva: 0, block_size: 0 }, - relocations: alloc::vec![crate::pecoff::relocation::Relocation { - type_and_offset: 0x1 << 12, - value: 0 - }], + relocations: std::vec![crate::pecoff::relocation::Relocation { type_and_offset: 0x1 << 12, value: 0 }], }; let result = add_runtime_image(ptr::null_mut(), 0, &[block], 0x1 as efi::Handle); assert!(matches!(result, Err(EfiError::Unsupported)), "unexpected result: {result:?}"); diff --git a/sdk/patina/src/base/c_ptr.rs b/sdk/patina/src/base/c_ptr.rs index 2aff2eba4..684969b3d 100644 --- a/sdk/patina/src/base/c_ptr.rs +++ b/sdk/patina/src/base/c_ptr.rs @@ -6,7 +6,7 @@ //! //! SPDX-License-Identifier: Apache-2.0 //! -#[cfg(any(test, feature = "alloc"))] +#[cfg(feature = "alloc")] use alloc::boxed::Box; use core::{ ffi::c_void, diff --git a/sdk/patina/src/base/error.rs b/sdk/patina/src/base/error.rs index dedb15029..98cebb08d 100644 --- a/sdk/patina/src/base/error.rs +++ b/sdk/patina/src/base/error.rs @@ -195,8 +195,6 @@ impl core::error::Error for EfiError {} #[cfg(test)] mod tests { use super::*; - extern crate alloc; - use alloc::format; #[test] fn test_display_known_variant_matches_status() { diff --git a/sdk/patina/src/base/string.rs b/sdk/patina/src/base/string.rs index 75ae5a9fb..f001d71f8 100644 --- a/sdk/patina/src/base/string.rs +++ b/sdk/patina/src/base/string.rs @@ -246,7 +246,7 @@ macro_rules! char8 { #[cfg_attr(coverage, coverage(off))] mod tests { use super::*; - use alloc::string::ToString; + use std::string::ToString; #[test] fn test_string_error_display() { diff --git a/sdk/patina/src/base/string/char16.rs b/sdk/patina/src/base/string/char16.rs index d004304a2..531fae8f0 100644 --- a/sdk/patina/src/base/string/char16.rs +++ b/sdk/patina/src/base/string/char16.rs @@ -13,7 +13,7 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::char8::Char8Array; -#[cfg(any(test, feature = "alloc"))] +#[cfg(feature = "alloc")] use alloc::{string::String, vec::Vec}; #[cfg(any(test, feature = "alloc"))] @@ -760,7 +760,7 @@ impl From> for String { mod tests { use super::*; use crate::char16; - use alloc::string::ToString; + use std::string::ToString; #[test] fn test_char16_from_units_with_nul_valid() { @@ -803,9 +803,9 @@ mod tests { fn test_char16_chars_and_iter() { let units = [0x0041u16, 0x00E9, 0x20AC, 0x0000]; // "Aé€" let s = Char16Str::from_units_with_nul(&units).unwrap(); - let chars: alloc::vec::Vec = s.chars().collect(); + let chars: std::vec::Vec = s.chars().collect(); assert_eq!(chars, ['A', 'é', '€']); - let code_units: alloc::vec::Vec = s.iter().copied().collect(); + let code_units: std::vec::Vec = s.iter().copied().collect(); assert_eq!(code_units, [0x0041, 0x00E9, 0x20AC]); } @@ -816,7 +816,7 @@ mod tests { let units = [0x0041u16, 0xD800, 0x0000]; // SAFETY: This deliberately bypasses validation to exercise the lossy fallback path. let s = unsafe { Char16Str::from_units_with_nul_unchecked(&units) }; - let chars: alloc::vec::Vec = s.chars().collect(); + let chars: std::vec::Vec = s.chars().collect(); assert_eq!(chars, ['A', char::REPLACEMENT_CHARACTER]); } @@ -856,7 +856,7 @@ mod tests { let units = [0x0045u16, 0x0046, 0x0049, 0x0000]; let s = Char16Str::from_units_with_nul(&units).unwrap(); assert_eq!(s.to_string(), "EFI"); - assert_eq!(alloc::format!("{s:?}"), "\"EFI\""); + assert_eq!(std::format!("{s:?}"), "\"EFI\""); } #[test] @@ -926,7 +926,7 @@ mod tests { let s = Char16String::from_le_bytes_until_nul(&bytes).unwrap(); assert_eq!(s.to_string(), "EFI"); // The owned buffer is trimmed to exactly "EFI\0". - assert_eq!(s.into_units_with_nul(), alloc::vec![0x0045, 0x0046, 0x0049, 0x0000]); + assert_eq!(s.into_units_with_nul(), std::vec![0x0045, 0x0046, 0x0049, 0x0000]); } #[test] @@ -971,12 +971,12 @@ mod tests { let b = Char16String::default(); assert!(a.is_empty()); assert_eq!(a, b); - assert_eq!(a.clone().into_units_with_nul(), alloc::vec![0]); + assert_eq!(a.clone().into_units_with_nul(), std::vec![0]); } #[test] fn test_char16string_to_owned_roundtrip() { - use alloc::borrow::ToOwned; + use std::borrow::ToOwned; let owned = Char16String::try_from_str("Test").unwrap(); let borrowed: &Char16Str = &owned; let reowned = borrowed.to_owned(); @@ -1025,7 +1025,7 @@ mod tests { fn test_char16string_debug_borrow_and_display() { use core::borrow::Borrow; let s = Char16String::try_from_str("EFI").unwrap(); - assert_eq!(alloc::format!("{s:?}"), "\"EFI\""); + assert_eq!(std::format!("{s:?}"), "\"EFI\""); assert_eq!(s.to_string(), "EFI"); let borrowed: &Char16Str = s.borrow(); assert_eq!(borrowed.len(), 3); @@ -1071,7 +1071,7 @@ mod tests { #[test] fn test_char16string_from_units_with_nul() { - let units = alloc::vec![0x0045u16, 0x0046, 0x0049, 0x0000]; + let units = std::vec![0x0045u16, 0x0046, 0x0049, 0x0000]; let s = Char16String::from_units_with_nul(units).unwrap(); assert_eq!(s.len(), 3); assert!(*s == *"EFI"); @@ -1079,25 +1079,25 @@ mod tests { #[test] fn test_char16string_from_units_with_nul_missing_terminator() { - let units = alloc::vec![0x0045u16, 0x0046]; + let units = std::vec![0x0045u16, 0x0046]; assert_eq!(Char16String::from_units_with_nul(units), Err(StringError::MissingNulTerminator)); } #[test] fn test_char16string_from_units_with_nul_interior_nul() { - let units = alloc::vec![0x0045u16, 0x0000, 0x0049, 0x0000]; + let units = std::vec![0x0045u16, 0x0000, 0x0049, 0x0000]; assert_eq!(Char16String::from_units_with_nul(units), Err(StringError::InteriorNul { position: 1 })); } #[test] fn test_char16string_from_units_with_nul_surrogate_rejected() { - let units = alloc::vec![0x0045u16, 0xD800, 0x0000]; + let units = std::vec![0x0045u16, 0xD800, 0x0000]; assert_eq!(Char16String::from_units_with_nul(units), Err(StringError::NotUcs2 { position: 1, value: 0xD800 })); } #[test] fn test_char16string_from_units_with_nul_unchecked() { - let units = alloc::vec![0x0045u16, 0x0046, 0x0049, 0x0000]; + let units = std::vec![0x0045u16, 0x0046, 0x0049, 0x0000]; // SAFETY: `units` is a valid NUL-terminated UCS-2 sequence. let s = unsafe { Char16String::from_units_with_nul_unchecked(units) }; assert!(*s == *"EFI"); @@ -1211,7 +1211,7 @@ mod tests { #[test] fn test_char16_array_to_string() { let array = Char16Array::<9>::from_str("Firmware"); - let owned: alloc::string::String = array.into(); + let owned: std::string::String = array.into(); assert_eq!(owned, "Firmware"); } diff --git a/sdk/patina/src/base/string/char8.rs b/sdk/patina/src/base/string/char8.rs index c63d34e76..70640dcc6 100644 --- a/sdk/patina/src/base/string/char8.rs +++ b/sdk/patina/src/base/string/char8.rs @@ -13,7 +13,7 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::char16::Char16Array; -#[cfg(any(test, feature = "alloc"))] +#[cfg(feature = "alloc")] use alloc::{string::String, vec::Vec}; #[cfg(any(test, feature = "alloc"))] @@ -746,7 +746,7 @@ mod tests { fn test_char8_high_latin1_bytes_valid() { let bytes = [0xE9u8, 0xFF, 0x00]; // "éÿ" let s = Char8Str::from_bytes_with_nul(&bytes).unwrap(); - let chars: alloc::vec::Vec = s.chars().collect(); + let chars: std::vec::Vec = s.chars().collect(); assert_eq!(chars, ['\u{00E9}', '\u{00FF}']); } @@ -754,7 +754,7 @@ mod tests { fn test_char8_iter() { let bytes = *b"EFI\0"; let s = Char8Str::from_bytes_with_nul(&bytes).unwrap(); - let collected: alloc::vec::Vec = s.iter().copied().collect(); + let collected: std::vec::Vec = s.iter().copied().collect(); assert_eq!(collected, b"EFI"); } @@ -787,7 +787,7 @@ mod tests { let bytes = *b"EFI\0"; let s = Char8Str::from_bytes_with_nul(&bytes).unwrap(); assert_eq!(s.to_string(), "EFI"); - assert_eq!(alloc::format!("{s:?}"), "\"EFI\""); + assert_eq!(std::format!("{s:?}"), "\"EFI\""); } #[test] @@ -850,12 +850,12 @@ mod tests { let b = Char8String::default(); assert!(a.is_empty()); assert_eq!(a, b); - assert_eq!(a.clone().into_bytes_with_nul(), alloc::vec![0]); + assert_eq!(a.clone().into_bytes_with_nul(), std::vec![0]); } #[test] fn test_char8string_to_owned_roundtrip() { - use alloc::borrow::ToOwned; + use std::borrow::ToOwned; let owned = Char8String::try_from_str("Test").unwrap(); let borrowed: &Char8Str = &owned; let reowned = borrowed.to_owned(); @@ -894,7 +894,7 @@ mod tests { fn test_char8string_debug_borrow_and_display() { use core::borrow::Borrow; let s = Char8String::try_from_str("EFI").unwrap(); - assert_eq!(alloc::format!("{s:?}"), "\"EFI\""); + assert_eq!(std::format!("{s:?}"), "\"EFI\""); assert_eq!(s.to_string(), "EFI"); let borrowed: &Char8Str = s.borrow(); assert_eq!(borrowed.len(), 3); @@ -933,7 +933,7 @@ mod tests { #[test] fn test_char8string_from_bytes_with_nul() { - let bytes = alloc::vec![b'E', b'F', b'I', 0]; + let bytes = std::vec![b'E', b'F', b'I', 0]; let s = Char8String::from_bytes_with_nul(bytes).unwrap(); assert_eq!(s.len(), 3); assert!(*s == *"EFI"); @@ -941,19 +941,19 @@ mod tests { #[test] fn test_char8string_from_bytes_with_nul_missing_terminator() { - let bytes = alloc::vec![b'E', b'F', b'I']; + let bytes = std::vec![b'E', b'F', b'I']; assert_eq!(Char8String::from_bytes_with_nul(bytes), Err(StringError::MissingNulTerminator)); } #[test] fn test_char8string_from_bytes_with_nul_interior_nul() { - let bytes = alloc::vec![b'E', 0, b'I', 0]; + let bytes = std::vec![b'E', 0, b'I', 0]; assert_eq!(Char8String::from_bytes_with_nul(bytes), Err(StringError::InteriorNul { position: 1 })); } #[test] fn test_char8string_from_bytes_with_nul_unchecked() { - let bytes = alloc::vec![b'E', b'F', b'I', 0]; + let bytes = std::vec![b'E', b'F', b'I', 0]; // SAFETY: `bytes` is a valid NUL-terminated Latin-1 sequence. let s = unsafe { Char8String::from_bytes_with_nul_unchecked(bytes) }; assert!(*s == *"EFI"); @@ -1055,7 +1055,7 @@ mod tests { #[test] fn test_char8_array_to_string() { let array = Char8Array::<9>::from_str("Firmware"); - let owned: alloc::string::String = array.into(); + let owned: std::string::String = array.into(); assert_eq!(owned, "Firmware"); } diff --git a/sdk/patina/src/component.rs b/sdk/patina/src/component.rs index 544467184..99c0dcadd 100644 --- a/sdk/patina/src/component.rs +++ b/sdk/patina/src/component.rs @@ -214,8 +214,6 @@ pub mod prelude { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - extern crate std; - use super::*; use crate as patina; use crate::{ diff --git a/sdk/patina/src/component/metadata.rs b/sdk/patina/src/component/metadata.rs index 0898c729f..13563d278 100644 --- a/sdk/patina/src/component/metadata.rs +++ b/sdk/patina/src/component/metadata.rs @@ -182,7 +182,6 @@ impl fmt::Debug for PrettyFixedBitSet<'_> { #[cfg_attr(coverage, coverage(off))] mod tests { use super::*; - extern crate std; #[test] fn test_debug_view_calculates_config_reads_correctly() { diff --git a/sdk/patina/src/component/service/memory.rs b/sdk/patina/src/component/service/memory.rs index 7a8df54a6..8eec7810a 100644 --- a/sdk/patina/src/component/service/memory.rs +++ b/sdk/patina/src/component/service/memory.rs @@ -48,7 +48,7 @@ use crate::{ #[cfg(any(test, feature = "alloc"))] use core::alloc::Allocator; -#[cfg(any(test, feature = "alloc"))] +#[cfg(feature = "alloc")] use alloc::boxed::Box; #[cfg(any(test, feature = "mockall"))] @@ -839,7 +839,6 @@ pub use mock::StdMemoryManager; #[cfg(any(test, feature = "mockall"))] #[cfg_attr(coverage, coverage(off))] mod mock { - extern crate std; use std::{ alloc::{Layout, alloc, dealloc}, collections::HashMap, diff --git a/sdk/patina/src/component/service/performance.rs b/sdk/patina/src/component/service/performance.rs index d607ac841..9a2a1a9d8 100644 --- a/sdk/patina/src/component/service/performance.rs +++ b/sdk/patina/src/component/service/performance.rs @@ -191,9 +191,9 @@ pub trait PerformanceManager: Send + Sync { #[cfg_attr(coverage, coverage(off))] mod tests { use super::*; - use alloc::string::String; - use alloc::vec::Vec; + use std::string::String; use std::sync::Mutex; + use std::vec::Vec; struct Recorded { caller_guid: Option, diff --git a/sdk/patina/src/component/struct_component.rs b/sdk/patina/src/component/struct_component.rs index ebe3ca9f8..9a80ec893 100644 --- a/sdk/patina/src/component/struct_component.rs +++ b/sdk/patina/src/component/struct_component.rs @@ -122,7 +122,7 @@ mod tests { params::{Config, ConfigMut}, }; - use alloc::borrow::Cow; + use std::borrow::Cow; #[allow(dead_code)] pub struct TestStructSuccess { diff --git a/sdk/patina/src/debug/log.rs b/sdk/patina/src/debug/log.rs index ad47da876..a9944aaab 100644 --- a/sdk/patina/src/debug/log.rs +++ b/sdk/patina/src/debug/log.rs @@ -103,7 +103,7 @@ impl Format { #[cfg(test)] mod tests { use super::Format; - use alloc::string::String; + use std::string::String; /// Writes a log record through the given Format into a String buffer and returns it. fn format_record(format: &Format, level: log::Level, target: &str, message: &str) -> String { diff --git a/sdk/patina/src/debug/log/serial_logger.rs b/sdk/patina/src/debug/log/serial_logger.rs index 77c57d07d..95bcc2722 100644 --- a/sdk/patina/src/debug/log/serial_logger.rs +++ b/sdk/patina/src/debug/log/serial_logger.rs @@ -125,10 +125,10 @@ mod tests { use super::*; use crate::debug::log::Format; use crate::peripheral::serial::MockSerialIO; - use alloc::{string::String, sync::Arc, vec::Vec}; use log::{Level, LevelFilter, Log, Metadata}; use spin::Mutex; use std::thread; + use std::{string::String, sync::Arc, vec::Vec}; fn metadata(level: Level, target: &str) -> Metadata<'_> { Metadata::builder().level(level).target(target).build() diff --git a/sdk/patina/src/lib.rs b/sdk/patina/src/lib.rs index 9735bad6c..5d49dbc20 100644 --- a/sdk/patina/src/lib.rs +++ b/sdk/patina/src/lib.rs @@ -13,7 +13,7 @@ #![cfg_attr(any(test, feature = "alloc"), feature(allocator_api))] #![cfg_attr(coverage, feature(coverage_attribute))] -#[cfg(any(test, feature = "alloc"))] +#[cfg(feature = "alloc")] extern crate alloc; // The base module gets republished from the root to flatten dependencies for common structures. diff --git a/sdk/patina/src/performance/measurement.rs b/sdk/patina/src/performance/measurement.rs index e8ec7895a..499864e7a 100644 --- a/sdk/patina/src/performance/measurement.rs +++ b/sdk/patina/src/performance/measurement.rs @@ -186,8 +186,8 @@ impl PerformanceProperty { mod tests { use super::*; - use alloc::boxed::Box; use core::ptr; + use std::boxed::Box; use crate::performance::record::{ PerformanceRecord, diff --git a/sdk/patina/src/peripheral/serial/virtio.rs b/sdk/patina/src/peripheral/serial/virtio.rs index 66574888c..3565b0bdb 100644 --- a/sdk/patina/src/peripheral/serial/virtio.rs +++ b/sdk/patina/src/peripheral/serial/virtio.rs @@ -132,8 +132,8 @@ mod tests { use super::*; use crate::peripheral::serial::SerialIO; - use alloc::vec::Vec; use mmio::VirtioMmioRegs; + use std::vec::Vec; fn test_instance(regs: &VirtioMmioRegs) -> VirtioSerial { // SAFETY: `regs` outlives the returned `VirtioSerial`. diff --git a/sdk/patina/src/peripheral/serial/virtio/queue.rs b/sdk/patina/src/peripheral/serial/virtio/queue.rs index 140634321..5a1143be4 100644 --- a/sdk/patina/src/peripheral/serial/virtio/queue.rs +++ b/sdk/patina/src/peripheral/serial/virtio/queue.rs @@ -279,8 +279,8 @@ impl VirtQueue { #[cfg(test)] #[cfg_attr(coverage, coverage(off))] impl VirtQueue { - pub(super) fn test_drain_tx(&mut self) -> alloc::vec::Vec> { - use alloc::vec::Vec; + pub(super) fn test_drain_tx(&mut self) -> std::vec::Vec> { + use std::vec::Vec; fence(Ordering::SeqCst); let mut out = Vec::new(); while self.used.idx != self.avail.idx { diff --git a/sdk/patina/src/pi/hob/hob_list.rs b/sdk/patina/src/pi/hob/hob_list.rs index ea8775d8b..dceb69ece 100644 --- a/sdk/patina/src/pi/hob/hob_list.rs +++ b/sdk/patina/src/pi/hob/hob_list.rs @@ -1057,7 +1057,7 @@ mod tests { #[test] fn test_hoblist_debug_display() { - use alloc::format; + use std::format; let mut hoblist = HobList::new(); let handoff = gen_phase_handoff_information_table(); diff --git a/sdk/patina/src/pi/serializable/serializable_hob.rs b/sdk/patina/src/pi/serializable/serializable_hob.rs index ef5392122..d4f42c803 100644 --- a/sdk/patina/src/pi/serializable/serializable_hob.rs +++ b/sdk/patina/src/pi/serializable/serializable_hob.rs @@ -528,7 +528,7 @@ mod tests { assert_eq!( entries, - alloc::vec![ + std::vec![ MemoryTypeInfoEntrySerDe { memory_type: 6, number_of_pages: 100 }, MemoryTypeInfoEntrySerDe { memory_type: 9, number_of_pages: 200 }, ] diff --git a/sdk/patina/src/uefi/decompress.rs b/sdk/patina/src/uefi/decompress.rs index 32fbcf151..9038bc1e9 100644 --- a/sdk/patina/src/uefi/decompress.rs +++ b/sdk/patina/src/uefi/decompress.rs @@ -724,7 +724,6 @@ impl Iterator for CodeIterator<'_> { #[cfg(test)] mod test { - extern crate std; use std::{fs::File, io::Read, iter::zip, println, time, vec, vec::Vec}; use super::decompress_into_with_algo; diff --git a/sdk/patina/src/uefi/device_path/helpers.rs b/sdk/patina/src/uefi/device_path/helpers.rs index d96ee202f..195aa113e 100644 --- a/sdk/patina/src/uefi/device_path/helpers.rs +++ b/sdk/patina/src/uefi/device_path/helpers.rs @@ -120,15 +120,12 @@ pub fn expand_device_path(boot_services: &B, partial_path: &mut #[cfg(test)] mod tests { - extern crate alloc; - extern crate std; - use super::*; use crate::{ uefi::boot_services::MockBootServices, uefi::device_path::node_defs::{Acpi, EndEntire, FilePath, HardDrive, Pci}, }; - use alloc::boxed::Box; + use std::boxed::Box; /// Helper to build a partial device path starting with HD node. fn build_partial_hd_path(guid: [u8; 16]) -> DevicePathBuf { @@ -198,11 +195,8 @@ mod tests { // Clone the device path bytes into a Vec and leak it so we can return a pointer let path_ref: &DevicePath = full_handle_path.as_ref(); // SAFETY: path_ref is a valid DevicePath reference and size() returns its exact byte length. - let bytes: alloc::vec::Vec = unsafe { - alloc::vec::Vec::from(core::slice::from_raw_parts( - std::ptr::from_ref(path_ref) as *const u8, - path_ref.size(), - )) + let bytes: std::vec::Vec = unsafe { + std::vec::Vec::from(core::slice::from_raw_parts(std::ptr::from_ref(path_ref) as *const u8, path_ref.size())) }; let leaked_bytes = Box::leak(bytes.into_boxed_slice()); let full_path_ptr: usize = leaked_bytes.as_ptr() as usize; diff --git a/sdk/patina/src/uefi/device_path/node_defs.rs b/sdk/patina/src/uefi/device_path/node_defs.rs index 12487c8df..97993a527 100644 --- a/sdk/patina/src/uefi/device_path/node_defs.rs +++ b/sdk/patina/src/uefi/device_path/node_defs.rs @@ -906,8 +906,6 @@ impl TryFromCtx<'_, scroll::Endian> for FilePath { #[cfg(test)] mod tests { - extern crate std; - use super::*; use scroll::{Pread, Pwrite}; diff --git a/sdk/patina_ffs_extractors/src/lib.rs b/sdk/patina_ffs_extractors/src/lib.rs index 20d23a5cc..33cc321f3 100644 --- a/sdk/patina_ffs_extractors/src/lib.rs +++ b/sdk/patina_ffs_extractors/src/lib.rs @@ -20,7 +20,7 @@ //! SPDX-License-Identifier: Apache-2.0 //! #![cfg_attr(coverage, feature(coverage_attribute))] -#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(all(not(feature = "std"), not(test)), no_std)] extern crate alloc; #[cfg(feature = "brotli")] @@ -51,12 +51,12 @@ const DECOMPRESSION_MAX_MEMORY_LIMIT: u32 = patina::SIZE_512MB as u32; #[cfg(test)] #[cfg_attr(coverage, coverage(off))] mod tests { - use alloc::{vec, vec::Vec}; use patina::pi::fw_fs::{ ffs::section::header::GuidDefined, guid::{BROTLI_SECTION_GUID, CRC32_SECTION_GUID, LZMA_SECTION_GUID}, }; use patina_ffs::section::{Section, SectionHeader}; + use std::{vec, vec::Vec}; /// Constructs a section with the specified GUID and payload, prepending /// the required 16-byte header (`out_size` + `scratch_size`) for Brotli sections. diff --git a/sdk/patina_ffs_extractors/src/lzma.rs b/sdk/patina_ffs_extractors/src/lzma.rs index d3c1b1f04..336301898 100644 --- a/sdk/patina_ffs_extractors/src/lzma.rs +++ b/sdk/patina_ffs_extractors/src/lzma.rs @@ -81,9 +81,9 @@ mod tests { use crate::tests::create_lzma_section; use super::*; - use alloc::vec; use patina::pi::fw_fs::ffs::section::header::GuidDefined; use patina_ffs::section::Section; + use std::vec; #[test] fn test_lzma_extractor_valid() { diff --git a/sdk/patina_macro/src/hob_macro.rs b/sdk/patina_macro/src/hob_macro.rs index fc6b6658f..dcce8deb0 100644 --- a/sdk/patina_macro/src/hob_macro.rs +++ b/sdk/patina_macro/src/hob_macro.rs @@ -153,8 +153,6 @@ mod tests { use super::*; use proc_macro2::TokenStream; use quote::quote; - extern crate alloc; - use alloc::format; #[test] fn test_config_basic() { @@ -229,7 +227,7 @@ mod tests { // Test that the hex string provided in the attribute matches the well known PCD Database HOB GUID let (f0, f1, f2, f3, f4, &[f5, f6, f7, f8, f9, f10]) = TEST_HOB_GUID.as_fields(); - let name = alloc::format!( + let name = std::format!( "{f0:08x}-{f1:04x}-{f2:04x}-{f3:02x}{f4:02x}-{f5:02x}{f6:02x}{f7:02x}{f8:02x}{f9:02x}{f10:02x}" ); assert_eq!(name, "ea296d92-0b69-423c-8c28-33b4e0a91268"); diff --git a/sdk/patina_macro/src/lib.rs b/sdk/patina_macro/src/lib.rs index 7a700a5bc..3cee6923e 100644 --- a/sdk/patina_macro/src/lib.rs +++ b/sdk/patina_macro/src/lib.rs @@ -9,6 +9,8 @@ #![cfg_attr(coverage, feature(coverage_attribute))] +extern crate alloc; + mod device_path_encoder; mod device_path_macro; mod device_path_nodes;