-
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.
Merge pull request #120 from Freax13/feature/custom-test-framework
run tests inside SVSM
- Loading branch information
Showing
18 changed files
with
257 additions
and
15 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ target/ | |
gen_meta | ||
stage1/stage1 | ||
print-meta | ||
cbit | ||
.idea/ |
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
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,34 @@ | ||
#!/bin/bash | ||
# | ||
|
||
set -e | ||
|
||
if [ "$QEMU" == "" ]; then | ||
echo "Set QEMU environment variable to QEMU installation path" && exit 1 | ||
fi | ||
if [ "$OVMF_PATH" == "" ]; then | ||
echo "Set OVMF_PATH environment variable to a folder containing OVMF_CODE.fd and OVMF_VARS.fd" && exit 1 | ||
fi | ||
if [ "$SUDO" != "" ]; then | ||
SUDO_CMD="sudo" | ||
else | ||
SUDO_CMD="" | ||
fi | ||
|
||
C_BIT_POS=`utils/cbit` | ||
|
||
$SUDO_CMD $QEMU \ | ||
-enable-kvm \ | ||
-cpu EPYC-v4 \ | ||
-machine q35,confidential-guest-support=sev0,memory-backend=ram1,kvm-type=protected \ | ||
-object memory-backend-memfd-private,id=ram1,size=1G,share=true \ | ||
-object sev-snp-guest,id=sev0,cbitpos=$C_BIT_POS,reduced-phys-bits=1,svsm=on \ | ||
-smp 8 \ | ||
-no-reboot \ | ||
-drive if=pflash,format=raw,unit=0,file=$OVMF_PATH/OVMF_CODE.fd,readonly=on \ | ||
-drive if=pflash,format=raw,unit=1,file=$OVMF_PATH/OVMF_VARS.fd,snapshot=on \ | ||
-drive if=pflash,format=raw,unit=2,file=./svsm.bin,readonly=on \ | ||
-nographic \ | ||
-monitor none \ | ||
-serial stdio \ | ||
-device isa-debug-exit,iobase=0xf4,iosize=0x04 || true |
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,10 @@ | |
// Author: Nicolai Stange <[email protected]> | ||
|
||
#![no_std] | ||
#![cfg_attr(all(test, test_in_svsm), no_main)] | ||
#![cfg_attr(all(test, test_in_svsm), feature(custom_test_frameworks))] | ||
#![cfg_attr(all(test, test_in_svsm), test_runner(crate::testing::svsm_test_runner))] | ||
#![cfg_attr(all(test, test_in_svsm), reexport_test_harness_main = "test_main")] | ||
|
||
pub mod acpi; | ||
pub mod address; | ||
|
@@ -33,3 +37,15 @@ pub mod utils; | |
|
||
#[test] | ||
fn test_nop() {} | ||
|
||
// When running tests inside the SVSM: | ||
// Build the kernel entrypoint. | ||
#[cfg(all(test, test_in_svsm))] | ||
#[path = "svsm.rs"] | ||
pub mod svsm_bin; | ||
// The kernel expects to access this crate as svsm, so reexport. | ||
#[cfg(all(test, test_in_svsm))] | ||
extern crate self as svsm; | ||
// Include a module containing the test runner. | ||
#[cfg(all(test, test_in_svsm))] | ||
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,6 @@ | |
// | ||
// Author: Joerg Roedel <[email protected]> | ||
|
||
#[cfg(any(test, fuzzing))] | ||
use crate::address::Address; | ||
use crate::address::{PhysAddr, VirtAddr}; | ||
use crate::utils::immut_after_init::ImmutAfterInitCell; | ||
|
||
|
@@ -30,7 +28,7 @@ pub fn init_kernel_mapping_info(vstart: VirtAddr, vend: VirtAddr, pstart: PhysAd | |
.expect("Already initialized kernel mapping info"); | ||
} | ||
|
||
#[cfg(not(any(test, fuzzing)))] | ||
#[cfg(target_os = "none")] | ||
pub fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr { | ||
if vaddr < KERNEL_MAPPING.virt_start || vaddr >= KERNEL_MAPPING.virt_end { | ||
panic!("Invalid physical address {:#018x}", vaddr); | ||
|
@@ -41,7 +39,7 @@ pub fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr { | |
KERNEL_MAPPING.phys_start + offset | ||
} | ||
|
||
#[cfg(not(any(test, fuzzing)))] | ||
#[cfg(target_os = "none")] | ||
pub fn phys_to_virt(paddr: PhysAddr) -> VirtAddr { | ||
let size: usize = KERNEL_MAPPING.virt_end - KERNEL_MAPPING.virt_start; | ||
if paddr < KERNEL_MAPPING.phys_start || paddr >= KERNEL_MAPPING.phys_start + size { | ||
|
@@ -53,13 +51,15 @@ pub fn phys_to_virt(paddr: PhysAddr) -> VirtAddr { | |
KERNEL_MAPPING.virt_start + offset | ||
} | ||
|
||
#[cfg(any(test, fuzzing))] | ||
#[cfg(not(target_os = "none"))] | ||
pub fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr { | ||
use crate::address::Address; | ||
PhysAddr::from(vaddr.bits()) | ||
} | ||
|
||
#[cfg(any(test, fuzzing))] | ||
#[cfg(not(target_os = "none"))] | ||
pub fn phys_to_virt(paddr: PhysAddr) -> VirtAddr { | ||
use crate::address::Address; | ||
VirtAddr::from(paddr.bits()) | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -479,6 +479,9 @@ pub extern "C" fn svsm_main() { | |
panic!("Failed to launch FW: {:#?}", e); | ||
} | ||
|
||
#[cfg(test)] | ||
crate::test_main(); | ||
|
||
request_loop(); | ||
|
||
panic!("Road ends here!"); | ||
|
Oops, something went wrong.