Skip to content

Commit 43a951f

Browse files
authored
Merge pull request #595 from nicholasbishop/bishop-make-test-stricter-2
test-runner: Make some tests stricter
2 parents cceedb9 + a3f42d0 commit 43a951f

File tree

4 files changed

+222
-230
lines changed

4 files changed

+222
-230
lines changed

uefi-test-runner/src/proto/console/pointer.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@ use uefi::table::boot::BootServices;
33

44
pub fn test(bt: &BootServices) {
55
info!("Running pointer protocol test");
6-
if let Ok(handle) = bt.get_handle_for_protocol::<Pointer>() {
7-
let mut pointer = bt
8-
.open_protocol_exclusive::<Pointer>(handle)
9-
.expect("failed to open pointer protocol");
6+
let handle = bt
7+
.get_handle_for_protocol::<Pointer>()
8+
.expect("missing Pointer protocol");
9+
let mut pointer = bt
10+
.open_protocol_exclusive::<Pointer>(handle)
11+
.expect("failed to open pointer protocol");
1012

11-
pointer
12-
.reset(false)
13-
.expect("Failed to reset pointer device");
13+
pointer
14+
.reset(false)
15+
.expect("Failed to reset pointer device");
1416

15-
let state = pointer
16-
.read_state()
17-
.expect("Failed to retrieve pointer state");
17+
let state = pointer
18+
.read_state()
19+
.expect("Failed to retrieve pointer state");
1820

19-
if let Some(state) = state {
20-
info!("New pointer State: {:#?}", state);
21-
} else {
22-
info!("Pointer state has not changed since the last query");
23-
}
21+
if let Some(state) = state {
22+
info!("New pointer State: {:#?}", state);
2423
} else {
25-
warn!("No pointer device found");
24+
info!("Pointer state has not changed since the last query");
2625
}
2726
}

uefi-test-runner/src/proto/console/serial.rs

+48-49
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,61 @@ use uefi::Handle;
44

55
pub unsafe fn test(image: Handle, bt: &BootServices) {
66
info!("Running serial protocol test");
7-
if let Ok(handle) = bt.get_handle_for_protocol::<Serial>() {
8-
let mut serial = bt
9-
.open_protocol::<Serial>(
10-
OpenProtocolParams {
11-
handle,
12-
agent: image,
13-
controller: None,
14-
},
15-
// For this test, don't open in exclusive mode. That
16-
// would break the connection between stdout and the
17-
// serial device.
18-
OpenProtocolAttributes::GetProtocol,
19-
)
20-
.expect("failed to open serial protocol");
21-
// BUG: there are multiple failures in the serial tests on AArch64
22-
if cfg!(target_arch = "aarch64") {
23-
return;
24-
}
7+
let handle = bt
8+
.get_handle_for_protocol::<Serial>()
9+
.expect("missing Serial protocol");
10+
let mut serial = bt
11+
.open_protocol::<Serial>(
12+
OpenProtocolParams {
13+
handle,
14+
agent: image,
15+
controller: None,
16+
},
17+
// For this test, don't open in exclusive mode. That
18+
// would break the connection between stdout and the
19+
// serial device.
20+
OpenProtocolAttributes::GetProtocol,
21+
)
22+
.expect("failed to open serial protocol");
23+
// BUG: there are multiple failures in the serial tests on AArch64
24+
if cfg!(target_arch = "aarch64") {
25+
return;
26+
}
2527

26-
let old_ctrl_bits = serial
27-
.get_control_bits()
28-
.expect("Failed to get device control bits");
29-
let mut ctrl_bits = ControlBits::empty();
28+
let old_ctrl_bits = serial
29+
.get_control_bits()
30+
.expect("Failed to get device control bits");
31+
let mut ctrl_bits = ControlBits::empty();
3032

31-
// For the purposes of testing, we're _not_ going to implement
32-
// software flow control.
33-
ctrl_bits |= ControlBits::HARDWARE_FLOW_CONTROL_ENABLE;
33+
// For the purposes of testing, we're _not_ going to implement
34+
// software flow control.
35+
ctrl_bits |= ControlBits::HARDWARE_FLOW_CONTROL_ENABLE;
3436

35-
// Use a loop back device for testing.
36-
ctrl_bits |= ControlBits::SOFTWARE_LOOPBACK_ENABLE;
37+
// Use a loop back device for testing.
38+
ctrl_bits |= ControlBits::SOFTWARE_LOOPBACK_ENABLE;
3739

38-
serial
39-
.set_control_bits(ctrl_bits)
40-
.expect("Failed to set device control bits");
40+
serial
41+
.set_control_bits(ctrl_bits)
42+
.expect("Failed to set device control bits");
4143

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

46-
serial
47-
.write(OUTPUT)
48-
.expect("Failed to write to serial port");
48+
serial
49+
.write(OUTPUT)
50+
.expect("Failed to write to serial port");
4951

50-
let mut input = [0u8; MSG_LEN];
51-
serial
52-
.read(&mut input)
53-
.expect("Failed to read from serial port");
52+
let mut input = [0u8; MSG_LEN];
53+
serial
54+
.read(&mut input)
55+
.expect("Failed to read from serial port");
5456

55-
assert_eq!(OUTPUT, &input[..]);
57+
assert_eq!(OUTPUT, &input[..]);
5658

57-
// Clean up after ourselves
58-
serial.reset().expect("Could not reset the serial device");
59-
serial
60-
.set_control_bits(old_ctrl_bits & ControlBits::SETTABLE)
61-
.expect("Could not restore the serial device state");
62-
} else {
63-
warn!("No serial device found");
64-
}
59+
// Clean up after ourselves
60+
serial.reset().expect("Could not reset the serial device");
61+
serial
62+
.set_control_bits(old_ctrl_bits & ControlBits::SETTABLE)
63+
.expect("Could not restore the serial device state");
6564
}

uefi-test-runner/src/proto/debug.rs

+72-77
Original file line numberDiff line numberDiff line change
@@ -4,91 +4,86 @@ use uefi::table::boot::BootServices;
44

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

18-
info!("- Architecture: {:?}", debug_support.arch());
19-
info!("- Maximum Processor Index: {:?}", maximum_processor_index);
20+
info!("- Architecture: {:?}", debug_support.arch());
21+
info!("- Maximum Processor Index: {:?}", maximum_processor_index);
2022

21-
match debug_support.arch() {
22-
// This arm is the only match when testing on QEMU w/ OVMF, regardless of the machine arch.
23-
// The released OVMF builds don't implement the Debug Support Protocol Interface for the
24-
// machine arch, only EBC.
25-
ProcessorArch::EBC => unsafe {
26-
info!("Registering periodic callback");
27-
debug_support
28-
.register_periodic_callback(0, Some(periodic_callback))
29-
.expect("Error while registering periodic callback");
30-
info!("Deregistering periodic callback");
31-
debug_support
32-
.register_periodic_callback(0, None)
33-
.expect("Error while deregistering periodic callback");
34-
// for the EBC virtual CPU, there are already exception callbacks registered
35-
info!("Deregistering exception callback");
36-
debug_support
37-
.register_exception_callback(0, None, ExceptionType::EXCEPT_EBC_DEBUG)
38-
.expect("Error while deregistering exception callback");
39-
info!("Registering exception callback");
40-
debug_support
41-
.register_exception_callback(
42-
0,
43-
Some(exception_callback),
44-
ExceptionType::EXCEPT_EBC_DEBUG,
45-
)
46-
.expect("Error while registering exception callback");
47-
},
48-
#[cfg(target_arch = "x86_64")]
49-
ProcessorArch::X86_64 => unsafe {
50-
info!("Registering exception callback");
51-
debug_support
52-
.register_exception_callback(
53-
0,
54-
Some(exception_callback),
55-
ExceptionType::EXCEPT_X64_DEBUG,
56-
)
57-
.expect("Error while registering exception callback");
58-
info!("Deregistering exception callback");
59-
debug_support
60-
.register_exception_callback(0, None, ExceptionType::EXCEPT_X64_DEBUG)
61-
.expect("Error while deregistering exception callback");
62-
},
63-
#[cfg(target_arch = "aarch64")]
64-
ProcessorArch::AARCH_64 => unsafe {
65-
info!("Registering exception callback");
66-
debug_support
67-
.register_exception_callback(
68-
0,
69-
Some(exception_callback),
70-
ExceptionType::EXCEPT_AARCH64_SERROR,
71-
)
72-
.expect("Error while registering exception callback");
73-
info!("Deregistering exception callback");
74-
debug_support
75-
.register_exception_callback(
76-
0,
77-
None,
78-
ExceptionType::EXCEPT_AARCH64_SERROR,
79-
)
80-
.expect("Error while deregistering exception callback");
81-
},
82-
// if we reach this, we're running on an arch that `cargo xtask run` doesn't support
83-
// TODO: Add match arms as we support testing on more archs
84-
_ => unreachable!(),
85-
}
86-
87-
test_invalidate_instruction_cache(&mut debug_support);
23+
match debug_support.arch() {
24+
// This arm is the only match when testing on QEMU w/ OVMF, regardless of the machine arch.
25+
// The released OVMF builds don't implement the Debug Support Protocol Interface for the
26+
// machine arch, only EBC.
27+
ProcessorArch::EBC => unsafe {
28+
info!("Registering periodic callback");
29+
debug_support
30+
.register_periodic_callback(0, Some(periodic_callback))
31+
.expect("Error while registering periodic callback");
32+
info!("Deregistering periodic callback");
33+
debug_support
34+
.register_periodic_callback(0, None)
35+
.expect("Error while deregistering periodic callback");
36+
// for the EBC virtual CPU, there are already exception callbacks registered
37+
info!("Deregistering exception callback");
38+
debug_support
39+
.register_exception_callback(0, None, ExceptionType::EXCEPT_EBC_DEBUG)
40+
.expect("Error while deregistering exception callback");
41+
info!("Registering exception callback");
42+
debug_support
43+
.register_exception_callback(
44+
0,
45+
Some(exception_callback),
46+
ExceptionType::EXCEPT_EBC_DEBUG,
47+
)
48+
.expect("Error while registering exception callback");
49+
},
50+
#[cfg(target_arch = "x86_64")]
51+
ProcessorArch::X86_64 => unsafe {
52+
info!("Registering exception callback");
53+
debug_support
54+
.register_exception_callback(
55+
0,
56+
Some(exception_callback),
57+
ExceptionType::EXCEPT_X64_DEBUG,
58+
)
59+
.expect("Error while registering exception callback");
60+
info!("Deregistering exception callback");
61+
debug_support
62+
.register_exception_callback(0, None, ExceptionType::EXCEPT_X64_DEBUG)
63+
.expect("Error while deregistering exception callback");
64+
},
65+
#[cfg(target_arch = "aarch64")]
66+
ProcessorArch::AARCH_64 => unsafe {
67+
info!("Registering exception callback");
68+
debug_support
69+
.register_exception_callback(
70+
0,
71+
Some(exception_callback),
72+
ExceptionType::EXCEPT_AARCH64_SERROR,
73+
)
74+
.expect("Error while registering exception callback");
75+
info!("Deregistering exception callback");
76+
debug_support
77+
.register_exception_callback(0, None, ExceptionType::EXCEPT_AARCH64_SERROR)
78+
.expect("Error while deregistering exception callback");
79+
},
80+
// if we reach this, we're running on an arch that `cargo xtask run` doesn't support
81+
// TODO: Add match arms as we support testing on more archs
82+
_ => unreachable!(),
8883
}
84+
85+
test_invalidate_instruction_cache(&mut debug_support);
8986
}
90-
} else {
91-
warn!("Debug protocol is not supported");
9287
}
9388
}
9489

0 commit comments

Comments
 (0)