Skip to content

Commit f5217cf

Browse files
committed
uefi-test-runner: test new protocol helpers on Handle
1 parent bdd8dbd commit f5217cf

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

uefi-test-runner/src/proto/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22

33
use uefi::boot::{self, OpenProtocolParams};
4+
use uefi::proto::device_path::DevicePath;
5+
use uefi::proto::driver::ComponentName2;
46
use uefi::proto::loaded_image::LoadedImage;
57
use uefi::{Identify, proto};
68

@@ -44,6 +46,9 @@ pub fn test() {
4446
shim::test();
4547
shell::test();
4648
tcg::test();
49+
50+
// now test some convenience that combines several things
51+
test_handle_convenience();
4752
}
4853

4954
fn find_protocol() {
@@ -74,6 +79,32 @@ fn test_test_protocol() {
7479
);
7580
}
7681

82+
fn test_handle_convenience() {
83+
// Handles that implement the following protocols:
84+
// - component name 2
85+
// - device path
86+
let handles = {
87+
let mut cn2_handles = boot::find_handles::<ComponentName2>().unwrap();
88+
let dvp_handles = boot::find_handles::<DevicePath>().unwrap();
89+
90+
cn2_handles.retain(|x| dvp_handles.contains(x));
91+
cn2_handles
92+
};
93+
for handle in handles {
94+
let dvp = handle.device_path().expect("should have device path");
95+
let cn2 = handle
96+
.component_name()
97+
.expect("should have component name (v2)");
98+
info!("handle: {:x?}", handle);
99+
info!("|- dvp: {dvp}");
100+
info!("|- cn2 driver: {}", cn2.driver_name("en").unwrap());
101+
info!(
102+
"|- cn2 controller: {}",
103+
cn2.controller_name(handle, None, "en").unwrap()
104+
);
105+
}
106+
}
107+
77108
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
78109
mod ata;
79110
mod console;

uefi-test-runner/src/proto/network/http.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,12 @@
22

33
use alloc::vec::Vec;
44

5-
use uefi::proto::device_path::DevicePath;
6-
use uefi::proto::device_path::text::{AllowShortcuts, DisplayOnly};
75
use uefi::proto::network::http::{HttpBinding, HttpHelper};
86
use uefi::proto::network::ip4config2::Ip4Config2;
97
use uefi::{Handle, boot};
108

119
use uefi_raw::protocol::network::http::HttpStatusCode;
1210

13-
pub fn print_handle_devpath(prefix: &str, handle: &Handle) {
14-
let Ok(dp) = boot::open_protocol_exclusive::<DevicePath>(*handle) else {
15-
info!("{prefix}no device path for handle");
16-
return;
17-
};
18-
if let Ok(string) = dp.to_string16(DisplayOnly(true), AllowShortcuts(true)) {
19-
info!("{prefix}{string}");
20-
}
21-
}
22-
2311
fn fetch_http(handle: Handle, url: &str) -> Option<Vec<u8>> {
2412
info!("http: fetching {url} ...");
2513

@@ -91,7 +79,7 @@ pub fn test() {
9179
.expect("get nic handles");
9280

9381
for h in handles.as_ref() {
94-
print_handle_devpath("nic: ", h);
82+
info!("nic: {}", h.device_path().expect("should have device path"));
9583

9684
info!("Bring up interface (ip4 config2 protocol)");
9785
let mut ip4 = Ip4Config2::new(*h).expect("open ip4 config2 protocol");

uefi-test-runner/src/proto/nvme/pass_thru.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
use core::time::Duration;
44
use uefi::boot;
5-
use uefi::proto::device_path::DevicePath;
6-
use uefi::proto::device_path::text::{AllowShortcuts, DisplayOnly};
75
use uefi::proto::media::block::BlockIO;
86
use uefi::proto::nvme::pass_thru::NvmePassThru;
97
use uefi::proto::nvme::{NvmeQueueType, NvmeRequestBuilder};
@@ -17,19 +15,14 @@ pub fn test() {
1715
fn has_nvme_drive() -> bool {
1816
let block_io_handles = boot::find_handles::<BlockIO>().unwrap();
1917
for handle in block_io_handles {
20-
let Ok(device_path) = boot::open_protocol_exclusive::<DevicePath>(handle) else {
21-
continue;
22-
};
23-
let mut device_path = &*device_path;
18+
let device_path_proto = handle.device_path().expect("should have device path");
19+
let mut device_path = &*device_path_proto;
2420

2521
let Ok(nvme_pt_handle) = boot::locate_device_path::<NvmePassThru>(&mut device_path) else {
2622
continue;
2723
};
2824
let nvme_pt = boot::open_protocol_exclusive::<NvmePassThru>(nvme_pt_handle).unwrap();
29-
let device_path_str = device_path
30-
.to_string16(DisplayOnly(true), AllowShortcuts(false))
31-
.unwrap();
32-
info!("- Successfully opened NVMe: {device_path_str}");
25+
info!("- Successfully opened NVMe: {device_path_proto}");
3326
let mut nvme_ctrl = nvme_pt.controller();
3427

3528
let request = NvmeRequestBuilder::new(nvme_pt.io_align(), 0x06, NvmeQueueType::ADMIN)

0 commit comments

Comments
 (0)