-
-
Notifications
You must be signed in to change notification settings - Fork 170
Enhancement/efi shell interface #1679
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
Open
RenTrieu
wants to merge
8
commits into
rust-osdev:main
Choose a base branch
from
RenTrieu:enhancement/efi_shell_interface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
92e07bb
uefi: Implementing wrappers for EFI Shell env and cur_dir functions
RenTrieu 0f30078
uefi-test-runner: Added tests for EFI Shell env and cur_dir functions
RenTrieu 0894142
uefi: Revising EFI Shell Protocol docstrings
RenTrieu dc388f7
uefi: Splitting get_env() into two separate functions
RenTrieu f5d84a5
uefi: Revise env functions to use panicking function calls
RenTrieu 42cad4a
uefi: Changing get_envs() to return an Iterator
RenTrieu 6b35e5a
uefi: Revise comments to be more descriptive and use macros for CStr16
RenTrieu d314651
uefi: Adding unit test for EFI Shell Vars struct
RenTrieu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,13 +1,168 @@ | ||||||||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||||||||
|
||||||||
use uefi::boot; | ||||||||
use uefi::boot::ScopedProtocol; | ||||||||
use uefi::proto::shell::Shell; | ||||||||
use uefi::{boot, cstr16}; | ||||||||
use uefi_raw::Status; | ||||||||
|
||||||||
/// Test `get_env()`, `get_envs()`, and `set_env()` | ||||||||
pub fn test_env(shell: &ScopedProtocol<Shell>) { | ||||||||
/* Test retrieving list of environment variable names */ | ||||||||
let mut cur_env_vec = shell.get_envs(); | ||||||||
assert_eq!(cur_env_vec.next().unwrap(), cstr16!("path"),); | ||||||||
assert_eq!(cur_env_vec.next().unwrap(), cstr16!("nonesting"),); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
let cur_env_vec = shell.get_envs(); | ||||||||
let default_len = cur_env_vec.count(); | ||||||||
|
||||||||
/* Test setting and getting a specific environment variable */ | ||||||||
let cur_env_vec = shell.get_envs(); | ||||||||
let test_var = cstr16!("test_var"); | ||||||||
let test_val = cstr16!("test_val"); | ||||||||
assert!(shell.get_env(test_var).is_none()); | ||||||||
let status = shell.set_env(test_var, test_val, false); | ||||||||
assert_eq!(status, Status::SUCCESS); | ||||||||
let cur_env_str = shell | ||||||||
.get_env(test_var) | ||||||||
.expect("Could not get environment variable"); | ||||||||
assert_eq!(cur_env_str, test_val); | ||||||||
|
||||||||
let mut found_var = false; | ||||||||
for env_var in cur_env_vec { | ||||||||
if env_var == test_var { | ||||||||
found_var = true; | ||||||||
} | ||||||||
} | ||||||||
assert!(!found_var); | ||||||||
let cur_env_vec = shell.get_envs(); | ||||||||
let mut found_var = false; | ||||||||
for env_var in cur_env_vec { | ||||||||
if env_var == test_var { | ||||||||
found_var = true; | ||||||||
} | ||||||||
} | ||||||||
assert!(found_var); | ||||||||
|
||||||||
let cur_env_vec = shell.get_envs(); | ||||||||
assert_eq!(cur_env_vec.count(), default_len + 1); | ||||||||
|
||||||||
/* Test deleting environment variable */ | ||||||||
let test_val = cstr16!(""); | ||||||||
let status = shell.set_env(test_var, test_val, false); | ||||||||
assert_eq!(status, Status::SUCCESS); | ||||||||
assert!(shell.get_env(test_var).is_none()); | ||||||||
|
||||||||
let cur_env_vec = shell.get_envs(); | ||||||||
let mut found_var = false; | ||||||||
for env_var in cur_env_vec { | ||||||||
if env_var == test_var { | ||||||||
found_var = true; | ||||||||
} | ||||||||
} | ||||||||
assert!(!found_var); | ||||||||
let cur_env_vec = shell.get_envs(); | ||||||||
assert_eq!(cur_env_vec.count(), default_len); | ||||||||
} | ||||||||
|
||||||||
/// Test `get_cur_dir()` and `set_cur_dir()` | ||||||||
pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) { | ||||||||
/* Test setting and getting current file system and current directory */ | ||||||||
let fs_var = cstr16!("fs0:"); | ||||||||
let dir_var = cstr16!("/"); | ||||||||
let status = shell.set_cur_dir(Some(fs_var), Some(dir_var)); | ||||||||
assert_eq!(status, Status::SUCCESS); | ||||||||
|
||||||||
let cur_fs_str = shell | ||||||||
.get_cur_dir(Some(fs_var)) | ||||||||
.expect("Could not get the current file system mapping"); | ||||||||
let expected_fs_str = cstr16!("FS0:\\"); | ||||||||
assert_eq!(cur_fs_str, expected_fs_str); | ||||||||
|
||||||||
// Changing current file system | ||||||||
let fs_var = cstr16!("fs1:"); | ||||||||
let dir_var = cstr16!("/"); | ||||||||
let status = shell.set_cur_dir(Some(fs_var), Some(dir_var)); | ||||||||
assert_eq!(status, Status::SUCCESS); | ||||||||
|
||||||||
let cur_fs_str = shell | ||||||||
.get_cur_dir(Some(fs_var)) | ||||||||
.expect("Could not get the current file system mapping"); | ||||||||
assert_ne!(cur_fs_str, expected_fs_str); | ||||||||
let expected_fs_str = cstr16!("FS1:\\"); | ||||||||
assert_eq!(cur_fs_str, expected_fs_str); | ||||||||
|
||||||||
// Changing current file system and current directory | ||||||||
let fs_var = cstr16!("fs0:"); | ||||||||
let dir_var = cstr16!("efi/"); | ||||||||
let status = shell.set_cur_dir(Some(fs_var), Some(dir_var)); | ||||||||
assert_eq!(status, Status::SUCCESS); | ||||||||
|
||||||||
let cur_fs_str = shell | ||||||||
.get_cur_dir(Some(fs_var)) | ||||||||
.expect("Could not get the current file system mapping"); | ||||||||
assert_ne!(cur_fs_str, expected_fs_str); | ||||||||
let expected_fs_str = cstr16!("FS0:\\efi"); | ||||||||
assert_eq!(cur_fs_str, expected_fs_str); | ||||||||
|
||||||||
/* Test current working directory cases */ | ||||||||
|
||||||||
// At this point, the current working file system has not been set | ||||||||
// So we expect a NULL output | ||||||||
assert!(shell.get_cur_dir(None).is_none()); | ||||||||
|
||||||||
// Setting the current working file system and current working directory | ||||||||
let dir_var = cstr16!("fs0:/"); | ||||||||
let status = shell.set_cur_dir(None, Some(dir_var)); | ||||||||
assert_eq!(status, Status::SUCCESS); | ||||||||
let cur_fs_str = shell | ||||||||
.get_cur_dir(Some(fs_var)) | ||||||||
.expect("Could not get the current file system mapping"); | ||||||||
let expected_fs_str = cstr16!("FS0:"); | ||||||||
assert_eq!(cur_fs_str, expected_fs_str); | ||||||||
|
||||||||
let cur_fs_str = shell | ||||||||
.get_cur_dir(None) | ||||||||
.expect("Could not get the current file system mapping"); | ||||||||
assert_eq!(cur_fs_str, expected_fs_str); | ||||||||
|
||||||||
// Changing current working directory | ||||||||
let dir_var = cstr16!("/efi"); | ||||||||
let status = shell.set_cur_dir(None, Some(dir_var)); | ||||||||
assert_eq!(status, Status::SUCCESS); | ||||||||
let cur_fs_str = shell | ||||||||
.get_cur_dir(Some(fs_var)) | ||||||||
.expect("Could not get the current file system mapping"); | ||||||||
let expected_fs_str = cstr16!("FS0:\\efi"); | ||||||||
assert_eq!(cur_fs_str, expected_fs_str); | ||||||||
let cur_fs_str = shell | ||||||||
.get_cur_dir(None) | ||||||||
.expect("Could not get the current file system mapping"); | ||||||||
assert_eq!(cur_fs_str, expected_fs_str); | ||||||||
|
||||||||
// Changing current directory in a non-current working file system | ||||||||
let fs_var = cstr16!("fs0:"); | ||||||||
let dir_var = cstr16!("efi/tools"); | ||||||||
let status = shell.set_cur_dir(Some(fs_var), Some(dir_var)); | ||||||||
assert_eq!(status, Status::SUCCESS); | ||||||||
let cur_fs_str = shell | ||||||||
.get_cur_dir(None) | ||||||||
.expect("Could not get the current file system mapping"); | ||||||||
assert_ne!(cur_fs_str, expected_fs_str); | ||||||||
|
||||||||
let expected_fs_str = cstr16!("FS0:\\efi\\tools"); | ||||||||
let cur_fs_str = shell | ||||||||
.get_cur_dir(Some(fs_var)) | ||||||||
.expect("Could not get the current file system mapping"); | ||||||||
assert_eq!(cur_fs_str, expected_fs_str); | ||||||||
} | ||||||||
|
||||||||
pub fn test() { | ||||||||
info!("Running shell protocol tests"); | ||||||||
|
||||||||
let handle = boot::get_handle_for_protocol::<Shell>().expect("No Shell handles"); | ||||||||
|
||||||||
let mut _shell = | ||||||||
let shell = | ||||||||
boot::open_protocol_exclusive::<Shell>(handle).expect("Failed to open Shell protocol"); | ||||||||
|
||||||||
test_env(&shell); | ||||||||
test_cur_dir(&shell); | ||||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does
nonesting
come from?! Looks a little magic to meThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, it is pre-defined: https://uefi.org/sites/default/files/resources/UEFI_Shell_2_2.pdf