Skip to content

Commit ab2317f

Browse files
committed
Fix graphics tests on QEMu
1 parent f75cf20 commit ab2317f

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

src/proto/console/gop.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl GraphicsOutput {
6262
}
6363

6464
/// Returns information about available graphics modes and output devices.
65-
pub fn modes(&self) -> impl Iterator<Item = Mode> {
65+
pub fn modes<'a>(&'a self) -> impl Iterator<Item = Mode> + 'a {
6666
ModeIter {
6767
gop: self,
6868
current: 0,
@@ -71,7 +71,7 @@ impl GraphicsOutput {
7171
}
7272

7373
/// Sets the current graphics mode.
74-
pub fn set_mode(&mut self, mode: &Mode) -> Result<()> {
74+
pub fn set_mode(&mut self, mode: Mode) -> Result<()> {
7575
(self.set_mode)(self, mode.index).into()
7676
}
7777

@@ -214,13 +214,13 @@ pub struct PixelBitmask {
214214
}
215215

216216
/// Represents a graphics mode compatible with a given graphics device.
217-
pub struct Mode<'a> {
217+
pub struct Mode {
218218
index: u32,
219219
info_sz: usize,
220-
info: &'a ModeInfo,
220+
info: &'static ModeInfo,
221221
}
222222

223-
impl<'a> Mode<'a> {
223+
impl Mode {
224224
/// The size of the info structure in bytes.
225225
///
226226
/// Newer versions of the spec might add extra information, in a backwards compatible way.
@@ -285,7 +285,7 @@ struct ModeIter<'a> {
285285
}
286286

287287
impl<'a> Iterator for ModeIter<'a> {
288-
type Item = Mode<'a>;
288+
type Item = Mode;
289289

290290
fn next(&mut self) -> Option<Self::Item> {
291291
let index = self.current;

uefi-test-runner/src/main.rs

+30-17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub extern "C" fn uefi_start(_handle: Handle, st: &'static table::SystemTable) -
6464
{
6565
stdout.enable_cursor(true).expect("Failed to enable cursor");
6666
stdout.set_cursor_position(24, 0).expect("Failed to move cursor");
67+
stdout.enable_cursor(false).expect("Failed to enable cursor");
6768

6869
// This will make this `info!` line be (somewhat) centered.
6970
info!("# uefi-rs test runner");
@@ -115,25 +116,25 @@ pub extern "C" fn uefi_start(_handle: Handle, st: &'static table::SystemTable) -
115116
info!("");
116117

117118
{
118-
let mut pointer = uefi_utils::proto::find_protocol::<uefi::proto::console::pointer::Pointer>()
119-
.expect("No pointer device was found");
119+
if let Some(mut pointer) = uefi_utils::proto::find_protocol::<uefi::proto::console::pointer::Pointer>() {
120+
let pointer = unsafe { pointer.as_mut() };
120121

121-
let pointer = unsafe { pointer.as_mut() };
122+
pointer.reset(false).expect("Failed to reset pointer device");
122123

123-
pointer.reset(false).expect("Failed to reset pointer device");
124-
125-
if let Ok(state) = pointer.state() {
126-
info!("Pointer State: {:#?}", state);
124+
if let Ok(state) = pointer.state() {
125+
info!("Pointer State: {:#?}", state);
126+
} else {
127+
error!("Failed to retrieve pointer state");
128+
}
127129
} else {
128-
error!("Failed to retrieve pointer state");
130+
warn!("No pointer device found");
129131
}
130132
}
131133

132-
stdout.enable_cursor(false).unwrap();
133-
134134
info!("");
135135

136-
timeout!("Testing UEFI graphics in {} second(s)...", 5);
136+
timeout!("Testing UEFI graphics in {} second(s)...", 3);
137+
stdout.reset(false).unwrap();
137138

138139
// Draw some graphics.
139140

@@ -143,29 +144,41 @@ pub extern "C" fn uefi_start(_handle: Handle, st: &'static table::SystemTable) -
143144
if let Some(mut gop_proto) = uefi_utils::proto::find_protocol::<GraphicsOutput>() {
144145
let gop = unsafe { gop_proto.as_mut() };
145146

146-
// First, fill the screen with color.
147+
// Set a larger graphics mode.
148+
{
149+
// We know for sure QEMU has a 1024x768, mode.
150+
let mode = gop.modes()
151+
.find(|ref mode| {
152+
let info = mode.info();
153+
154+
info.resolution() == (1024, 768)
155+
})
156+
.unwrap();
157+
158+
gop.set_mode(mode).expect("Failed to set graphics mode");
159+
}
160+
161+
// Fill the screen with color.
147162
{
148163
let op = BltOp::VideoFill {
149164
// Cornflower blue.
150165
color: BltPixel::new(100, 149, 237),
151166
dest: (0, 0),
152-
dims: (32, 32),
167+
dims: (1024, 768),
153168
};
154169

155170
gop.blt(op).expect("Failed to fill screen with color");
156171
}
157172

158-
bt.stall(1_000_000);
173+
bt.stall(3_000_000);
159174
} else {
160175
warn!("UEFI Graphics Output Protocol is not supported");
161176
}
162177

163178
// TODO: also test manipulating the pixel buffer directly.
164179
}
165180

166-
info!("");
167-
168-
timeout!("Testing complete, shutting down in {} second(s)...", 5);
181+
timeout!("Testing complete, shutting down in {} second(s)...", 3);
169182

170183
let rt = st.runtime;
171184
rt.reset(table::runtime::ResetType::Shutdown, Status::Success, None);

0 commit comments

Comments
 (0)