Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ jobs:
if: matrix.arch == 'x86_64'
- run: cargo clean
working-directory: .
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.rs_flags }} --package vsock qemu ${{ matrix.qemu_flags }} --sudo --devices virtio-vsock-pci
if: matrix.arch != 'riscv64' && matrix.arch != 'aarch64_be'
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.rs_flags }} --package httpd --features ci,hermit/dhcpv4,hermit/virtio-net qemu ${{ matrix.qemu_flags }} --devices virtio-net-pci
if: matrix.arch != 'riscv64'
# FIXME: this is broken on QEMU 8.2.2
Expand Down
43 changes: 41 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"

[features]
default = ["ci"]
ci = ["dep:ovmf-prebuilt", "dep:sysinfo", "dep:ureq", "dep:wait-timeout"]
ci = ["dep:ovmf-prebuilt", "dep:sysinfo", "dep:ureq", "dep:vsock", "dep:wait-timeout"]

[dependencies]
anyhow = "1.0"
Expand All @@ -15,5 +15,6 @@ home = "0.5"
ovmf-prebuilt = { version = "0.2", optional = true }
sysinfo = { version = "0.38", optional = true }
ureq = { version = "3", default-features = false, features = ["rustls"], optional = true }
vsock = { version = "0.5", optional = true }
wait-timeout = { version = "0.2", optional = true }
xshell = "0.2"
40 changes: 39 additions & 1 deletion xtask/src/ci/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{env, fs, thread};
use anyhow::{Context, Result, bail, ensure};
use clap::{Args, ValueEnum};
use sysinfo::{CpuRefreshKind, System};
use vsock::VsockStream;
use wait_timeout::ChildExt;
use xshell::cmd;

Expand Down Expand Up @@ -79,6 +80,12 @@ pub enum Device {

/// virtio-net via PCI.
VirtioNetPci,

/// virtio-vsock via MMIO.
VirtioVsockMmio,

/// virtio-vsock via PCI.
VirtioVsockPci,
}

impl Qemu {
Expand Down Expand Up @@ -152,12 +159,13 @@ impl Qemu {
"mioudp" => test_mioudp(guest_ip)?,
"poll" => test_poll(guest_ip)?,
"stdin" => test_stdin(&mut qemu.0)?,
"vsock" => test_vsock()?,
_ => {}
}

if matches!(
image_name,
"axum-example" | "http_server" | "http_server_poll" | "http_server_select"
"axum-example" | "http_server" | "http_server_poll" | "http_server_select" | "vsock"
) || self.devices.contains(&Device::CadenceGem)
// sifive_u, on which we test CadenceGem, does not support software shutdowns, so we have to kill the machine ourselves.
{
Expand Down Expand Up @@ -430,6 +438,16 @@ impl Qemu {
"virtconsole,chardev=char0".to_owned(),
]
}
device @ (Device::VirtioVsockMmio | Device::VirtioVsockPci) => {
let device_arg = match device {
Device::VirtioVsockMmio => "vhost-vsock-device",
Device::VirtioVsockPci => "vhost-vsock-pci,disable-legacy=on",
_ => unreachable!(),
};
let device_arg = format!("{device_arg},guest-cid=3");

vec!["-device".to_owned(), device_arg]
}
})
.collect()
}
Expand Down Expand Up @@ -545,6 +563,26 @@ fn test_stdin(child: &mut Child) -> Result<()> {
Ok(())
}

fn test_vsock() -> Result<()> {
thread::sleep(Duration::from_secs(10));
let messages = ["Hello, there!", "Hello, again!", "Bye-bye!"];

let mut stream = VsockStream::connect_with_cid_port(3, 9975)?;
for message in messages {
writeln!(&mut stream, "{message}")?;
thread::sleep(Duration::from_secs(1));
}

const BUF_SIZE: usize = 8 * 1024;
let mut buf = vec![0; BUF_SIZE];
let n = stream.read(&mut buf)?;
let s = str::from_utf8(&buf[0..n])?;
let received_messages = s.trim().split('\n').collect::<Vec<_>>();
assert_eq!(received_messages, messages);

Ok(())
}

fn test_http_server(guest_ip: IpAddr) -> Result<()> {
thread::sleep(Duration::from_secs(10));
let url = format!("http://{guest_ip}:9975");
Expand Down
Loading