From 1b660d76d712372b4deeadfb8ca260c144ab4bb1 Mon Sep 17 00:00:00 2001 From: Hadrien G Date: 2018年9月21日 22:35:46 +0200 Subject: [PATCH 1/5] Some test suite cleanup --- uefi-test-runner/src/boot/memory.rs | 2 + uefi-test-runner/src/proto/console/gop.rs | 44 ++++++++++++-------- uefi-test-runner/src/proto/console/stdout.rs | 11 ++++- 3 files changed, 38 insertions(+), 19 deletions(-) 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..07af49875 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,33 +48,43 @@ 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; + type PixelWriter = fn(&mut [u8], &[u8; 3]); + fn write_pixel_rgb(pixel: &mut [u8], rgb: &[u8; 3]) { + pixel[0] = rgb[0]; + pixel[1] = rgb[1]; + pixel[2] = rgb[2]; + } + fn write_pixel_bgr(pixel: &mut [u8], rgb: &[u8; 3]) { + pixel[0] = rgb[2]; + pixel[1] = rgb[1]; + pixel[2] = rgb[0]; + } - fb[bi] = b; - fb[gi] = g; - fb[ri] = 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); } } }; - fill_rectangle((50, 30), (150, 600), (250, 128, 64)); - fill_rectangle((400, 120), (750, 450), (16, 128, 255)); + fill_rectangle((50, 30), (150, 600), [250, 128, 64]); + fill_rectangle((400, 120), (750, 450), [16, 128, 255]); } diff --git a/uefi-test-runner/src/proto/console/stdout.rs b/uefi-test-runner/src/proto/console/stdout.rs index 7f4915311..76ac051fc 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,15 @@ 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.set_cursor_position(24, 0).expect("Failed to move cursor"); - stdout.enable_cursor(false).expect("Failed to disable cursor"); + stdout.enable_cursor(true).unwrap_or_else(|s| match s { + Status::Unsupported => info!("Cursor visibility control unavailable"), + _ => panic!("Failed to enable 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 enable cursor") + }); } From 86b7c488b992d6e4619bfba080810d635f367c9e Mon Sep 17 00:00:00 2001 From: Hadrien G Date: 2018年9月21日 22:38:50 +0200 Subject: [PATCH 2/5] Use more specific language in test failures --- uefi-test-runner/src/proto/console/stdout.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uefi-test-runner/src/proto/console/stdout.rs b/uefi-test-runner/src/proto/console/stdout.rs index 76ac051fc..7b3895056 100644 --- a/uefi-test-runner/src/proto/console/stdout.rs +++ b/uefi-test-runner/src/proto/console/stdout.rs @@ -38,11 +38,11 @@ fn center_text(stdout: &mut Output) { stdout.enable_cursor(true).unwrap_or_else(|s| match s { Status::Unsupported => info!("Cursor visibility control unavailable"), - _ => panic!("Failed to enable cursor") + _ => panic!("Failed to show 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 enable cursor") + _ => panic!("Failed to hide cursor") }); } From 1ecb2eed0695506f0bd9c9d6f3e0989965774ff3 Mon Sep 17 00:00:00 2001 From: Hadrien G Date: 2018年9月21日 22:46:00 +0200 Subject: [PATCH 3/5] wClean up the framebuffer example --- uefi-test-runner/src/proto/console/gop.rs | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/uefi-test-runner/src/proto/console/gop.rs b/uefi-test-runner/src/proto/console/gop.rs index 07af49875..23388345b 100644 --- a/uefi-test-runner/src/proto/console/gop.rs +++ b/uefi-test-runner/src/proto/console/gop.rs @@ -52,21 +52,21 @@ fn draw_fb(gop: &mut GraphicsOutput) { let fb = unsafe { gop.frame_buffer() }; - type PixelWriter = fn(&mut [u8], &[u8; 3]); - fn write_pixel_rgb(pixel: &mut [u8], rgb: &[u8; 3]) { - pixel[0] = rgb[0]; - pixel[1] = rgb[1]; - pixel[2] = rgb[2]; - } - fn write_pixel_bgr(pixel: &mut [u8], rgb: &[u8; 3]) { - pixel[0] = rgb[2]; - pixel[1] = rgb[1]; - pixel[2] = rgb[0]; - } + 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, + PixelFormat::RGB => &write_pixel_rgb, + PixelFormat::BGR => &write_pixel_bgr, _ => { info!("This pixel format is not supported by the drawing demo"); return; @@ -80,11 +80,11 @@ fn draw_fb(gop: &mut GraphicsOutput) { for column in x1..x2 { let index = (row * stride) + column; let pixel = &mut fb[4*index..4*index+3]; - write_pixel(pixel, &color); + write_pixel(pixel, color); } } }; - fill_rectangle((50, 30), (150, 600), [250, 128, 64]); - fill_rectangle((400, 120), (750, 450), [16, 128, 255]); + fill_rectangle((50, 30), (150, 600), (250, 128, 64)); + fill_rectangle((400, 120), (750, 450), (16, 128, 255)); } From fc23598a28264a365c558d0466829ecb0f004cfe Mon Sep 17 00:00:00 2001 From: Hadrien G Date: 2018年9月21日 22:51:22 +0200 Subject: [PATCH 4/5] Spacing tweak --- uefi-test-runner/src/proto/console/gop.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/uefi-test-runner/src/proto/console/gop.rs b/uefi-test-runner/src/proto/console/gop.rs index 23388345b..e894f0aef 100644 --- a/uefi-test-runner/src/proto/console/gop.rs +++ b/uefi-test-runner/src/proto/console/gop.rs @@ -63,7 +63,6 @@ fn draw_fb(gop: &mut GraphicsOutput) { pixel[1] = g; pixel[2] = r; }; - let write_pixel: PixelWriter = match mi.pixel_format() { PixelFormat::RGB => &write_pixel_rgb, PixelFormat::BGR => &write_pixel_bgr, From c1103b3fae08389f045cd3abc9d2d13f98f3a019 Mon Sep 17 00:00:00 2001 From: Hadrien G Date: 2018年9月21日 22:52:05 +0200 Subject: [PATCH 5/5] Avoid further corruption --- uefi-test-runner/src/proto/console/stdout.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/uefi-test-runner/src/proto/console/stdout.rs b/uefi-test-runner/src/proto/console/stdout.rs index 7b3895056..779de33d1 100644 --- a/uefi-test-runner/src/proto/console/stdout.rs +++ b/uefi-test-runner/src/proto/console/stdout.rs @@ -34,12 +34,11 @@ 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.set_cursor_position(24, 0).expect("Failed to move 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"); info!("# uefi-rs test runner"); stdout.enable_cursor(false).unwrap_or_else(|s| match s { Status::Unsupported => info!("Cursor visibility control unavailable"),

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