Skip to content

Commit 3eb1e7a

Browse files
committed
Refactor tests
1 parent 74590fe commit 3eb1e7a

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

tests/src/main.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,46 @@ use uefi::{Handle, Status};
2222
use uefi::table;
2323

2424
#[no_mangle]
25-
pub extern "C" fn uefi_start(handle: Handle, st: &'static table::SystemTable) -> Status {
25+
pub extern "C" fn uefi_start(_handle: Handle, st: &'static table::SystemTable) -> Status {
2626
uefi_services::init(st);
2727

2828
let stdout = st.stdout();
29-
stdout.reset(false).unwrap();
29+
stdout.reset(false).expect("Failed to reset stdout");
3030

3131
// Switch to the maximum supported graphics mode.
3232
let best_mode = stdout.modes().last().unwrap();
33-
stdout.set_mode(best_mode).unwrap();
33+
stdout.set_mode(best_mode).expect("Failed to change graphics mode");
3434

3535
info!("# uefi-rs test runner");
36-
info!("Image handle: {:?}", handle);
3736

38-
// Test the memory allocator.
3937
{
40-
let mut values = vec![-5, 16, 23, 4, 0];
38+
let revision = st.uefi_revision();
39+
let (major, minor) = (revision.major(), revision.minor());
4140

42-
values.sort();
41+
info!("UEFI {}.{}.{}", major, minor / 10, minor % 10);
42+
}
4343

44-
info!("Sorted vector: {:?}", values);
44+
info!("");
45+
46+
// Print all modes.
47+
for (index, mode) in stdout.modes().enumerate() {
48+
info!("Graphics mode #{}: {} rows by {} columns", index, mode.rows(), mode.columns());
4549
}
4650

51+
info!("");
52+
4753
{
48-
let revision = st.uefi_revision();
49-
let (major, minor) = (revision.major(), revision.minor());
54+
info!("Memory Allocation Test");
5055

51-
info!("UEFI {}.{}.{}", major, minor / 10, minor % 10);
56+
let mut values = vec![-5, 16, 23, 4, 0];
57+
58+
values.sort();
59+
60+
info!("Sorted vector: {:?}", values);
5261
}
5362

63+
info!("");
64+
5465
let bt = st.boot;
5566

5667
match boot::boot_services_test(bt) {
@@ -64,11 +75,28 @@ pub extern "C" fn uefi_start(handle: Handle, st: &'static table::SystemTable) ->
6475
}
6576

6677
match ucs2::ucs2_encoding_test() {
67-
Ok(_) => info!("UCS-2 encoding test passed"),
78+
Ok(_) => info!("UCS-2 encoding test passed."),
6879
Err(status) => error!("UCS-2 encoding test failed with status {:?}", status),
6980
}
7081

71-
bt.stall(4_000_000);
82+
info!("");
83+
84+
{
85+
let mut pointer = uefi_utils::proto::find_protocol::<uefi::proto::console::pointer::Pointer>()
86+
.expect("No pointer device was found");
87+
88+
let pointer = unsafe { pointer.as_mut() };
89+
90+
pointer.reset(false).expect("Failed to reset pointer device");
91+
92+
if let Ok(state) = pointer.state() {
93+
info!("Pointer State: {:#?}", state);
94+
} else {
95+
error!("Failed to retrieve pointer state");
96+
}
97+
}
98+
99+
bt.stall(10_000_000);
72100

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

tests/src/proto.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@ use uefi::proto;
55
use uefi_utils;
66

77
pub fn protocol_test(_bt: &boot::BootServices) -> Result<()> {
8-
type SearchedProtocol = proto::console::text::Output;
8+
{
9+
info!("UEFI Protocol Searching test");
910

10-
let handles = uefi_utils::proto::find_handles::<SearchedProtocol>()
11-
.expect("Failed to retrieve the list of handles");
11+
type SearchedProtocol = proto::console::text::Output;
1212

13-
info!("Number of handles which implement the SimpleTextOutput protocol: {}", handles.len());
13+
let handles = uefi_utils::proto::find_handles::<SearchedProtocol>()
14+
.expect("Failed to retrieve the list of handles");
1415

15-
let mut debug_support_proto = uefi_utils::proto::find_protocol::<proto::debug::DebugSupport>()
16-
.expect("UEFI debug protocol is not implemented");
16+
info!("- Number of handles which implement the SimpleTextOutput protocol: {}", handles.len());
17+
}
1718

18-
let debug_support = unsafe { debug_support_proto.as_mut() };
19+
info!("");
1920

20-
info!("{:#?}", debug_support.arch());
21+
{
22+
info!("Debug Support Protocol");
23+
24+
let mut debug_support_proto = uefi_utils::proto::find_protocol::<proto::debug::DebugSupport>()
25+
.expect("UEFI debug protocol is not implemented");
26+
27+
let debug_support = unsafe { debug_support_proto.as_mut() };
28+
29+
info!("- Architecture: {:?}", debug_support.arch());
30+
}
31+
32+
info!("");
2133

2234
Ok(())
2335
}

0 commit comments

Comments
 (0)