guest_test_uefi/uefi/tests/mod.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use crate::uefi::Splashes;
use crate::uefi::splash;
use core::num::NonZeroU8;
use uefi::boot;
use uefi::cstr16;
use uefi::println;
use uefi::runtime;
use uefi::runtime::VariableVendor;
// TODO: add runtime config for which tests to run (e.g: skipping watchdog)
pub fn run_tests() {
println!("running tests...");
let mut splash_seq = 2u8;
macro_rules! do_test {
($test_fn:ident) => {{
let name = stringify!($test_fn);
println!(">>>>>> [TEST]: running '{}'", name);
$test_fn();
splash_seq = splash_seq.wrapping_shl(1);
splash::draw_splash(Splashes(NonZeroU8::new(splash_seq).unwrap()));
boot::stall(1000000); // stall for 1 seconds
}};
}
do_test!(test_global_alloc);
do_test!(test_dbdefault);
// TODO: re-enable when UEFI handles dbDefault correctly
//do_test!(test_readonly);
// leave the watchdog test for last, since it blows away the VM
do_test!(test_watchdog);
}
fn test_global_alloc() {
let s = format!("hello {}!", "world");
println!("look 'ma, i'm outputting a heap allocated string: {}", s);
}
fn test_watchdog() {
boot::set_watchdog_timer(5, 0xdeadbeef, None).unwrap();
boot::stall(1000000 * 6); // stall for 6 seconds
panic!("watchdog should've expired, but we're still running!")
}
fn test_dbdefault() {
let db = runtime::get_variable_boxed(cstr16!("db"), &VariableVendor::IMAGE_SECURITY_DATABASE);
let dbdefault =
runtime::get_variable_boxed(cstr16!("dbDefault"), &VariableVendor::GLOBAL_VARIABLE);
let (db_data, _) = db.expect("db not found");
let (dbdefault_data, _) = dbdefault.expect("dbDefault not found");
assert_eq!(db_data, dbdefault_data);
}
/* TODO: re-enable when UEFI handles dbDefault correctly
fn test_readonly(rt: &RuntimeServices) {
match rt.set_variable(
cstr16!("dbDefault"),
&VariableVendor::GLOBAL_VARIABLE,
VariableAttributes::BOOTSERVICE_ACCESS | VariableAttributes::RUNTIME_ACCESS,
&[0, 1, 2],
) {
Ok(_) => {
panic!("Expected an error, but got Ok")
}
Err(error) => {
assert_eq!(
error.status(),
Status::WRITE_PROTECTED,
"Error status: {:?}",
error.status()
)
}
}
}
*/