Skip to content

Commit 83ade2e

Browse files
committed
integration test for existing simple file system code
1 parent b9fde3d commit 83ade2e

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
mod known_disk;
22

33
use uefi::prelude::*;
4-
use uefi::proto::media::file::{Directory, File, FileSystemInfo, FileSystemVolumeLabel};
4+
use uefi::proto::media::file::{
5+
Directory, File, FileAttribute, FileMode, FileSystemInfo, FileSystemVolumeLabel, FileType,
6+
};
57
use uefi::proto::media::fs::SimpleFileSystem;
68
use uefi::proto::media::partition::PartitionInfo;
9+
use uefi::table::boot::{OpenProtocolAttributes, OpenProtocolParams};
10+
use uefi::CString16;
711

812
/// Test `FileSystemInfo` and `FileSystemVolumeLabel`.
913
fn test_file_system_info(directory: &mut Directory) {
@@ -23,18 +27,18 @@ fn test_file_system_info(directory: &mut Directory) {
2327
assert_eq!(fs_info.volume_label(), fs_vol.volume_label());
2428
}
2529

26-
pub fn test(bt: &BootServices) {
27-
info!("Testing Media Access protocols");
30+
pub fn test_simple_file_system_protocol(image: Handle, bt: &BootServices) {
31+
info!("Testing Simple File System Protocol");
2832

2933
if let Ok(handle) = bt.get_handle_for_protocol::<SimpleFileSystem>() {
3034
let mut sfs = bt
3135
.open_protocol_exclusive::<SimpleFileSystem>(handle)
3236
.expect("failed to open SimpleFileSystem protocol");
3337

34-
let mut directory = sfs.open_volume().unwrap();
38+
let mut root_directory = sfs.open_volume().unwrap();
3539
let mut buffer = vec![0; 128];
3640
loop {
37-
let file_info = match directory.read_entry(&mut buffer) {
41+
let file_info = match root_directory.read_entry(&mut buffer) {
3842
Ok(info) => {
3943
if let Some(info) = info {
4044
info
@@ -52,12 +56,35 @@ pub fn test(bt: &BootServices) {
5256
};
5357
info!("Root directory entry: {:?}", file_info);
5458
}
55-
directory.reset_entry_readout().unwrap();
59+
root_directory.reset_entry_readout().unwrap();
5660

57-
test_file_system_info(&mut directory);
61+
test_file_system_info(&mut root_directory);
62+
63+
assert_eq!(Ok(true), root_directory.is_directory());
64+
assert_eq!(Ok(false), root_directory.is_regular_file());
65+
66+
info!("creating file in root volume");
67+
let created_file = root_directory
68+
.open(
69+
CString16::try_from("foo").unwrap().as_ref(),
70+
FileMode::CreateReadWrite,
71+
FileAttribute::empty(),
72+
)
73+
.unwrap();
74+
assert_eq!(Ok(true), created_file.is_regular_file());
75+
let created_file = match created_file.into_type().unwrap() {
76+
FileType::Regular(file) => file,
77+
_ => panic!("unsupported value"),
78+
};
79+
assert_eq!(Ok(true), created_file.is_regular_file());
80+
assert_eq!(Ok(false), created_file.is_directory());
5881
} else {
5982
warn!("`SimpleFileSystem` protocol is not available");
6083
}
84+
}
85+
86+
pub fn test_partition_info_protocol(image: Handle, bt: &BootServices) {
87+
info!("Testing Partition Info protocols");
6188

6289
let handles = bt
6390
.find_handles::<PartitionInfo>()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub fn test(image: Handle, st: &mut SystemTable<Boot>) {
1919
network::test(bt);
2020
pi::test(bt);
2121
rng::test(bt);
22+
media::test_simple_file_system_protocol(image, bt);
23+
media::test_partition_info_protocol(image, bt);
2224

2325
#[cfg(any(
2426
target_arch = "i386",

0 commit comments

Comments
 (0)