Skip to content

Commit 1f9669d

Browse files
committed
tests: Parameterize arch-dependent tests
This commit parameterize x86_64-specific integration test code and scripts so that we can add other architectures. Signed-off-by: Akira Moroo <retrage01@gmail.com>
1 parent 4aa332a commit 1f9669d

File tree

5 files changed

+65
-34
lines changed

5 files changed

+65
-34
lines changed

scripts/fetch_images.sh

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ set -x
33

44
fetch_ch() {
55
CH_PATH="$1"
6+
CH_ARCH="$2"
67
CH_VERSION="v32.0"
7-
CH_URL="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$CH_VERSION/cloud-hypervisor"
8+
CH_URL_BASE="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$CH_VERSION"
9+
10+
[ "$CH_ARCH" = "x86_64" ] && CH_NAME="cloud-hypervisor"
11+
CH_URL="$CH_URL_BASE/$CH_NAME"
12+
813
if [ ! -f "$CH_PATH" ]; then
914
wget --quiet $CH_URL -O $CH_PATH
1015
chmod +x $CH_PATH
@@ -30,28 +35,34 @@ convert_image() {
3035
fi
3136
}
3237

33-
fetch_disk_images() {
34-
WORKLOADS_DIR="$1"
35-
pushd "$WORKLOADS_DIR"
38+
fetch_raw_ubuntu_image() {
39+
OS_NAME="$1"
40+
OS_ARCH="$2"
41+
OS_IMAGE_NAME="$OS_NAME-server-cloudimg-$OS_ARCH.img"
42+
OS_RAW_IMAGE_NAME="$OS_NAME-server-cloudimg-$OS_ARCH-raw.img"
43+
OS_IMAGE_BASE="https://cloud-images.ubuntu.com"
44+
OS_IMAGE_URL="$OS_IMAGE_BASE/$OS_NAME/current/$OS_IMAGE_NAME"
45+
fetch_image "$OS_IMAGE_NAME" "$OS_IMAGE_URL"
46+
convert_image "$OS_IMAGE_NAME" "$OS_RAW_IMAGE_NAME"
47+
}
3648

49+
x86_64_fetch_disk_images() {
3750
CLEAR_OS_IMAGE_NAME="clear-31311-cloudguest.img"
3851
CLEAR_OS_URL_BASE="https://cloud-hypervisor.azureedge.net/"
3952
CLEAR_OS_IMAGE_URL="$CLEAR_OS_URL_BASE/$CLEAR_OS_IMAGE_NAME"
4053
fetch_image "$CLEAR_OS_IMAGE_NAME" "$CLEAR_OS_IMAGE_URL"
4154

42-
FOCAL_OS_IMAGE_NAME="focal-server-cloudimg-amd64.img"
43-
FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-amd64-raw.img"
44-
FOCAL_OS_IMAGE_BASE="https://cloud-images.ubuntu.com/focal/current"
45-
FOCAL_OS_IMAGE_URL="$FOCAL_OS_IMAGE_BASE/$FOCAL_OS_IMAGE_NAME"
46-
fetch_image "$FOCAL_OS_IMAGE_NAME" "$FOCAL_OS_IMAGE_URL"
47-
convert_image "$FOCAL_OS_IMAGE_NAME" "$FOCAL_OS_RAW_IMAGE_NAME"
48-
49-
JAMMY_OS_IMAGE_NAME="jammy-server-cloudimg-amd64.img"
50-
JAMMY_OS_RAW_IMAGE_NAME="jammy-server-cloudimg-amd64-raw.img"
51-
JAMMY_OS_IMAGE_BASE="https://cloud-images.ubuntu.com/jammy/current"
52-
JAMMY_OS_IMAGE_URL="$JAMMY_OS_IMAGE_BASE/$JAMMY_OS_IMAGE_NAME"
53-
fetch_image "$JAMMY_OS_IMAGE_NAME" "$JAMMY_OS_IMAGE_URL"
54-
convert_image "$JAMMY_OS_IMAGE_NAME" "$JAMMY_OS_RAW_IMAGE_NAME"
55+
fetch_raw_ubuntu_image "focal" "amd64"
56+
fetch_raw_ubuntu_image "jammy" "amd64"
57+
}
58+
59+
fetch_disk_images() {
60+
WORKLOADS_DIR="$1"
61+
ARCH="$2"
62+
63+
pushd "$WORKLOADS_DIR"
64+
65+
[ "$ARCH" = "x86_64" ] && x86_64_fetch_disk_images
5566

5667
popd
5768
}

scripts/run_coreboot_integration_tests.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ RHF_ROOT_DIR=$(cd "$(dirname "$0")/../" && pwd)
66
source "${CARGO_HOME:-$HOME/.cargo}/env"
77
source "$(dirnam "$0")/fetch_images.sh"
88

9+
arch="$(uname -m)"
10+
911
WORKLOADS_DIR="$HOME/workloads"
1012
mkdir -p "$WORKLOADS_DIR"
1113

12-
fetch_disk_images "$WORKLOADS_DIR"
14+
fetch_disk_images "$WORKLOADS_DIR" "$arch"
15+
16+
[ "$arch" = "x86_64" ] && target="x86_64-unknown-none"
1317

1418
rustup component add rust-src
15-
cargo build --release --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem --features "coreboot"
19+
cargo build --release --target "$target.json" -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem --features "coreboot"
1620

17-
RHF_BIN="$RHF_ROOT_DIR/target/x86_64-unknown-none/release/hypervisor-fw"
21+
RHF_BIN="$RHF_ROOT_DIR/target/$target/release/hypervisor-fw"
1822
COREBOOT_CONFIG_IN="$RHF_ROOT_DIR/resources/coreboot/qemu-q35-config.in"
1923

2024
cat $COREBOOT_CONFIG_IN | sed -e "s#@CONFIG_PAYLOAD_FILE@#$RHF_BIN#g" > "$COREBOOT_DIR/.config"
2125
make -C $COREBOOT_DIR olddefconfig
2226
make -C $COREBOOT_DIR -j"$(nproc)"
2327

2428
export RUST_BACKTRACE=1
25-
cargo test --features "coreboot integration_tests" "integration::tests::linux::x86_64"
29+
cargo test --features "coreboot integration_tests" "integration::tests::linux::$arch"

scripts/run_integration_tests.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ set -x
44
source "${CARGO_HOME:-$HOME/.cargo}/env"
55
source "$(dirname "$0")/fetch_images.sh"
66

7+
arch="$(uname -m)"
8+
79
WORKLOADS_DIR="$HOME/workloads"
810
mkdir -p "$WORKLOADS_DIR"
911

1012
CH_PATH="$WORKLOADS_DIR/cloud-hypervisor"
11-
fetch_ch "$CH_PATH"
13+
fetch_ch "$CH_PATH" "$arch"
14+
15+
fetch_disk_images "$WORKLOADS_DIR" "$arch"
1216

13-
fetch_disk_images "$WORKLOADS_DIR"
17+
[ "$arch" = "x86_64" ] && target="x86_64-unknown-none"
1418

1519
rustup component add rust-src
16-
cargo build --release --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
20+
cargo build --release --target "$target.json" -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
1721

1822
export RUST_BACKTRACE=1
19-
time cargo test --features "integration_tests" "integration::tests::linux::x86_64"
23+
time cargo test --features "integration_tests" "integration::tests::linux::$arch"

scripts/run_integration_tests_windows.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set -x
44
source "${CARGO_HOME:-$HOME/.cargo}/env"
55
source "$(dirname "$0")/fetch_images.sh"
66

7+
arch="$(uname -m)"
8+
79
WORKLOADS_DIR="$HOME/workloads"
810
mkdir -p "$WORKLOADS_DIR"
911

@@ -16,7 +18,7 @@ if [ ! -f "$WIN_IMAGE_FILE" ]; then
1618
fi
1719

1820
CH_PATH="$WORKLOADS_DIR/cloud-hypervisor"
19-
fetch_ch "$CH_PATH"
21+
fetch_ch "$CH_PATH" "$arch"
2022

2123
# Use device mapper to create a snapshot of the Windows image
2224
img_blk_size=$(du -b -B 512 ${WIN_IMAGE_FILE} | awk '{print $1;}')
@@ -26,11 +28,13 @@ dmsetup mknodes
2628
dmsetup create windows-snapshot-base --table "0 $img_blk_size snapshot-origin /dev/mapper/windows-base"
2729
dmsetup mknodes
2830

31+
[ "$arch" = "x86_64" ] && target="x86_64-unknown-none"
32+
2933
rustup component add rust-src
30-
cargo build --release --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
34+
cargo build --release --target "$target.json" -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
3135

3236
export RUST_BACKTRACE=1
33-
time cargo test --features "integration_tests" "integration::tests::windows::x86_64"
37+
time cargo test --features "integration_tests" "integration::tests::windows::$arch"
3438
RES=$?
3539

3640
dmsetup remove_all -f

src/integration.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,12 @@ mod tests {
465465
path: &'a str,
466466
}
467467

468+
#[cfg(target_arch = "x86_64")]
469+
const TARGET_TRIPLE: &str = "x86_64-unknown-none";
470+
471+
#[cfg(target_arch = "x86_64")]
472+
const QEMU_NAME: &str = "qemu-system-x86_64";
473+
468474
mod linux {
469475
use crate::integration::tests::*;
470476

@@ -480,7 +486,7 @@ mod tests {
480486
"--serial",
481487
"tty",
482488
"--kernel",
483-
"target/x86_64-unknown-none/release/hypervisor-fw",
489+
&format!("target/{TARGET_TRIPLE}/release/hypervisor-fw"),
484490
"--disk",
485491
&format!("path={os}"),
486492
"--disk",
@@ -506,7 +512,7 @@ mod tests {
506512
ci: &str,
507513
net: &GuestNetworkConfig,
508514
) -> Child {
509-
let mut c = Command::new("qemu-system-x86_64");
515+
let mut c = Command::new(QEMU_NAME);
510516
c.args([
511517
"-machine",
512518
"q35,accel=kvm",
@@ -550,9 +556,10 @@ mod tests {
550556

551557
#[cfg(not(feature = "coreboot"))]
552558
fn spawn_qemu(tmp_dir: &TempDir, os: &str, ci: &str, net: &GuestNetworkConfig) -> Child {
559+
let path = format!("target/{TARGET_TRIPLE}/release/hypervisor-fw");
553560
let fw = Firmware {
554561
fw_type: "-kernel",
555-
path: "target/x86_64-unknown-none/release/hypervisor-fw",
562+
path: path.as_str(),
556563
};
557564
spawn_qemu_common(tmp_dir, &fw, os, ci, net)
558565
}
@@ -660,7 +667,7 @@ mod tests {
660667

661668
prepare_tap(&net);
662669

663-
let mut c = Command::new("qemu-system-x86_64");
670+
let mut c = Command::new(QEMU_NAME);
664671
c.args([
665672
"-machine",
666673
"q35,accel=kvm",
@@ -720,9 +727,10 @@ mod tests {
720727
#[ignore] // Windows guest test on QEMU is not supported yet.
721728
#[cfg(not(feature = "coreboot"))]
722729
fn test_boot_qemu_windows() {
730+
let path = format!("target/{TARGET_TRIPLE}/release/hypervisor-fw");
723731
let fw = Firmware {
724732
fw_type: "-kernel",
725-
path: "target/x86_64-unknown-none/release/hypervisor-fw",
733+
path: path.as_str(),
726734
};
727735
test_boot_qemu_windows_common(&fw);
728736
}
@@ -761,7 +769,7 @@ mod tests {
761769
"--serial",
762770
"tty",
763771
"--kernel",
764-
"target/x86_64-unknown-none/release/hypervisor-fw",
772+
&format!("target/{TARGET_TRIPLE}/release/hypervisor-fw"),
765773
"--disk",
766774
&format!("path={}", disk.osdisk_path),
767775
"--net",

0 commit comments

Comments
 (0)