Skip to content

Commit

Permalink
tests: Parameterize arch-dependent tests
Browse files Browse the repository at this point in the history
This commit parameterize x86_64-specific integration test code and
scripts so that we can add other architectures.

Signed-off-by: Akira Moroo <[email protected]>
  • Loading branch information
retrage committed Jul 23, 2023
1 parent 33e0919 commit 35b2205
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 30 deletions.
45 changes: 28 additions & 17 deletions scripts/fetch_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
10 changes: 7 additions & 3 deletions scripts/run_coreboot_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 8 additions & 4 deletions scripts/run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 14 additions & 6 deletions src/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 35b2205

Please sign in to comment.