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 16e3360

Browse files
committed
uefi-fs: add integration test
1 parent 2b8e5e2 commit 16e3360

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

‎uefi-test-runner/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition = "2021"
99
# TODO we should let the uefi-test-runner run with and without unstable.
1010
uefi = { path = "../uefi", features = ["alloc", "unstable"] }
1111
uefi-services = { path = "../uefi-services" }
12+
uefi-fs = { path = "../uefi-fs" }
1213

1314
log = { version = "0.4.17", default-features = false }
1415

‎uefi-test-runner/src/fs/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use alloc::string::{String, ToString};
2+
use alloc::vec::Vec;
3+
use uefi::prelude::*;
4+
5+
use uefi::proto::loaded_image::LoadedImage;
6+
use uefi::proto::media::file::{Directory, File, FileAttribute, FileMode, FileSystemInfo};
7+
use uefi::proto::media::fs::SimpleFileSystem;
8+
use uefi::table::boot::ScopedProtocol;
9+
use uefi::{proto, Identify};
10+
use uefi_fs::{FileSystem, FileSystemError};
11+
12+
/// Tests functionality from the `uefi-fs` crate.
13+
pub fn test(sfs: ScopedProtocol<SimpleFileSystem>) {
14+
let mut fs = FileSystem::new(sfs);
15+
16+
fs.create_dir("test_file_system_abs").unwrap();
17+
18+
// slash is transparently transformed to backslash
19+
fs.write("test_file_system_abs/foo", "hello").unwrap();
20+
// absolute or relative paths are supported; ./ is ignored
21+
fs.copy("\\test_file_system_abs/foo", "\\test_file_system_abs/./bar").unwrap();
22+
let read = fs.read("\\test_file_system_abs\\bar").unwrap();
23+
let read = String::from_utf8(read).unwrap();
24+
assert_eq!(read, "hello");
25+
26+
assert_eq!(
27+
fs.try_exists("test_file_system_abs\\barfoo"),
28+
Err(FileSystemError::OpenError("\\test_file_system_abs\\barfoo".to_string()))
29+
);
30+
fs.rename("test_file_system_abs\\bar", "test_file_system_abs\\barfoo").unwrap();
31+
assert!(fs.try_exists("test_file_system_abs\\barfoo").is_ok());
32+
33+
let entries = fs.read_dir("test_file_system_abs").unwrap()
34+
.map(|e| e.unwrap().file_name().to_string())
35+
.collect::<Vec<_>>();
36+
assert_eq!(&[".", "..", "foo", "barfoo"], entries.as_slice());
37+
}

‎uefi-test-runner/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ extern crate log;
88
extern crate alloc;
99

1010
use alloc::string::ToString;
11+
use core::ptr::hash;
1112
use uefi::prelude::*;
1213
use uefi::proto::console::serial::Serial;
1314
use uefi::Result;
1415
use uefi_services::{print, println};
1516

1617
mod boot;
18+
mod fs;
1719
mod proto;
1820
mod runtime;
1921

‎uefi-test-runner/src/proto/media/known_disk.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ pub fn test_known_disk(bt: &BootServices) {
339339
test_delete_warning(&mut root_directory);
340340
test_existing_file(&mut root_directory);
341341
test_create_file(&mut root_directory);
342+
343+
crate::fs::test(sfs)
342344
}
343345

344346
test_raw_disk_io(handle, bt);

0 commit comments

Comments
(0)

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