Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: run KVM tests on GitHub runners #368

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
matrix:
target: [x86_64, aarch64, riscv64]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- target: x86_64
os: ubuntu-latest
flags: --accel --sudo
runs-on: ${{ matrix.os }}
steps:
- name: Install QEMU (ubuntu)
Expand Down Expand Up @@ -85,39 +89,41 @@ jobs:
cp /usr/share/OVMF/OVMF_VARS.fd edk2-stable202405-r1-bin/x64/vars.fd
if: matrix.os == 'ubuntu-latest'
- name: Run VM (hello_world, dev)
run: cargo xtask ci qemu --target ${{ matrix.target }}
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }}
- name: Run VM (hello_world, release)
run: cargo xtask ci qemu --target ${{ matrix.target }} --release
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --release
- name: Run VM (hello_world, uefi, dev)
run: cargo xtask ci qemu --target ${{ matrix.target }}-uefi
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }}-uefi
if: matrix.target == 'x86_64'
- name: Run VM (hello_world, uefi, release)
run: cargo xtask ci qemu --target ${{ matrix.target }}-uefi --release
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }}-uefi --release
if: matrix.target == 'x86_64'
- name: Run VM (hello_world-microvm, dev)
if: matrix.target == 'x86_64' && matrix.os == 'ubuntu-latest'
run: cargo xtask ci qemu --target ${{ matrix.target }} --image hello_world-microvm --microvm
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --image hello_world-microvm --microvm
- name: Run VM (hello_world-microvm, release)
if: matrix.target == 'x86_64' && matrix.os == 'ubuntu-latest'
run: cargo xtask ci qemu --target ${{ matrix.target }} --image hello_world-microvm --microvm --release
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --image hello_world-microvm --microvm --release
- name: Run VM (hello_c, dev)
if: matrix.target == 'x86_64'
run: cargo xtask ci qemu --target ${{ matrix.target }} --image hello_c
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --image hello_c
- name: Run VM (hello_c, release)
if: matrix.target == 'x86_64'
run: cargo xtask ci qemu --target ${{ matrix.target }} --image hello_c --release
run: cargo xtask ci qemu ${{ matrix.flags }} --target ${{ matrix.target }} --image hello_c --release

run-kvm:
name: Run (KVM)
runs-on: [self-hosted]
runs-on: ubuntu-24.04
steps:
- name: Install QEMU
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends qemu-system-x86
sudo apt-get install qemu-system-x86
- uses: actions/checkout@v4
with:
lfs: true
- run: git lfs pull
- run: git lfs checkout
- name: Install firecracker
run: |
# https://github.com/firecracker-microvm/firecracker/blob/v1.5.1/docs/getting-started.md#getting-a-firecracker-binary
Expand All @@ -127,29 +133,27 @@ jobs:
curl -L ${release_url}/download/${latest}/firecracker-${latest}-${ARCH}.tgz \
| tar -xz

# Rename the binary to "firecracker"
mv release-${latest}-$(uname -m)/firecracker-${latest}-${ARCH} firecracker
echo "$PWD" >> $GITHUB_PATH
./firecracker --version
mkdir -p $HOME/.local/bin
mv release-${latest}-$(uname -m)/firecracker-${latest}-${ARCH} $HOME/.local/bin/firecracker
echo $HOME/.local/bin >> $GITHUB_PATH

