diff --git a/uefi-test-runner/src/boot/memory.rs b/uefi-test-runner/src/boot/memory.rs index 7429dd8b1..abec331c9 100644 --- a/uefi-test-runner/src/boot/memory.rs +++ b/uefi-test-runner/src/boot/memory.rs @@ -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"); } diff --git a/uefi-test-runner/src/proto/console/gop.rs b/uefi-test-runner/src/proto/console/gop.rs index f7b9a2ac4..e894f0aef 100644 --- a/uefi-test-runner/src/proto/console/gop.rs +++ b/uefi-test-runner/src/proto/console/gop.rs @@ -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(); + 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. - 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); } } }; diff --git a/uefi-test-runner/src/proto/console/stdout.rs b/uefi-test-runner/src/proto/console/stdout.rs index 7f4915311..779de33d1 100644 --- a/uefi-test-runner/src/proto/console/stdout.rs +++ b/uefi-test-runner/src/proto/console/stdout.rs @@ -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") + }); }

AltStyle によって変換されたページ (->オリジナル) /