Skip to content

Commit

Permalink
integration: Move x86_64 tests to x86_64 mod
Browse files Browse the repository at this point in the history
This change is to prepare for adding aarch64 integration tests.

Signed-off-by: Akira Moroo <[email protected]>
  • Loading branch information
retrage committed Jul 23, 2023
1 parent 0223f6f commit 33e0919
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 100 deletions.
2 changes: 1 addition & 1 deletion scripts/run_coreboot_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ make -C $COREBOOT_DIR olddefconfig
make -C $COREBOOT_DIR -j"$(nproc)"

export RUST_BACKTRACE=1
cargo test --features "coreboot integration_tests" "integration::tests::linux"
cargo test --features "coreboot integration_tests" "integration::tests::linux::x86_64"
2 changes: 1 addition & 1 deletion scripts/run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ rustup component add rust-src
cargo build --release --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem

export RUST_BACKTRACE=1
time cargo test --features "integration_tests" "integration::tests::linux"
time cargo test --features "integration_tests" "integration::tests::linux::x86_64"
2 changes: 1 addition & 1 deletion scripts/run_integration_tests_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rustup component add rust-src
cargo build --release --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem

export RUST_BACKTRACE=1
time cargo test --features "integration_tests" "integration::tests::windows"
time cargo test --features "integration_tests" "integration::tests::windows::x86_64"
RES=$?

dmsetup remove_all -f
Expand Down
203 changes: 106 additions & 97 deletions src/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,41 +598,45 @@ mod tests {
handle_child_output(&tmp_dir, r, &output);
}

const FOCAL_IMAGE_NAME: &str = "focal-server-cloudimg-amd64-raw.img";
const JAMMY_IMAGE_NAME: &str = "jammy-server-cloudimg-amd64-raw.img";
const CLEAR_IMAGE_NAME: &str = "clear-31311-cloudguest.img";
mod x86_64 {
use super::*;

#[test]
fn test_boot_qemu_focal() {
test_boot(FOCAL_IMAGE_NAME, &UbuntuCloudInit {}, spawn_qemu)
}
const FOCAL_IMAGE_NAME: &str = "focal-server-cloudimg-amd64-raw.img";
const JAMMY_IMAGE_NAME: &str = "jammy-server-cloudimg-amd64-raw.img";
const CLEAR_IMAGE_NAME: &str = "clear-31311-cloudguest.img";

#[test]
fn test_boot_qemu_jammy() {
test_boot(JAMMY_IMAGE_NAME, &UbuntuCloudInit {}, spawn_qemu)
}
#[test]
fn test_boot_qemu_focal() {
test_boot(FOCAL_IMAGE_NAME, &UbuntuCloudInit {}, spawn_qemu)
}

#[test]
fn test_boot_qemu_clear() {
test_boot(CLEAR_IMAGE_NAME, &ClearCloudInit {}, spawn_qemu)
}
#[test]
fn test_boot_qemu_jammy() {
test_boot(JAMMY_IMAGE_NAME, &UbuntuCloudInit {}, spawn_qemu)
}

#[test]
#[cfg(not(feature = "coreboot"))]
fn test_boot_ch_focal() {
test_boot(FOCAL_IMAGE_NAME, &UbuntuCloudInit {}, spawn_ch)
}
#[test]
fn test_boot_qemu_clear() {
test_boot(CLEAR_IMAGE_NAME, &ClearCloudInit {}, spawn_qemu)
}

#[test]
#[cfg(not(feature = "coreboot"))]
fn test_boot_ch_jammy() {
test_boot(JAMMY_IMAGE_NAME, &UbuntuCloudInit {}, spawn_ch)
}
#[test]
#[cfg(not(feature = "coreboot"))]
fn test_boot_ch_focal() {
test_boot(FOCAL_IMAGE_NAME, &UbuntuCloudInit {}, spawn_ch)
}

#[test]
#[cfg(not(feature = "coreboot"))]
fn test_boot_ch_clear() {
test_boot(CLEAR_IMAGE_NAME, &ClearCloudInit {}, spawn_ch)
#[test]
#[cfg(not(feature = "coreboot"))]
fn test_boot_ch_jammy() {
test_boot(JAMMY_IMAGE_NAME, &UbuntuCloudInit {}, spawn_ch)
}

#[test]
#[cfg(not(feature = "coreboot"))]
fn test_boot_ch_clear() {
test_boot(CLEAR_IMAGE_NAME, &ClearCloudInit {}, spawn_ch)
}
}
}

Expand Down Expand Up @@ -709,78 +713,83 @@ mod tests {
handle_child_output(&tmp_dir, r, &output);
}

