diff --git a/scripts/fetch_images.sh b/scripts/fetch_images.sh index b68f6b25..f26129e5 100755 --- a/scripts/fetch_images.sh +++ b/scripts/fetch_images.sh @@ -3,8 +3,13 @@ set -x fetch_ch() { CH_PATH="$1" + CH_ARCH="$2" CH_VERSION="v32.0" - CH_URL="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$CH_VERSION/cloud-hypervisor" + CH_URL_BASE="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$CH_VERSION" + + [ "$CH_ARCH" = "x86_64" ] && CH_NAME="cloud-hypervisor" + CH_URL="$CH_URL_BASE/$CH_NAME" + if [ ! -f "$CH_PATH" ]; then wget --quiet $CH_URL -O $CH_PATH chmod +x $CH_PATH @@ -30,28 +35,34 @@ convert_image() { fi } -fetch_disk_images() { - WORKLOADS_DIR="$1" - pushd "$WORKLOADS_DIR" +fetch_raw_ubuntu_image() { + OS_NAME="$1" + OS_ARCH="$2" + OS_IMAGE_NAME="$OS_NAME-server-cloudimg-$OS_ARCH.img" + OS_RAW_IMAGE_NAME="$OS_NAME-server-cloudimg-$OS_ARCH-raw.img" + OS_IMAGE_BASE="https://cloud-images.ubuntu.com" + OS_IMAGE_URL="$OS_IMAGE_BASE/$OS_NAME/current/$OS_IMAGE_NAME" + fetch_image "$OS_IMAGE_NAME" "$OS_IMAGE_URL" + convert_image "$OS_IMAGE_NAME" "$OS_RAW_IMAGE_NAME" +} +x86_64_fetch_disk_images() { CLEAR_OS_IMAGE_NAME="clear-31311-cloudguest.img" CLEAR_OS_URL_BASE="https://cloud-hypervisor.azureedge.net/" CLEAR_OS_IMAGE_URL="$CLEAR_OS_URL_BASE/$CLEAR_OS_IMAGE_NAME" fetch_image "$CLEAR_OS_IMAGE_NAME" "$CLEAR_OS_IMAGE_URL" - FOCAL_OS_IMAGE_NAME="focal-server-cloudimg-amd64.img" - FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-amd64-raw.img" - FOCAL_OS_IMAGE_BASE="https://cloud-images.ubuntu.com/focal/current" - FOCAL_OS_IMAGE_URL="$FOCAL_OS_IMAGE_BASE/$FOCAL_OS_IMAGE_NAME" - fetch_image "$FOCAL_OS_IMAGE_NAME" "$FOCAL_OS_IMAGE_URL" - convert_image "$FOCAL_OS_IMAGE_NAME" "$FOCAL_OS_RAW_IMAGE_NAME" - - JAMMY_OS_IMAGE_NAME="jammy-server-cloudimg-amd64.img" - JAMMY_OS_RAW_IMAGE_NAME="jammy-server-cloudimg-amd64-raw.img" - JAMMY_OS_IMAGE_BASE="https://cloud-images.ubuntu.com/jammy/current" - JAMMY_OS_IMAGE_URL="$JAMMY_OS_IMAGE_BASE/$JAMMY_OS_IMAGE_NAME" - fetch_image "$JAMMY_OS_IMAGE_NAME" "$JAMMY_OS_IMAGE_URL" - convert_image "$JAMMY_OS_IMAGE_NAME" "$JAMMY_OS_RAW_IMAGE_NAME" + fetch_raw_ubuntu_image "focal" "amd64" + fetch_raw_ubuntu_image "jammy" "amd64" +} + +fetch_disk_images() { + WORKLOADS_DIR="$1" + ARCH="$2" + + pushd "$WORKLOADS_DIR" + + [ "$ARCH" = "x86_64" ] && x86_64_fetch_disk_images popd } diff --git a/scripts/run_coreboot_integration_tests.sh b/scripts/run_coreboot_integration_tests.sh index 68ff5869..422b36a4 100755 --- a/scripts/run_coreboot_integration_tests.sh +++ b/scripts/run_coreboot_integration_tests.sh @@ -6,15 +6,19 @@ RHF_ROOT_DIR=$(cd "$(dirname "$0")/../" && pwd) source "${CARGO_HOME:-$HOME/.cargo}/env" source "$(dirnam "$0")/fetch_images.sh" +arch="$(uname -m)" + WORKLOADS_DIR="$HOME/workloads" mkdir -p "$WORKLOADS_DIR" -fetch_disk_images "$WORKLOADS_DIR" +fetch_disk_images "$WORKLOADS_DIR" "$arch" + +[ "$arch" = "x86_64" ] && target="x86_64-unknown-none" rustup component add rust-src -cargo build --release --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem --features "coreboot" +cargo build --release --target "$target.json" -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem --features "coreboot" -RHF_BIN="$RHF_ROOT_DIR/target/x86_64-unknown-none/release/hypervisor-fw" +RHF_BIN="$RHF_ROOT_DIR/target/$target/release/hypervisor-fw" COREBOOT_CONFIG_IN="$RHF_ROOT_DIR/resources/coreboot/qemu-q35-config.in" cat $COREBOOT_CONFIG_IN | sed -e "s#@CONFIG_PAYLOAD_FILE@#$RHF_BIN#g" > "$COREBOOT_DIR/.config" diff --git a/scripts/run_integration_tests.sh b/scripts/run_integration_tests.sh index 57e33c56..a97ae16d 100755 --- a/scripts/run_integration_tests.sh +++ b/scripts/run_integration_tests.sh @@ -4,16 +4,20 @@ set -x source "${CARGO_HOME:-$HOME/.cargo}/env" source "$(dirname "$0")/fetch_images.sh" +arch="$(uname -m)" + WORKLOADS_DIR="$HOME/workloads" mkdir -p "$WORKLOADS_DIR" CH_PATH="$WORKLOADS_DIR/cloud-hypervisor" -fetch_ch "$CH_PATH" +fetch_ch "$CH_PATH" "$arch" + +fetch_disk_images "$WORKLOADS_DIR" "$arch" -fetch_disk_images "$WORKLOADS_DIR" +[ "$arch" = "x86_64" ] && target="x86_64-unknown-none" rustup component add rust-src -cargo build --release --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem +cargo build --release --target "$target.json" -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem export RUST_BACKTRACE=1 -time cargo test --features "integration_tests" "integration::tests::linux::x86_64" +time cargo test --features "integration_tests" "integration::tests::linux::$arch" diff --git a/src/integration.rs b/src/integration.rs index f3e4dbf3..b146c05d 100644 --- a/src/integration.rs +++ b/src/integration.rs @@ -465,6 +465,12 @@ mod tests { path: &'a str, } + #[cfg(target_arch = "x86_64")] + const TARGET_TRIPLE: &str = "x86_64-unknown-none"; + + #[cfg(target_arch = "x86_64")] + const QEMU_NAME: &str = "qemu-system-x86_64"; + mod linux { use crate::integration::tests::*; @@ -480,7 +486,7 @@ mod tests { "--serial", "tty", "--kernel", - "target/x86_64-unknown-none/release/hypervisor-fw", + &format!("target/{TARGET_TRIPLE}/release/hypervisor-fw"), "--disk", &format!("path={os}"), "--disk", @@ -506,7 +512,7 @@ mod tests { ci: &str, net: &GuestNetworkConfig, ) -> Child { - let mut c = Command::new("qemu-system-x86_64"); + let mut c = Command::new(QEMU_NAME); c.args([ "-machine", "q35,accel=kvm", @@ -550,9 +556,10 @@ mod tests { #[cfg(not(feature = "coreboot"))] fn spawn_qemu(tmp_dir: &TempDir, os: &str, ci: &str, net: &GuestNetworkConfig) -> Child { + let path = format!("target/{TARGET_TRIPLE}/release/hypervisor-fw"); let fw = Firmware { fw_type: "-kernel", - path: "target/x86_64-unknown-none/release/hypervisor-fw", + path: path.as_str(), }; spawn_qemu_common(tmp_dir, &fw, os, ci, net) } @@ -660,7 +667,7 @@ mod tests { prepare_tap(&net); - let mut c = Command::new("qemu-system-x86_64"); + let mut c = Command::new(QEMU_NAME); c.args([ "-machine", "q35,accel=kvm", @@ -720,9 +727,10 @@ mod tests { #[ignore] // Windows guest test on QEMU is not supported yet. #[cfg(not(feature = "coreboot"))] fn test_boot_qemu_windows() { + let path = format!("target/{TARGET_TRIPLE}/release/hypervisor-fw"); let fw = Firmware { fw_type: "-kernel", - path: "target/x86_64-unknown-none/release/hypervisor-fw", + path: path.as_str(), }; test_boot_qemu_windows_common(&fw); } @@ -761,7 +769,7 @@ mod tests { "--serial", "tty", "--kernel", - "target/x86_64-unknown-none/release/hypervisor-fw", + &format!("target/{TARGET_TRIPLE}/release/hypervisor-fw"), "--disk", &format!("path={}", disk.osdisk_path), "--net",