$HOME/.local/bin/firecracker --version
- name: Download OVMF
run: |
gh release download edk2-stable202405-r1 --repo rust-osdev/ovmf-prebuilt --pattern 'edk2-stable*-bin.tar.xz'
tar -xvf edk2-stable*-bin.tar.xz edk2-stable202405-r1-bin/x64
- uses: dtolnay/rust-toolchain@stable
- name: Run QEMU (hello_world, dev)
run: cargo xtask ci qemu --target x86_64 --accel
run: cargo xtask ci qemu --target x86_64 --accel --sudo
- name: Run QEMU (hello_world, release)
run: cargo xtask ci qemu --target x86_64 --accel --release
run: cargo xtask ci qemu --target x86_64 --accel --sudo --release
- name: Run QEMU (hello_world-microvm, dev)
run: cargo xtask ci qemu --target x86_64 --accel --image hello_world-microvm --microvm
run: cargo xtask ci qemu --target x86_64 --accel --sudo --image hello_world-microvm --microvm
- name: Run QEMU (hello_world-microvm, release)
run: cargo xtask ci qemu --target x86_64 --accel --image hello_world-microvm --microvm --release
run: cargo xtask ci qemu --target x86_64 --accel --sudo --image hello_world-microvm --microvm --release
- name: Run UEFI (dev)
run: cargo xtask ci qemu --target x86_64-uefi --accel
run: cargo xtask ci qemu --target x86_64-uefi --accel --sudo
- name: Run UEFI (release)
run: cargo xtask ci qemu --target x86_64-uefi --accel --release
- name: Run Firecracker (hello_world, dev)
run: cargo xtask ci firecracker --target x86_64-fc --features fc --image hello_world-microvm
run: cargo xtask ci qemu --target x86_64-uefi --accel --sudo --release
- name: Run Firecracker (hello_world, release)
run: cargo xtask ci firecracker --target x86_64-fc --features fc --image hello_world-microvm --release
run: FIRECRACKER=$HOME/.local/bin/firecracker cargo xtask ci firecracker --target x86_64-fc --sudo --features fc --image hello_world-microvm --release
16 changes: 15 additions & 1 deletion xtask/src/ci/firecracker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::path::Path;

use anyhow::Result;
Expand All @@ -9,6 +10,10 @@ use crate::build::Build;
/// Run hermit-rs images on Firecracker.
#[derive(Args)]
pub struct Firecracker {
/// Run Firecracker using `sudo`.
#[arg(long)]
sudo: bool,

#[command(flatten)]
build: Build,

Expand All @@ -32,13 +37,22 @@ impl Firecracker {
let config_path = Path::new("firecracker_vm_config.json");
sh.write_file(config_path, config)?;

let firecracker = env::var("FIRECRACKER").unwrap_or_else(|_| "firecracker".to_string());
let program = if self.sudo {
"sudo"
} else {
firecracker.as_str()
};
let arg = self.sudo.then_some(firecracker.as_str());

let log_path = Path::new("firecracker.log");
sh.write_file(log_path, "")?;
cmd!(sh, "firecracker --no-api --config-file {config_path} --log-path {log_path} --level Info --show-level --show-log-origin").run()?;
let res = cmd!(sh, "{program} {arg...} --no-api --config-file {config_path} --log-path {log_path} --level Trace --show-level --show-log-origin").run();
let log = sh.read_file(log_path)?;

eprintln!("firecracker log");
eprintln!("{log}");
res?;

Ok(())
}
Expand Down
10 changes: 8 additions & 2 deletions xtask/src/ci/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub struct Qemu {
#[arg(long)]
accel: bool,

/// Run QEMU using `sudo`.
#[arg(long)]
sudo: bool,

/// Enable the `microvm` machine type.
#[arg(long)]
microvm: bool,
Expand Down Expand Up @@ -49,9 +53,11 @@ impl Qemu {

let target = self.build.target();
let arch = target.arch();
let qemu = env::var_os("QEMU").unwrap_or_else(|| format!("qemu-system-{arch}").into());
let qemu = env::var("QEMU").unwrap_or_else(|_| format!("qemu-system-{arch}"));
let program = if self.sudo { "sudo" } else { qemu.as_str() };
let arg = self.sudo.then_some(qemu.as_str());

let qemu = cmd!(sh, "{qemu}")
let qemu = cmd!(sh, "{program} {arg...}")
.args(&["-display", "none"])
.args(&["-serial", "stdio"])
.args(self.machine_args())
Expand Down
Loading