Skip to content

media/test: add integration test for creating a directory #625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions uefi-test-runner/src/proto/media/known_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,54 @@ fn test_create_file(directory: &mut Directory) {
file.write(b"test output data").unwrap();
}

/// Test directory creation by
/// - creating a new directory
/// - creating a file in that directory
/// - accessing the new directory via a flat path and a deep path
fn test_create_directory(root_dir: &mut Directory) {
info!("Testing directory creation");

// Create a new directory.
let new_dir = root_dir
.open(
cstr16!("created_dir"),
FileMode::CreateReadWrite,
FileAttribute::DIRECTORY,
)
.expect("failed to create directory");

let mut new_dir = new_dir.into_directory().expect("Should be a directory");

// create new file in new director
let msg = "hello_world";
let file = new_dir
.open(
cstr16!("foobar"),
FileMode::CreateReadWrite,
FileAttribute::empty(),
)
.unwrap();

let mut file = file.into_regular_file().expect("Should be a file!");
file.write(msg.as_bytes()).unwrap();

// now access the new file with a deep path and read its content
let file = root_dir
.open(
cstr16!("created_dir\\foobar"),
FileMode::Read,
FileAttribute::empty(),
)
.expect("Must open created file with deep path.");
let mut file = file.into_regular_file().expect("Should be a file!");

let mut buf = vec![0; msg.len()];
let read_bytes = file.read(&mut buf).unwrap();
let read = &buf[0..read_bytes];

assert_eq!(msg.as_bytes(), read);
}

/// Get the media ID via the BlockIO protocol.
fn get_block_media_id(handle: Handle, bt: &BootServices) -> u32 {
// This cannot be opened in `EXCLUSIVE` mode, as doing so
Expand Down Expand Up @@ -339,6 +387,7 @@ pub fn test_known_disk(bt: &BootServices) {
test_delete_warning(&mut root_directory);
test_existing_file(&mut root_directory);
test_create_file(&mut root_directory);
test_create_directory(&mut root_directory);
}

test_raw_disk_io(handle, bt);
Expand Down