Skip to content

Commit 0e9c2c1

Browse files
authored
patina: test: Add test on event callback support (#927)
## Description adds a new attribute for the `#[patina_test]` attribute macro that allows the user to specify a UEFI event that the test should be executed on. When the UEFI event callback is fired, the patina_test will be executed. This new attribute is `#[on(event= <REAL_GUID>)]` e.g. `#[on(event = r_efi::efi::EVENT_GROUP_READY_TO_BOOT)]`. After this change, not all patina_tests are executed immediately during the `TestRunner` component. Due To this, test result reporting is delayed to two separate event callbacks. Test results are now reported once at READY_TO_BOOT and once at EXIT_BOOT_SERVICES. The `fail_fast` config feature has been removed. This is because not all tests happen within the control of the `TestRunner` component, and thus cannot fail if it wanted to. Instead, an optional callback can be registered by the platform to handle an error however the platform prefers, that is executed anytime a test fails. Example Test reporting: ``` INFO - INFO - Patina on-system unit-test results: INFO - patina_adv_logger::integration_test::adv_logger_test ... ok (1 passes) INFO - patina_dxe_core::memory_manager::memory_manager_allocations_test ... ok (1 passes) INFO - patina_dxe_core::memory_manager::memory_manager_attributes_test ... ok (1 passes) INFO - qemu_q35_dxe_core::my_test ... ok (413 passes) INFO - qemu_q35_dxe_core::ready_to_boot_test ... ok (1 passes) ``` - [x] Impacts functionality? - [ ] Impacts security? - [ ] Breaking change? - [x] Includes tests? - [x] Includes documentation? ## How This Was Tested Boot to QEMUQ35 with various tests that use the event callback logic. ## Integration Instructions 1. Developers can now edit or write patina_tests that use the newly created attribute macro. This attribute macro allows you to specify an event guid to have your test executed on. Example seen below. Please note that if an invalid guid is provided, or the event never fires, the test results will report the test as "not triggered" ```rust #[patina_test] #[on(event = r_efi::efi::EVENT_GROUP_READY_TO_BOOT)] fn my_patina_test() -> Result { Ok(()) } ``` 2. Developers can now register a callback function that is executed if a test fails ```rust let component = TestRunner::default().with_callback(|test_name, err_msg| { panic!("{test_name} errored with result {err_msg}); }); ``` 3. Remove any configuration of `fail_fast` e.g. `fail_fast(...)`. Replace with custom error handling when a patina test fails with `.with_callback(fn(&'static str, &'static str))`
1 parent 5968418 commit 0e9c2c1

File tree

5 files changed

+630
-66
lines changed

5 files changed

+630
-66
lines changed

docs/src/dev/testing/platform.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ use patina_dxe_core::Core;
9797
9898
let test_runner = TestRunner::default()
9999
.with_filter("X64")
100-
.debug_mode(true)
101-
.fail_fast(true);
100+
.debug_mode(true);
102101
103102
Core::default()
104103
.init_memory(hob_list)

sdk/patina/src/boot_services/c_ptr.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use core::{
1313
mem::{self, ManuallyDrop},
1414
num::NonZeroUsize,
1515
ops::Deref,
16-
ptr,
16+
ptr::{self, NonNull},
1717
};
1818

1919
#[derive(Copy)]
@@ -231,6 +231,16 @@ unsafe impl<'a, R: CRef<'a, Type = T>, T> CRef<'a> for ManuallyDrop<R> {}
231231
// SAFETY: Memory layout and mutability are respected for these types.
232232
unsafe impl<'a, R: CMutRef<'a, Type = T>, T> CMutRef<'a> for ManuallyDrop<R> {}
233233

234+
// SAFETY: NonNull<T> is a transparent wrapper around a non-null pointer that preserves
235+
// the memory layout and pointer semantics of T.
236+
unsafe impl<T> CPtr<'_> for NonNull<T> {
237+
type Type = T;
238+
239+
fn as_ptr(&self) -> *const Self::Type {
240+
Self::as_ptr(*self)
241+
}
242+
}
243+
234244
#[cfg(test)]
235245
#[coverage(off)]
236246
mod tests {

0 commit comments

Comments
 (0)