Skip to content

Commit 971b01c

Browse files
committed
Port uefi-test-runner to Completion
1 parent 3957b56 commit 971b01c

File tree

8 files changed

+104
-53
lines changed

8 files changed

+104
-53
lines changed

uefi-test-runner/src/boot/memory.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ fn allocate_pages(bt: &BootServices) {
2020
let mem_ty = MemoryType::LOADER_DATA;
2121
let pgs = bt
2222
.allocate_pages(ty, mem_ty, 1)
23-
.expect("Failed to allocate a page of memory");
23+
.expect("Failed to allocate a page of memory")
24+
.expect("Warnings encountered while allocating a page");
2425

2526
assert_eq!(pgs % 4096, 0, "Page pointer is not page-aligned");
2627

@@ -37,7 +38,7 @@ fn allocate_pages(bt: &BootServices) {
3738
buf[4095] = 0x23;
3839

3940
// Clean up to avoid memory leaks.
40-
bt.free_pages(pgs, 1).unwrap();
41+
bt.free_pages(pgs, 1).unwrap().unwrap();
4142
}
4243

4344
// Simple test to ensure our custom allocator works with the `alloc` crate.
@@ -91,7 +92,8 @@ fn memory_map(bt: &BootServices) {
9192

9293
let (_key, mut desc_iter) = bt
9394
.memory_map(&mut buffer)
94-
.expect("Failed to retrieve UEFI memory map");
95+
.expect("Failed to retrieve UEFI memory map")
96+
.expect("Warnings encountered while retrieving memory map");
9597

9698
// Ensured we have at least one entry.
9799
// Real memory maps usually have dozens of entries.

uefi-test-runner/src/boot/misc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ pub fn test(bt: &BootServices) {
77
fn test_watchdog(bt: &BootServices) {
88
// Disable the UEFI watchdog timer
99
bt.set_watchdog_timer(0, 0x10000, None)
10-
.expect("Could not set watchdog timer");
10+
.expect("Could not set watchdog timer")
11+
.expect("Warnings encountered while setting watchdog timer");
1112
}

uefi-test-runner/src/main.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#![no_std]
22
#![no_main]
3-
#![feature(slice_patterns)]
43
#![feature(alloc)]
54
#![feature(asm)]
5+
#![feature(const_slice_len)]
6+
#![feature(slice_patterns)]
67

78
#[macro_use]
89
extern crate log;
@@ -22,7 +23,10 @@ pub extern "win64" fn uefi_start(_handle: uefi::Handle, st: &'static SystemTable
2223
uefi_services::init(st);
2324

2425
// Reset the console before running all the other tests.
25-
st.stdout().reset(false).expect("Failed to reset stdout");
26+
st.stdout()
27+
.reset(false)
28+
.expect("Failed to reset stdout")
29+
.expect("Warnings encountered while resetting stdout");
2630

2731
// Ensure the tests are run on a version of UEFI we support.
2832
check_revision(st.uefi_revision());
@@ -71,25 +75,31 @@ fn check_screenshot(bt: &BootServices, name: &str) {
7175
io_mode.timeout = 3_000_000;
7276
serial
7377
.set_attributes(&io_mode)
74-
.expect("Failed to configure serial port timeout");
78+
.expect("Failed to configure serial port timeout")
79+
.expect("Warnings encountered while configuring serial port timeout");
7580

7681
// Send a screenshot request to the host
77-
let mut len = serial
82+
serial
7883
.write(b"SCREENSHOT: ")
79-
.expect("Failed to send request");
80-
assert_eq!(len, 12, "Screenshot request timed out");
84+
.expect("Failed to send request")
85+
.expect("Request triggered a warning");
8186
let name_bytes = name.as_bytes();
82-
len = serial.write(name_bytes).expect("Failed to send request");
83-
assert_eq!(len, name_bytes.len(), "Screenshot request timed out");
84-
len = serial.write(b"\n").expect("Failed to send request");
85-
assert_eq!(len, 1, "Screenshot request timed out");
87+
serial
88+
.write(name_bytes)
89+
.expect("Failed to send request")
90+
.expect("Request triggered a warning");
91+
serial
92+
.write(b"\n")
93+
.expect("Failed to send request")
94+
.expect("Request triggered a warning");
8695

8796
// Wait for the host's acknowledgement before moving forward
8897
let mut reply = [0; 3];
89-
let read_size = serial
98+
serial
9099
.read(&mut reply[..])
91-
.expect("Failed to read host reply");
92-
assert_eq!(read_size, 3, "Screenshot request timed out");
100+
.expect("Failed to read host reply")
101+
.expect("Request triggered a warning");
102+
93103
assert_eq!(&reply[..], b"OK\n", "Unexpected screenshot request reply");
94104
} else {
95105
// Outside of QEMU, give the user some time to inspect the output
@@ -101,7 +111,7 @@ fn shutdown(st: &SystemTable) -> ! {
101111
use uefi::table::runtime::ResetType;
102112

103113
// Get our text output back.
104-
st.stdout().reset(false).unwrap();
114+
st.stdout().reset(false).unwrap().unwrap();
105115

106116
// Inform the user, and give him time to read on real hardware
107117
if cfg!(not(feature = "qemu")) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ fn set_graphics_mode(gop: &mut GraphicsOutput) {
2424
// We know for sure QEMU has a 1024x768, mode.
2525
let mode = gop
2626
.modes()
27+
.map(|mode| mode.expect("Warnings encountered while querying mode"))
2728
.find(|ref mode| {
2829
let info = mode.info();
29-
3030
info.resolution() == (1024, 768)
3131
})
3232
.unwrap();
3333

34-
gop.set_mode(&mode).expect("Failed to set graphics mode");
34+
gop.set_mode(&mode)
35+
.expect("Failed to set graphics mode")
36+
.expect("Warnings encountered while setting graphics mode");
3537
}
3638

3739
// Fill the screen with color.
@@ -43,7 +45,9 @@ fn fill_color(gop: &mut GraphicsOutput) {
4345
dims: (1024, 768),
4446
};
4547

46-
gop.blt(op).expect("Failed to fill screen with color");
48+
gop.blt(op)
49+
.expect("Failed to fill screen with color")
50+
.expect("Warnings encountered while filling screen with color");
4751
}
4852

4953
// Draw directly to the frame buffer.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ pub fn test(bt: &BootServices) {
1010

1111
pointer
1212
.reset(false)
13-
.expect("Failed to reset pointer device");
13+
.expect("Failed to reset pointer device")
14+
.expect("Warnings encountered while resetting pointer device");
1415

1516
let state = pointer
1617
.read_state()
17-
.expect("Failed to retrieve pointer state");
18+
.expect("Failed to retrieve pointer state")
19+
.expect("Warnings encountered while retrieving pointer state");
1820
if let Some(state) = state {
1921
info!("New pointer State: {:#?}", state);
2022
} else {

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ pub fn test(bt: &BootServices) {
99

1010
let old_ctrl_bits = serial
1111
.get_control_bits()
12-
.expect("Failed to get device control bits");
12+
.expect("Failed to get device control bits")
13+
.expect("Warnings encountered while getting device control bits");
1314
let mut ctrl_bits = ControlBits::empty();
1415

1516
// For the purposes of testing, we're _not_ going to implement
@@ -21,30 +22,37 @@ pub fn test(bt: &BootServices) {
2122

2223
serial
2324
.set_control_bits(ctrl_bits)
24-
.expect("Failed to set device control bits");
25+
.expect("Failed to set device control bits")
26+
.expect("Warnings encountered while setting device control bits");
2527

2628
// Keep this message short, we need it to fit in the FIFO.
27-
let output = b"Hello world!";
28-
let msg_len = output.len();
29+
const OUTPUT: &[u8] = b"Hello world!";
30+
const MSG_LEN: usize = OUTPUT.len();
2931

3032
let len = serial
31-
.write(output)
32-
.expect("Failed to write to serial port");
33-
assert_eq!(len, msg_len, "Serial port write timed-out!");
33+
.write(OUTPUT)
34+
.expect("Failed to write to serial port")
35+
.expect("Warnings encountered while writing to serial port");
36+
assert_eq!(len, MSG_LEN, "Bad serial port write length");
3437

35-
let mut input = [0u8; 128];
38+
let mut input = [0u8; MSG_LEN];
3639
let len = serial
3740
.read(&mut input)
38-
.expect("Failed to read from serial port");
39-
assert_eq!(len, msg_len, "Serial port read timed-out!");
41+
.expect("Failed to read from serial port")
42+
.expect("Warnings encountered while reading from serial port");
43+
assert_eq!(len, MSG_LEN, "Bad serial port read length");
4044

41-
assert_eq!(&output[..], &input[..msg_len]);
45+
assert_eq!(&OUTPUT[..], &input[..MSG_LEN]);
4246

4347
// Clean up after ourselves
44-
serial.reset().expect("Could not reset the serial device");
48+
serial
49+
.reset()
50+
.expect("Could not reset the serial device")
51+
.expect("Warnings encountered while resetting serial device");
4552
serial
4653
.set_control_bits(old_ctrl_bits & ControlBits::SETTABLE)
47-
.expect("Could not restore the serial device state");
54+
.expect("Could not restore the serial device state")
55+
.expect("Warnings encountered while restoring serial device state");
4856
} else {
4957
warn!("No serial device found");
5058
}

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

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,71 @@ pub fn test(stdout: &mut Output) {
1010

1111
// Print all modes.
1212
for (index, mode) in stdout.modes().enumerate() {
13+
let mode = mode.expect("Warnings encountered while querying text mode");
1314
info!(
14-
"- Graphics mode #{}: {} rows by {} columns",
15+
"- Text mode #{}: {} rows by {} columns",
1516
index,
1617
mode.rows(),
1718
mode.columns()
1819
);
1920
}
2021

2122
// Should clean up after us.
22-
stdout.reset(false).unwrap();
23+
stdout.reset(false).unwrap().unwrap();
2324
}
2425

25-
// Switch to the maximum supported graphics mode.
26+
// Switch to the maximum supported text mode.
2627
fn change_text_mode(stdout: &mut Output) {
27-
let best_mode = stdout.modes().last().unwrap();
28+
let best_mode = stdout
29+
.modes()
30+
.last()
31+
.unwrap()
32+
.expect("Warnings encountered while querying text mode");;
2833
stdout
2934
.set_mode(best_mode)
30-
.expect("Failed to change graphics mode");
35+
.expect("Failed to change text mode")
36+
.expect("Warnings encountered while changing text mode");
3137
}
3238

3339
// Set a new color, and paint the background with it.
3440
fn change_color(stdout: &mut Output) {
3541
stdout
3642
.set_color(Color::White, Color::Blue)
37-
.expect("Failed to change console color");
38-
stdout.clear().expect("Failed to clear screen");
43+
.expect("Failed to change console color")
44+
.expect("Warnings encountered while changing console color");
45+
stdout
46+
.clear()
47+
.expect("Failed to clear screen")
48+
.expect("Warnings encountered while clearing screen");
3949
}
4050

4151
// Print a text centered on screen.
4252
fn center_text(stdout: &mut Output) {
4353
// Move the cursor.
4454
// This will make this `info!` line below be (somewhat) centered.
45-
stdout.enable_cursor(true).unwrap_or_else(|s| match s {
46-
Status::UNSUPPORTED => info!("Cursor visibility control unavailable"),
47-
_ => panic!("Failed to show cursor"),
48-
});
55+
stdout
56+
.enable_cursor(true)
57+
.unwrap_or_else(|s| {
58+
match s {
59+
Status::UNSUPPORTED => info!("Cursor visibility control unavailable"),
60+
_ => panic!("Failed to show cursor"),
61+
}
62+
.into()
63+
})
64+
.expect("Warnings encountered while enabling cursor");
4965
stdout
5066
.set_cursor_position(24, 0)
51-
.expect("Failed to move cursor");
67+
.expect("Failed to move cursor")
68+
.expect("Warnings encountered while moving cursor");
5269
info!("# uefi-rs test runner");
53-
stdout.enable_cursor(false).unwrap_or_else(|s| match s {
54-
Status::UNSUPPORTED => info!("Cursor visibility control unavailable"),
55-
_ => panic!("Failed to hide cursor"),
56-
});
70+
stdout
71+
.enable_cursor(false)
72+
.unwrap_or_else(|s| {
73+
match s {
74+
Status::UNSUPPORTED => info!("Cursor visibility control unavailable"),
75+
_ => panic!("Failed to hide cursor"),
76+
}
77+
.into()
78+
})
79+
.expect("Warnings encountered while enabling cursor");
5780
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ fn find_protocol(bt: &BootServices) {
1919

2020
let handles = bt
2121
.find_handles::<SearchedProtocol>()
22-
.expect("Failed to retrieve list of handles");
22+
.expect("Failed to retrieve list of handles")
23+
.expect("Warnings encountered while retrieving list of handles");
2324
assert!(
2425
handles.len() > 1,
2526
"There should be at least one implementation of Simple Text Output (stdout)"

0 commit comments

Comments
 (0)