Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 188da95

Browse files
HadrienG2GabrielMajeri
authored andcommitted
Some test suite tweaks (#24)
This PR cleans up some tests, fixes some issues.
1 parent 035d96b commit 188da95

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

‎uefi-test-runner/src/boot/memory.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ fn memory_map(bt: &BootServices) {
8585
let first_desc = desc_iter.next().unwrap();
8686

8787
let phys_start = first_desc.phys_start;
88+
let page_count = first_desc.page_count;
8889

8990
assert_eq!(phys_start, 0, "Memory does not start at address 0");
91+
assert!(page_count != 0, "Memory map entry has zero size");
9092
}

‎uefi-test-runner/src/proto/console/gop.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use uefi::table::boot::BootServices;
2-
use uefi::proto::console::gop::{GraphicsOutput, BltOp, BltPixel};
2+
use uefi::proto::console::gop::{GraphicsOutput, BltOp, BltPixel,PixelFormat};
33
use uefi_exts::BootServicesExt;
44

55
pub fn test(bt: &BootServices) {
@@ -48,29 +48,38 @@ fn fill_color(gop: &mut GraphicsOutput) {
4848
fn draw_fb(gop: &mut GraphicsOutput) {
4949
let mi = gop.current_mode_info();
5050
let stride = mi.stride();
51-
// BUG: we should check we have enough space to draw.
52-
// let (width, height) = mi.resolution();
51+
let (width, height) = mi.resolution();
5352

5453
let fb = unsafe { gop.frame_buffer() };
5554

56-
let mut set_pixel = |(row, column), (r, g, b)| {
57-
let index = (row * stride) + column;
58-
59-
// BUG: we assume the pixel format is 32-bit BGR, as it often is on x86.
60-
// For RGB the red / blue channels will be inverted.
61-
let bi = 4 * index;
62-
let gi = 4 * index + 1;
63-
let ri = 4 * index + 2;
64-
65-
fb[bi] = b;
66-
fb[gi] = g;
67-
fb[ri] = r;
55+
type PixelWriter<'a> = &'a Fn(&mut [u8], (u8, u8, u8));
56+
let write_pixel_rgb = |pixel: &mut [u8], (r, g, b)| {
57+
pixel[0] = r;
58+
pixel[1] = g;
59+
pixel[2] = b;
60+
};
61+
let write_pixel_bgr = |pixel: &mut [u8], (r, g, b)| {
62+
pixel[0] = b;
63+
pixel[1] = g;
64+
pixel[2] = r;
65+
};
66+
let write_pixel: PixelWriter = match mi.pixel_format() {
67+
PixelFormat::RGB => &write_pixel_rgb,
68+
PixelFormat::BGR => &write_pixel_bgr,
69+
_ => {
70+
info!("This pixel format is not supported by the drawing demo");
71+
return;
72+
}
6873
};
6974

7075
let mut fill_rectangle = |(x1, y1), (x2, y2), color| {
76+
assert!((x1 < width) && (x2 < width), "Bad X coordinate");
77+
assert!((y1 < height) && (y2 < height), "Bad Y coordinate");
7178
for row in y1..y2 {
7279
for column in x1..x2 {
73-
set_pixel((row, column), color);
80+
let index = (row * stride) + column;
81+
let pixel = &mut fb[4*index..4*index+3];
82+
write_pixel(pixel, color);
7483
}
7584
}
7685
};

‎uefi-test-runner/src/proto/console/stdout.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use uefi::prelude::*;
12
use uefi::proto::console::text::{Output, Color};
23

34
pub fn test(stdout: &mut Output) {
@@ -33,9 +34,14 @@ fn change_color(stdout: &mut Output) {
3334
fn center_text(stdout: &mut Output) {
3435
// Move the cursor.
3536
// This will make this `info!` line below be (somewhat) centered.
36-
stdout.enable_cursor(true).expect("Failed to enable cursor");
37+
stdout.enable_cursor(true).unwrap_or_else(|s| match s {
38+
Status::Unsupported => info!("Cursor visibility control unavailable"),
39+
_ => panic!("Failed to show cursor")
40+
});
3741
stdout.set_cursor_position(24, 0).expect("Failed to move cursor");
38-
stdout.enable_cursor(false).expect("Failed to disable cursor");
39-
4042
info!("# uefi-rs test runner");
43+
stdout.enable_cursor(false).unwrap_or_else(|s| match s {
44+
Status::Unsupported => info!("Cursor visibility control unavailable"),
45+
_ => panic!("Failed to hide cursor")
46+
});
4147
}

0 commit comments

Comments
(0)

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