#[test]
#[ignore] // Windows guest test on QEMU is not supported yet.
#[cfg(not(feature = "coreboot"))]
fn test_boot_qemu_windows() {
let fw = Firmware {
fw_type: "-kernel",
path: "target/x86_64-unknown-none/release/hypervisor-fw",
};
test_boot_qemu_windows_common(&fw);
}

#[test]
#[ignore] // Windows guest test on QEMU is not supported yet.
#[cfg(feature = "coreboot")]
fn test_boot_qemu_windows() {
let fw = Firmware {
fw_type: "-bios",
path: "resources/coreboot/coreboot/build/coreboot.rom",
};
test_boot_qemu_windows_common(&fw);
}

#[test]
#[cfg(not(feature = "coreboot"))]
fn test_boot_ch_windows() {
let mut disk = WindowsDiskConfig::new(WINDOWS_IMAGE_NAME.to_string());
let tmp_dir = TempDir::new().expect("Expect creating temporary directory to succeed");
prepare_windows_os_disk(&mut disk, &tmp_dir);

let clh_path = dirs::home_dir()
.unwrap()
.join("workloads")
.join("cloud-hypervisor");
let mut c = Command::new(clh_path.to_str().unwrap());
c.args([
"--cpus",
"boot=2,kvm_hyperv=on",
"--memory",
"size=4G",
"--console",
"off",
"--serial",
"tty",
"--kernel",
"target/x86_64-unknown-none/release/hypervisor-fw",
"--disk",
&format!("path={}", disk.osdisk_path),
"--net",
"tap=",
]);

let stdout = fs::File::create(tmp_dir.path().join("stdout")).unwrap();
let stderr = fs::File::create(tmp_dir.path().join("stderr")).unwrap();
mod x86_64 {
use super::*;

#[test]
#[ignore] // Windows guest test on QEMU is not supported yet.
#[cfg(not(feature = "coreboot"))]
fn test_boot_qemu_windows() {
let fw = Firmware {
fw_type: "-kernel",
path: "target/x86_64-unknown-none/release/hypervisor-fw",
};
test_boot_qemu_windows_common(&fw);
}

eprintln!("Spawning: {:?}", c);
let mut child = c
.stdout(Stdio::from(stdout))
.stderr(Stdio::from(stderr))
.spawn()
.expect("Expect launching Cloud Hypervisor to succeed");
#[test]
#[ignore] // Windows guest test on QEMU is not supported yet.
#[cfg(feature = "coreboot")]
fn test_boot_qemu_windows() {
let fw = Firmware {
fw_type: "-bios",
path: "resources/coreboot/coreboot/build/coreboot.rom",
};
test_boot_qemu_windows_common(&fw);
}

thread::sleep(std::time::Duration::from_secs(60));
let r = std::panic::catch_unwind(|| {
let auth = windows_auth();
ssh_command_with_auth("192.168.249.2", "shutdown /s", &auth)
.expect("Expect SSH command to work");
});
#[test]
#[cfg(not(feature = "coreboot"))]
fn test_boot_ch_windows() {
let mut disk = WindowsDiskConfig::new(WINDOWS_IMAGE_NAME.to_string());
let tmp_dir =
TempDir::new().expect("Expect creating temporary directory to succeed");
prepare_windows_os_disk(&mut disk, &tmp_dir);

let clh_path = dirs::home_dir()
.unwrap()
.join("workloads")
.join("cloud-hypervisor");
let mut c = Command::new(clh_path.to_str().unwrap());
c.args([
"--cpus",
"boot=2,kvm_hyperv=on",
"--memory",
"size=4G",
"--console",
"off",
"--serial",
"tty",
"--kernel",
"target/x86_64-unknown-none/release/hypervisor-fw",
"--disk",
&format!("path={}", disk.osdisk_path),
"--net",
"tap=",
]);

let stdout = fs::File::create(tmp_dir.path().join("stdout")).unwrap();
let stderr = fs::File::create(tmp_dir.path().join("stderr")).unwrap();

eprintln!("Spawning: {:?}", c);
let mut child = c
.stdout(Stdio::from(stdout))
.stderr(Stdio::from(stderr))
.spawn()
.expect("Expect launching Cloud Hypervisor to succeed");

thread::sleep(std::time::Duration::from_secs(60));
let r = std::panic::catch_unwind(|| {
let auth = windows_auth();
ssh_command_with_auth("192.168.249.2", "shutdown /s", &auth)
.expect("Expect SSH command to work");
});

child.kill().unwrap();
let output = child.wait_with_output().unwrap();
child.kill().unwrap();
let output = child.wait_with_output().unwrap();

handle_child_output(&tmp_dir, r, &output);
handle_child_output(&tmp_dir, r, &output);
}
}
}
}

0 comments on commit 33e0919

Please sign in to comment.