Skip to content

Commit 4c4555c

Browse files
authored
Merge pull request #579 from nicholasbishop/bishop-runner-just-qemu-4
uefi-test-runner: Assume that we're running in the special QEMU env
2 parents f6cfd48 + 8e673f9 commit 4c4555c

File tree

6 files changed

+67
-78
lines changed

6 files changed

+67
-78
lines changed

uefi-test-runner/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ qemu-exit = "3.0.0"
1717
# This feature should only be enabled in our CI, it disables some tests
1818
# which currently fail in that environment (see #103 for discussion).
1919
ci = []
20-
qemu = ["uefi-services/qemu"]
20+

uefi-test-runner/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
# Running the tests
1+
# uefi-test-runner
22

3-
This file documents the process of building and running the test suite.
3+
This package is a UEFI application for running tests. It is intended to
4+
be run in a specially-configured QEMU VM. This allows us to test the
5+
parts of the `uefi` package that depend on a UEFI environment, such as
6+
various boot services and protocols.
47

58
## Prerequisites
69

uefi-test-runner/src/main.rs

Lines changed: 60 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern crate log;
88
#[macro_use]
99
extern crate alloc;
1010

11-
use alloc::string::String;
11+
use alloc::string::ToString;
1212
use uefi::prelude::*;
1313
use uefi::proto::console::serial::Serial;
1414
use uefi_services::{print, println};
@@ -24,10 +24,9 @@ fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
2424

2525
// unit tests here
2626

27-
// output firmware-vendor (CStr16 to Rust string)
28-
let mut buf = String::new();
29-
st.firmware_vendor().as_str_in_buf(&mut buf).unwrap();
30-
info!("Firmware Vendor: {}", buf.as_str());
27+
let firmware_vendor = st.firmware_vendor();
28+
info!("Firmware Vendor: {}", firmware_vendor);
29+
assert_eq!(firmware_vendor.to_string(), "EDK II");
3130

