Commit 0e9c2c1
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- docs/src/dev/testing
- sdk
- patina_macro/src
- patina/src
- boot_services
- test
5 files changed
+630
-66
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
| 100 | + | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
234 | 244 | | |
235 | 245 | | |
236 | 246 | | |
| |||
0 commit comments