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 e0bebaf

Browse files
committed
uefi-test-runner: Added tests for EFI Shell env functions
This commit includes tests for the following EFI Shell Protocol functions: get_env() and set_env()
1 parent fe6727f commit e0bebaf

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

‎uefi-test-runner/src/proto/shell.rs‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22

3-
use uefi::boot;
3+
use uefi::boot::ScopedProtocol;
44
use uefi::proto::shell::Shell;
5+
use uefi::{CStr16, boot};
6+
use uefi_raw::Status;
7+
8+
/// Test ``get_env()`` and ``set_env()``
9+
pub fn test_env(shell: &ScopedProtocol<Shell>) {
10+
let mut test_buf = [0u16; 128];
11+
12+
/* Test retrieving list of environment variable names (null input) */
13+
let cur_env_vec = shell
14+
.get_env(None)
15+
.expect("Could not get environment variable");
16+
assert_eq!(
17+
*cur_env_vec.first().unwrap(),
18+
CStr16::from_str_with_buf("path", &mut test_buf).unwrap()
19+
);
20+
assert_eq!(
21+
*cur_env_vec.get(1).unwrap(),
22+
CStr16::from_str_with_buf("nonesting", &mut test_buf).unwrap()
23+
);
24+
25+
/* Test setting and getting a specific environment variable */
26+
let mut test_env_buf = [0u16; 32];
27+
let test_var = CStr16::from_str_with_buf("test_var", &mut test_env_buf).unwrap();
28+
let mut test_val_buf = [0u16; 32];
29+
let test_val = CStr16::from_str_with_buf("test_val", &mut test_val_buf).unwrap();
30+
assert!(shell.get_env(Some(test_var)).is_none());
31+
let status = shell.set_env(test_var, test_val, false);
32+
assert_eq!(status, Status::SUCCESS);
33+
let cur_env_str = *shell
34+
.get_env(Some(test_var))
35+
.expect("Could not get environment variable")
36+
.first()
37+
.unwrap();
38+
assert_eq!(cur_env_str, test_val);
39+
40+
/* Test deleting environment variable */
41+
let test_val = CStr16::from_str_with_buf("", &mut test_val_buf).unwrap();
42+
let status = shell.set_env(test_var, test_val, false);
43+
assert_eq!(status, Status::SUCCESS);
44+
assert!(shell.get_env(Some(test_var)).is_none());
45+
}
546

647
pub fn test() {
748
info!("Running shell protocol tests");
849

950
let handle = boot::get_handle_for_protocol::<Shell>().expect("No Shell handles");
1051

11-
let mut _shell =
52+
let shell =
1253
boot::open_protocol_exclusive::<Shell>(handle).expect("Failed to open Shell protocol");
54+
55+
test_env(&shell);
1356
}

0 commit comments

Comments
(0)

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