3231
// Test print! and println! macros.
3332
let (print, println) = ("print!", "println!"); // necessary for clippy to ignore
@@ -82,64 +81,51 @@ fn check_revision(rev: uefi::table::Revision) {
8281
/// of it, we just pause the tests for a couple of seconds to allow visual
8382
/// inspection of the output.
8483
fn check_screenshot(bt: &BootServices, name: &str) {
85-
if cfg!(feature = "qemu") {
86-
let serial_handles = bt
87-
.find_handles::<Serial>()
88-
.expect("Failed to get serial handles");
89-
90-
// Use the second serial device handle. Opening a serial device
91-
// in exclusive mode breaks the connection between stdout and
92-
// the serial device, and we don't want that to happen to the
93-
// first serial device since it's used for log transport.
94-
let serial_handle = *serial_handles
95-
.get(1)
96-
.expect("Second serial device is missing");
97-
98-
let mut serial = bt
99-
.open_protocol_exclusive::<Serial>(serial_handle)
100-
.expect("Could not open serial protocol");
101-
102-
// Set a large timeout to avoid problems with CI
103-
let mut io_mode = *serial.io_mode();
104-
io_mode.timeout = 10_000_000;
105-
serial
106-
.set_attributes(&io_mode)
107-
.expect("Failed to configure serial port timeout");
108-
109-
// Send a screenshot request to the host
110-
serial
111-
.write(b"SCREENSHOT: ")
112-
.expect("Failed to send request");
113-
let name_bytes = name.as_bytes();
114-
serial.write(name_bytes).expect("Failed to send request");
115-
serial.write(b"\n").expect("Failed to send request");
116-
117-
// Wait for the host's acknowledgement before moving forward
118-
let mut reply = [0; 3];
119-
serial
120-
.read(&mut reply[..])
121-
.expect("Failed to read host reply");
122-
123-
assert_eq!(&reply[..], b"OK\n", "Unexpected screenshot request reply");
124-
} else {
125-
// Outside of QEMU, give the user some time to inspect the output
126-
bt.stall(3_000_000);
127-
}
84+
let serial_handles = bt
85+
.find_handles::<Serial>()
86+
.expect("Failed to get serial handles");
87+
88+
// Use the second serial device handle. Opening a serial device
89+
// in exclusive mode breaks the connection between stdout and
90+
// the serial device, and we don't want that to happen to the
91+
// first serial device since it's used for log transport.
92+
let serial_handle = *serial_handles
93+
.get(1)
94+
.expect("Second serial device is missing");
95+
96+
let mut serial = bt
97+
.open_protocol_exclusive::<Serial>(serial_handle)
98+
.expect("Could not open serial protocol");
99+
100+
// Set a large timeout to avoid problems with CI
101+
let mut io_mode = *serial.io_mode();
102+
io_mode.timeout = 10_000_000;
103+
serial
104+
.set_attributes(&io_mode)
105+
.expect("Failed to configure serial port timeout");
106+
107+
// Send a screenshot request to the host
108+
serial
109+
.write(b"SCREENSHOT: ")
110+
.expect("Failed to send request");
111+
let name_bytes = name.as_bytes();
112+
serial.write(name_bytes).expect("Failed to send request");
113+
serial.write(b"\n").expect("Failed to send request");
114+
115+
// Wait for the host's acknowledgement before moving forward
116+
let mut reply = [0; 3];
117+
serial
118+
.read(&mut reply[..])
119+
.expect("Failed to read host reply");
120+
121+
assert_eq!(&reply[..], b"OK\n", "Unexpected screenshot request reply");
128122
}
129123

130124
fn shutdown(image: uefi::Handle, mut st: SystemTable<Boot>) -> ! {
131-
use uefi::table::runtime::ResetType;
132-
133125
// Get our text output back.
134126
st.stdout().reset(false).unwrap();
135127

136-
// Inform the user, and give him time to read on real hardware
137-
if cfg!(not(feature = "qemu")) {
138-
info!("Testing complete, shutting down in 3 seconds...");
139-
st.boot_services().stall(3_000_000);
140-
} else {
141-
info!("Testing complete, shutting down...");
142-
}
128+
info!("Testing complete, shutting down...");
143129

144130
// Exit boot services as a proof that it works :)
145131
let sizes = st.boot_services().memory_map_size();
@@ -151,15 +137,23 @@ fn shutdown(image: uefi::Handle, mut st: SystemTable<Boot>) -> ! {
151137

152138
#[cfg(target_arch = "x86_64")]
153139
{
154-
if cfg!(feature = "qemu") {
155-
use qemu_exit::QEMUExit;
156-
let custom_exit_success = 3;
157-
let qemu_exit_handle = qemu_exit::X86::new(0xF4, custom_exit_success);
158-
qemu_exit_handle.exit_success();
159-
}
140+
// Prevent unused variable warning.
141+
let _ = st;
142+
143+
use qemu_exit::QEMUExit;
144+
let custom_exit_success = 3;
145+
let qemu_exit_handle = qemu_exit::X86::new(0xF4, custom_exit_success);
146+
qemu_exit_handle.exit_success();
160147
}
161148

162-
// Shut down the system
163-
let rt = unsafe { st.runtime_services() };
164-
rt.reset(ResetType::Shutdown, Status::SUCCESS, None);
149+
#[cfg(not(target_arch = "x86_64"))]
150+
{
151+
// Shut down the system
152+
let rt = unsafe { st.runtime_services() };
153+
rt.reset(
154+
uefi::table::runtime::ResetType::Shutdown,
155+
Status::SUCCESS,
156+
None,
157+
);
158+
}
165159
}

uefi-test-runner/src/proto/media/known_disk.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,6 @@ fn test_raw_disk_io2(handle: Handle, bt: &BootServices) {
248248
/// Run various file-system related tests on a special test disk. The disk is created by
249249
/// `xtask/src/disk.rs`.
250250
pub fn test_known_disk(bt: &BootServices) {
251-
// This test is only valid when running in the specially-prepared
252-
// qemu with the test disk.
253-
if !cfg!(feature = "qemu") {
254-
return;
255-
}
256-
257251
let handles = bt
258252
.find_handles::<SimpleFileSystem>()
259253
.expect("Failed to get handles for `SimpleFileSystem` protocol");

xtask/src/cargo.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ pub enum Feature {
5050
Logger,
5151

5252
Ci,
53-
Qemu,
5453
}
5554

5655
impl Feature {
@@ -61,7 +60,6 @@ impl Feature {
6160
Self::Logger => "logger",
6261

6362
Self::Ci => "uefi-test-runner/ci",
64-
Self::Qemu => "uefi-test-runner/qemu",
6563
}
6664
}
6765

xtask/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn run_miri() -> Result<()> {
8686

8787
/// Build uefi-test-runner and run it in QEMU.
8888
fn run_vm_tests(opt: &QemuOpt) -> Result<()> {
89-
let mut features = vec![Feature::Qemu];
89+
let mut features = vec![];
9090

9191
// Always enable the ci feature when not building on Linux so that
9292
// the MP test is skipped. That test doesn't work with kvm disabled

0 commit comments

Comments
 (0)