Skip to content
Draft
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
12 changes: 11 additions & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@ jobs:
run: curl -L -o /tmp/libkrunfw-5.0.0-x86_64.tgz https://github.com/containers/libkrunfw/releases/download/v5.0.0/libkrunfw-5.0.0-x86_64.tgz && mkdir tmp && tar xf /tmp/libkrunfw-5.0.0-x86_64.tgz -C tmp && sudo mv tmp/lib64/* /lib/x86_64-linux-gnu

- name: Integration tests
run: RUST_LOG=trace KRUN_ENOMEM_WORKAROUND=1 KRUN_NO_UNSHARE=1 make test
run: KRUN_ENOMEM_WORKAROUND=1 KRUN_NO_UNSHARE=1 KRUN_TEST_BASE_DIR=/tmp/libkrun-tests make test TEST_FLAGS="--keep-all --github-summary"

- name: Upload test logs
if: always()
uses: actions/upload-artifact@v4
with:
name: test-logs
path: |
/tmp/libkrun-tests/
!/tmp/libkrun-tests/**/guest-agent
if-no-files-found: ignore
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,8 @@ test-prefix/lib64/libkrun.pc: $(LIBRARY_RELEASE_$(OS))

test-prefix: test-prefix/lib64/libkrun.pc

TEST ?= all
TEST_FLAGS ?=

test: test-prefix
cd tests; LD_LIBRARY_PATH="$$(realpath ../test-prefix/lib64/)" PKG_CONFIG_PATH="$$(realpath ../test-prefix/lib64/pkgconfig/)" ./run.sh
cd tests; RUST_LOG=trace LD_LIBRARY_PATH="$$(realpath ../test-prefix/lib64/)" PKG_CONFIG_PATH="$$(realpath ../test-prefix/lib64/pkgconfig/)" ./run.sh test --test-case "$(TEST)" $(TEST_FLAGS)
26 changes: 23 additions & 3 deletions src/devices/src/virtio/vsock/tsi_dgram.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::net::{Ipv4Addr, SocketAddrV4};
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6};
use std::num::Wrapping;
use std::os::fd::OwnedFd;
use std::os::unix::io::{AsRawFd, RawFd};
Expand All @@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex};
use nix::fcntl::{fcntl, FcntlArg, OFlag};
use nix::sys::socket::{
bind, connect, getpeername, recv, send, sendto, socket, AddressFamily, MsgFlags, SockFlag,
SockType, SockaddrIn, SockaddrLike, SockaddrStorage,
SockType, SockaddrIn, SockaddrLike, SockaddrStorage, UnixAddr,
};

#[cfg(target_os = "macos")]
Expand All @@ -35,6 +35,7 @@ pub struct TsiDgramProxy {
pub status: ProxyStatus,
sendto_addr: Option<SockaddrStorage>,
listening: bool,
family: AddressFamily,
mem: GuestMemoryMmap,
queue: Arc<Mutex<VirtQueue>>,
rxq: Arc<Mutex<MuxerRxQ>>,
Expand Down Expand Up @@ -102,6 +103,7 @@ impl TsiDgramProxy {
status: ProxyStatus::Idle,
sendto_addr: None,
listening: false,
family,
mem,
queue,
rxq,
Expand Down Expand Up @@ -339,7 +341,25 @@ impl Proxy for TsiDgramProxy {

self.sendto_addr = Some(req.addr);
if !self.listening {
match bind(self.fd.as_raw_fd(), &SockaddrIn::new(0, 0, 0, 0, 0)) {
let bind_result = match self.family {
AddressFamily::Inet => bind(self.fd.as_raw_fd(), &SockaddrIn::new(0, 0, 0, 0, 0)),
AddressFamily::Inet6 => {
let addr6: SockaddrStorage =
SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 0, 0, 0).into();
bind(self.fd.as_raw_fd(), &addr6)
}
#[cfg(target_os = "linux")]
AddressFamily::Unix => {
let addr = UnixAddr::new_unnamed();
bind(self.fd.as_raw_fd(), &addr)
}
_ => {
warn!("sendto_addr: unsupported address family: {:?}", self.family);
return update;
}
};

match bind_result {
Ok(_) => {
self.listening = true;
update.polling = Some((self.id, self.fd.as_raw_fd(), EventSet::IN));
Expand Down
6 changes: 5 additions & 1 deletion tests/guest-agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ fn run_guest_agent(test_name: &str) -> anyhow::Result<()> {
.into_iter()
.find(|t| t.name() == test_name)
.context("No such test!")?;
let TestCase { test, name: _ } = test_case;
let TestCase {
test,
name: _,
requires_namespace: _,
} = test_case;
test.in_guest();
Ok(())
}
Expand Down
14 changes: 11 additions & 3 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/bin/sh
#!/bin/sh

# This script has to be run with the working directory being "test"
# This runs the tests on the libkrun instance found by pkg-config.
Expand All @@ -16,11 +16,19 @@ cargo build -p runner

export KRUN_TEST_GUEST_AGENT_PATH="target/$GUEST_TARGET_ARCH/debug/guest-agent"

# Build runner args: pass through all arguments
RUNNER_ARGS="$*"

# Add --base-dir if KRUN_TEST_BASE_DIR is set
if [ -n "${KRUN_TEST_BASE_DIR}" ]; then
RUNNER_ARGS="${RUNNER_ARGS} --base-dir ${KRUN_TEST_BASE_DIR}"
fi

if [ -z "${KRUN_NO_UNSHARE}" ] && which unshare 2>&1 >/dev/null; then
unshare --user --map-root-user --net -- /bin/sh -c "ifconfig lo 127.0.0.1 && exec target/debug/runner $@"
unshare --user --map-root-user --net -- /bin/sh -c "ifconfig lo 127.0.0.1 && exec target/debug/runner ${RUNNER_ARGS}"
else
echo "WARNING: Running tests without a network namespace."
echo "Tests may fail if the required network ports are already in use."
echo
target/debug/runner $@
target/debug/runner ${RUNNER_ARGS}
fi
2 changes: 1 addition & 1 deletion tests/runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
test_cases = { path = "../test_cases", features = ["host"] }
anyhow = "1.0.95"
nix = { version = "0.29.0", features = ["resource", "fs"] }
nix = { version = "0.29.0", features = ["resource", "fs", "sched", "user", "process"] }
macros = { path = "../macros" }
clap = { version = "4.5.27", features = ["derive"] }
tempdir = "0.3.7"
Loading
Loading