Skip to content

Commit

Permalink
wip: Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasbishop committed Jul 20, 2024
1 parent 85901b6 commit b0de1ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions uefi-test-runner/src/runtime/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ fn test_variables(rt: &RuntimeServices) {
info!("First variable: {}", key);
}

// Test that the `runtime::variable_keys` iterator gives exactly the same
// list as the `RuntimeServices::variable_keys` function.
assert_eq!(
runtime::variable_keys()
.map(|k| k.unwrap())
.collect::<alloc::vec::Vec<_>>(),
variable_keys
);

info!("Testing delete_variable()");
rt.delete_variable(NAME, VENDOR)
.expect("failed to delete variable");
Expand Down Expand Up @@ -86,6 +95,15 @@ fn test_variables_freestanding() {
assert_eq!(&*data, VALUE);
assert_eq!(attrs, ATTRS);

// Test that the variable is present in the `variable_keys` iterator.
let find_by_key = || {
runtime::variable_keys().any(|k| {
let k = k.as_ref().unwrap();
k.name().unwrap() == NAME && &k.vendor == VENDOR
})
};
assert!(find_by_key());

// Delete the variable and verify it can no longer be read.
runtime::delete_variable(NAME, VENDOR).expect("failed to delete variable");
assert_eq!(
Expand All @@ -94,6 +112,8 @@ fn test_variables_freestanding() {
.status(),
Status::NOT_FOUND
);
// Variable is no longer present in the `variable_keys` iterator.
assert!(!find_by_key());
}

fn test_variable_info(rt: &RuntimeServices) {
Expand Down
2 changes: 1 addition & 1 deletion uefi/src/table/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ impl TryFrom<&[u8]> for Time {

/// Unique key for a variable.
#[cfg(feature = "alloc")]
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct VariableKey {
pub(crate) name: Vec<u16>,
/// Unique identifier for the vendor.
Expand Down

0 comments on commit b0de1ab

Please sign in to comment.