Skip to content

test-runner: Make some tests stricter #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions uefi-test-runner/src/proto/console/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ use uefi::table::boot::BootServices;

pub fn test(bt: &BootServices) {
info!("Running pointer protocol test");
if let Ok(handle) = bt.get_handle_for_protocol::<Pointer>() {
let mut pointer = bt
.open_protocol_exclusive::<Pointer>(handle)
.expect("failed to open pointer protocol");
let handle = bt
.get_handle_for_protocol::<Pointer>()
.expect("missing Pointer protocol");
let mut pointer = bt
.open_protocol_exclusive::<Pointer>(handle)
.expect("failed to open pointer protocol");

pointer
.reset(false)
.expect("Failed to reset pointer device");
pointer
.reset(false)
.expect("Failed to reset pointer device");

let state = pointer
.read_state()
.expect("Failed to retrieve pointer state");
let state = pointer
.read_state()
.expect("Failed to retrieve pointer state");

if let Some(state) = state {
info!("New pointer State: {:#?}", state);
} else {
info!("Pointer state has not changed since the last query");
}
if let Some(state) = state {
info!("New pointer State: {:#?}", state);
} else {
warn!("No pointer device found");
info!("Pointer state has not changed since the last query");
}
}
97 changes: 48 additions & 49 deletions uefi-test-runner/src/proto/console/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,61 @@ use uefi::Handle;

pub unsafe fn test(image: Handle, bt: &BootServices) {
info!("Running serial protocol test");
if let Ok(handle) = bt.get_handle_for_protocol::<Serial>() {
let mut serial = bt
.open_protocol::<Serial>(
OpenProtocolParams {
handle,
agent: image,
controller: None,
},
// For this test, don't open in exclusive mode. That
// would break the connection between stdout and the
// serial device.
OpenProtocolAttributes::GetProtocol,
)
.expect("failed to open serial protocol");
// BUG: there are multiple failures in the serial tests on AArch64
if cfg!(target_arch = "aarch64") {
return;
}
let handle = bt
.get_handle_for_protocol::<Serial>()
.expect("missing Serial protocol");
let mut serial = bt
.open_protocol::<Serial>(
OpenProtocolParams {
handle,
agent: image,
controller: None,
},
// For this test, don't open in exclusive mode. That
// would break the connection between stdout and the
// serial device.
OpenProtocolAttributes::GetProtocol,
)
.expect("failed to open serial protocol");
// BUG: there are multiple failures in the serial tests on AArch64
if cfg!(target_arch = "aarch64") {
return;
}

let old_ctrl_bits = serial
.get_control_bits()
.expect("Failed to get device control bits");
let mut ctrl_bits = ControlBits::empty();
let old_ctrl_bits = serial
.get_control_bits()
.expect("Failed to get device control bits");
let mut ctrl_bits = ControlBits::empty();

// For the purposes of testing, we're _not_ going to implement
// software flow control.
ctrl_bits |= ControlBits::HARDWARE_FLOW_CONTROL_ENABLE;
// For the purposes of testing, we're _not_ going to implement
// software flow control.
ctrl_bits |= ControlBits::HARDWARE_FLOW_CONTROL_ENABLE;

// Use a loop back device for testing.
ctrl_bits |= ControlBits::SOFTWARE_LOOPBACK_ENABLE;
// Use a loop back device for testing.
ctrl_bits |= ControlBits::SOFTWARE_LOOPBACK_ENABLE;

serial
.set_control_bits(ctrl_bits)
.expect("Failed to set device control bits");
serial
.set_control_bits(ctrl_bits)
.expect("Failed to set device control bits");

// Keep this message short, we need it to fit in the FIFO.
const OUTPUT: &[u8] = b"Hello world!";
const MSG_LEN: usize = OUTPUT.len();
// Keep this message short, we need it to fit in the FIFO.
const OUTPUT: &[u8] = b"Hello world!";
const MSG_LEN: usize = OUTPUT.len();

serial
.write(OUTPUT)
.expect("Failed to write to serial port");
serial
.write(OUTPUT)
.expect("Failed to write to serial port");

let mut input = [0u8; MSG_LEN];
serial
.read(&mut input)
.expect("Failed to read from serial port");
let mut input = [0u8; MSG_LEN];
serial
.read(&mut input)
.expect("Failed to read from serial port");

assert_eq!(OUTPUT, &input[..]);
assert_eq!(OUTPUT, &input[..]);

// Clean up after ourselves
serial.reset().expect("Could not reset the serial device");
serial
.set_control_bits(old_ctrl_bits & ControlBits::SETTABLE)
.expect("Could not restore the serial device state");
} else {
warn!("No serial device found");
}
// Clean up after ourselves
serial.reset().expect("Could not reset the serial device");
serial
.set_control_bits(old_ctrl_bits & ControlBits::SETTABLE)
.expect("Could not restore the serial device state");
}
149 changes: 72 additions & 77 deletions uefi-test-runner/src/proto/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,86 @@ use uefi::table::boot::BootServices;

pub fn test(bt: &BootServices) {
info!("Running UEFI debug connection protocol test");
if let Ok(handles) = bt.find_handles::<DebugSupport>() {
for handle in handles {
if let Ok(mut debug_support) = bt.open_protocol_exclusive::<DebugSupport>(handle) {
// make sure that the max processor index is a sane value, i.e. it works
let maximum_processor_index = debug_support.get_maximum_processor_index();
assert_ne!(
let handles = bt
.find_handles::<DebugSupport>()
.expect("missing DebugSupport protocol");
for handle in handles {
if let Ok(mut debug_support) = bt.open_protocol_exclusive::<DebugSupport>(handle) {
// make sure that the max processor index is a sane value, i.e. it works
let maximum_processor_index = debug_support.get_maximum_processor_index();
assert_ne!(
maximum_processor_index,
usize::MAX,
"get_maximum_processor_index() returning garbage, unless you really have 18,446,744,073,709,551,615 processors"
);

info!("- Architecture: {:?}", debug_support.arch());
info!("- Maximum Processor Index: {:?}", maximum_processor_index);
info!("- Architecture: {:?}", debug_support.arch());
info!("- Maximum Processor Index: {:?}", maximum_processor_index);

match debug_support.arch() {
// This arm is the only match when testing on QEMU w/ OVMF, regardless of the machine arch.
// The released OVMF builds don't implement the Debug Support Protocol Interface for the
// machine arch, only EBC.
ProcessorArch::EBC => unsafe {
info!("Registering periodic callback");
debug_support
.register_periodic_callback(0, Some(periodic_callback))
.expect("Error while registering periodic callback");
info!("Deregistering periodic callback");
debug_support
.register_periodic_callback(0, None)
.expect("Error while deregistering periodic callback");
// for the EBC virtual CPU, there are already exception callbacks registered
info!("Deregistering exception callback");
debug_support
.register_exception_callback(0, None, ExceptionType::EXCEPT_EBC_DEBUG)
.expect("Error while deregistering exception callback");
info!("Registering exception callback");
debug_support
.register_exception_callback(
0,
Some(exception_callback),
ExceptionType::EXCEPT_EBC_DEBUG,
)
.expect("Error while registering exception callback");
},
#[cfg(target_arch = "x86_64")]
ProcessorArch::X86_64 => unsafe {
info!("Registering exception callback");
debug_support
.register_exception_callback(
0,
Some(exception_callback),
ExceptionType::EXCEPT_X64_DEBUG,
)
.expect("Error while registering exception callback");
info!("Deregistering exception callback");
debug_support
.register_exception_callback(0, None, ExceptionType::EXCEPT_X64_DEBUG)
.expect("Error while deregistering exception callback");
},
#[cfg(target_arch = "aarch64")]
ProcessorArch::AARCH_64 => unsafe {
info!("Registering exception callback");
debug_support
.register_exception_callback(
0,
Some(exception_callback),
ExceptionType::EXCEPT_AARCH64_SERROR,
)
.expect("Error while registering exception callback");
info!("Deregistering exception callback");
debug_support
.register_exception_callback(
0,
None,
ExceptionType::EXCEPT_AARCH64_SERROR,
)
.expect("Error while deregistering exception callback");
},
// if we reach this, we're running on an arch that `cargo xtask run` doesn't support
// TODO: Add match arms as we support testing on more archs
_ => unreachable!(),
}

test_invalidate_instruction_cache(&mut debug_support);
match debug_support.arch() {
// This arm is the only match when testing on QEMU w/ OVMF, regardless of the machine arch.
// The released OVMF builds don't implement the Debug Support Protocol Interface for the
// machine arch, only EBC.
ProcessorArch::EBC => unsafe {
info!("Registering periodic callback");
debug_support
.register_periodic_callback(0, Some(periodic_callback))
.expect("Error while registering periodic callback");
info!("Deregistering periodic callback");
debug_support
.register_periodic_callback(0, None)
.expect("Error while deregistering periodic callback");
// for the EBC virtual CPU, there are already exception callbacks registered
info!("Deregistering exception callback");
debug_support
.register_exception_callback(0, None, ExceptionType::EXCEPT_EBC_DEBUG)
.expect("Error while deregistering exception callback");
info!("Registering exception callback");
debug_support
.register_exception_callback(
0,
Some(exception_callback),
ExceptionType::EXCEPT_EBC_DEBUG,
)
.expect("Error while registering exception callback");
},
#[cfg(target_arch = "x86_64")]
ProcessorArch::X86_64 => unsafe {
info!("Registering exception callback");
debug_support
.register_exception_callback(
0,
Some(exception_callback),
ExceptionType::EXCEPT_X64_DEBUG,
)
.expect("Error while registering exception callback");
info!("Deregistering exception callback");
debug_support
.register_exception_callback(0, None, ExceptionType::EXCEPT_X64_DEBUG)
.expect("Error while deregistering exception callback");
},
#[cfg(target_arch = "aarch64")]
ProcessorArch::AARCH_64 => unsafe {
info!("Registering exception callback");
debug_support
.register_exception_callback(
0,
Some(exception_callback),
ExceptionType::EXCEPT_AARCH64_SERROR,
)
.expect("Error while registering exception callback");
info!("Deregistering exception callback");
debug_support
.register_exception_callback(0, None, ExceptionType::EXCEPT_AARCH64_SERROR)
.expect("Error while deregistering exception callback");
},
// if we reach this, we're running on an arch that `cargo xtask run` doesn't support
// TODO: Add match arms as we support testing on more archs
_ => unreachable!(),
}

test_invalidate_instruction_cache(&mut debug_support);
}
} else {
warn!("Debug protocol is not supported");
}
}

Expand Down
Loading