-
-
Notifications
You must be signed in to change notification settings - Fork 178
Some test suite tweaks #24
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,8 @@ fn memory_map(bt: &BootServices) { | |
let first_desc = desc_iter.next().unwrap(); | ||
|
||
let phys_start = first_desc.phys_start; | ||
let page_count = first_desc.page_count; | ||
|
||
assert_eq!(phys_start, 0, "Memory does not start at address 0"); | ||
assert!(page_count != 0, "Memory map entry has zero size"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just another sanity check. The UEFI spec mandates this, and it can be used to check that we did not get a memory block full of zeroes... |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use uefi::table::boot::BootServices; | ||
use uefi::proto::console::gop::{GraphicsOutput, BltOp, BltPixel}; | ||
use uefi::proto::console::gop::{GraphicsOutput, BltOp, BltPixel, PixelFormat}; | ||
use uefi_exts::BootServicesExt; | ||
|
||
pub fn test(bt: &BootServices) { | ||
|
@@ -48,29 +48,38 @@ fn fill_color(gop: &mut GraphicsOutput) { | |
fn draw_fb(gop: &mut GraphicsOutput) { | ||
let mi = gop.current_mode_info(); | ||
let stride = mi.stride(); | ||
// BUG: we should check we have enough space to draw. | ||
// let (width, height) = mi.resolution(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
let (width, height) = mi.resolution(); | ||
|
||
let fb = unsafe { gop.frame_buffer() }; | ||
|
||
let mut set_pixel = |(row, column), (r, g, b)| { | ||
let index = (row * stride) + column; | ||
|
||
// BUG: we assume the pixel format is 32-bit BGR, as it often is on x86. | ||
// For RGB the red / blue channels will be inverted. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Simplified the functionality of set_pixel along the way to reduce code duplication between RGB and BGR. |
||
let bi = 4 * index; | ||
let gi = 4 * index + 1; | ||
let ri = 4 * index + 2; | ||
|
||
fb[bi] = b; | ||
fb[gi] = g; | ||
fb[ri] = r; | ||
type PixelWriter<'a> = &'a Fn(&mut [u8], (u8, u8, u8)); | ||
let write_pixel_rgb = |pixel: &mut [u8], (r, g, b)| { | ||
pixel[0] = r; | ||
pixel[1] = g; | ||
pixel[2] = b; | ||
}; | ||
let write_pixel_bgr = |pixel: &mut [u8], (r, g, b)| { | ||
pixel[0] = b; | ||
pixel[1] = g; | ||
pixel[2] = r; | ||
}; | ||
let write_pixel: PixelWriter = match mi.pixel_format() { | ||
PixelFormat::RGB => &write_pixel_rgb, | ||
PixelFormat::BGR => &write_pixel_bgr, | ||
_ => { | ||
info!("This pixel format is not supported by the drawing demo"); | ||
return; | ||
} | ||
}; | ||
|
||
let mut fill_rectangle = |(x1, y1), (x2, y2), color| { | ||
assert!((x1 < width) && (x2 < width), "Bad X coordinate"); | ||
assert!((y1 < height) && (y2 < height), "Bad Y coordinate"); | ||
for row in y1..y2 { | ||
for column in x1..x2 { | ||
set_pixel((row, column), color); | ||
let index = (row * stride) + column; | ||
let pixel = &mut fb[4*index..4*index+3]; | ||
write_pixel(pixel, color); | ||
} | ||
} | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
use uefi::prelude::*; | ||
use uefi::proto::console::text::{Output, Color}; | ||
|
||
pub fn test(stdout: &mut Output) { | ||
|
@@ -33,9 +34,14 @@ fn change_color(stdout: &mut Output) { | |
fn center_text(stdout: &mut Output) { | ||
// Move the cursor. | ||
// This will make this `info!` line below be (somewhat) centered. | ||
stdout.enable_cursor(true).expect("Failed to enable cursor"); | ||
stdout.enable_cursor(true).unwrap_or_else(|s| match s { | ||
Status::Unsupported => info!("Cursor visibility control unavailable"), | ||
_ => panic!("Failed to show cursor") | ||
}); | ||
stdout.set_cursor_position(24, 0).expect("Failed to move cursor"); | ||
stdout.enable_cursor(false).expect("Failed to disable cursor"); | ||
|
||
info!("# uefi-rs test runner"); | ||
stdout.enable_cursor(false).unwrap_or_else(|s| match s { | ||
Status::Unsupported => info!("Cursor visibility control unavailable"), | ||
_ => panic!("Failed to hide cursor") | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition to fixing the bug in #1, this also ensures that the new debug messages pointing out that showing and hiding the cursor is not supported will not corrupt the display. |
||
} |