-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: make it possible to run tests inside SVSM
To build and run a kernel that runs the tests use ``` QEMU=/path/to/qemu OVMF=/path/to/firmware/ make test-in-svsm ``` Signed-off-by: Tom Dohrmann <[email protected]>
- Loading branch information
Showing
7 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -5,6 +5,16 @@ | |
// Author: Nicolai Stange <[email protected]> | ||
|
||
#![no_std] | ||
#![cfg_attr(all(test, target_os = "none"), no_main)] | ||
#![cfg_attr(all(test, target_os = "none"), feature(custom_test_frameworks))] | ||
#![cfg_attr( | ||
all(test, target_os = "none"), | ||
test_runner(crate::testing::svsm_test_runner) | ||
)] | ||
#![cfg_attr( | ||
all(test, target_os = "none"), | ||
reexport_test_harness_main = "test_main" | ||
)] | ||
|
||
pub mod acpi; | ||
pub mod address; | ||
|
@@ -33,3 +43,15 @@ pub mod utils; | |
|
||
#[test] | ||
fn test_nop() {} | ||
|
||
// When running tests inside the SVSM: | ||
// Build the kernel entrypoint. | ||
#[cfg(all(test, target_os = "none"))] | ||
#[path = "svsm.rs"] | ||
pub mod svsm_bin; | ||
// The kernel expects to access this crate as svsm, so reexport. | ||
#[cfg(all(test, target_os = "none"))] | ||
extern crate self as svsm; | ||
// Include a module containing the test runner. | ||
#[cfg(all(test, target_os = "none"))] | ||
pub mod testing; |
This file contains 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 |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
// | ||
// Author: Joerg Roedel <[email protected]> | ||
|
||
#![no_std] | ||
#![no_main] | ||
#![cfg_attr(not(test), no_std)] | ||
#![cfg_attr(not(test), no_main)] | ||
|
||
extern crate alloc; | ||
|
||
|
@@ -470,6 +470,9 @@ pub extern "C" fn svsm_main() { | |
panic!("Failed to launch FW: {:#?}", e); | ||
} | ||
|
||
#[cfg(test)] | ||
crate::test_main(); | ||
|
||
request_loop(); | ||
|
||
panic!("Road ends here!"); | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use log::info; | ||
use test::ShouldPanic; | ||
|
||
use crate::sev::msr_protocol::request_termination_msr; | ||
|
||
pub fn svsm_test_runner(test_cases: &[&test::TestDescAndFn]) { | ||
info!("running {} tests", test_cases.len()); | ||
for mut test_case in test_cases.iter().copied().copied() { | ||
if test_case.desc.should_panic == ShouldPanic::Yes { | ||
test_case.desc.ignore = true; | ||
test_case | ||
.desc | ||
.ignore_message | ||
.get_or_insert("#[should_panic] not supported"); | ||
} | ||
|
||
if test_case.desc.ignore { | ||
if let Some(message) = test_case.desc.ignore_message { | ||
info!("test {} ... ignored, {message}", test_case.desc.name.0); | ||
} else { | ||
info!("test {} ... ignored", test_case.desc.name.0); | ||
} | ||
continue; | ||
} | ||
|
||
info!("test {} ...", test_case.desc.name.0); | ||
(test_case.testfn.0)(); | ||
} | ||
|
||
info!("All tests passed!"); | ||
|
||
request_termination_msr(); | ||
} |