Skip to content

Commit cf296df

Browse files
committed
Intruduce an E2E testing framework
Add a tests directory containing an E2E testing framework. The tests are E2E in the sense that they use the public API of libkrun to start a VM and run a test program in the guest. Note that currently this is limited that there are no userspace program or libraries (not even libc) in the guest apart from `guest-agent`, which is part of the testing framework. `guest-agent` is a statically linked Rust executable, that executes the guest part of each test. In the future this can be extended to run tests with specific images and allow the use of system libraries by the test program. Signed-off-by: Matej Hrica <[email protected]>
1 parent 8fa139f commit cf296df

File tree

26 files changed

+844
-19
lines changed

26 files changed

+844
-19
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = [ "krun-sys","src/libkrun"]
2+
members = ["krun-sys", "src/libkrun"]
33
resolver = "2"
44

55
[profile.dev]
@@ -8,3 +8,4 @@ resolver = "2"
88
[profile.release]
99
#panic = "abort"
1010
lto = true
11+
debug = true

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ifeq ($(PREFIX),)
7474
PREFIX := /usr/local
7575
endif
7676

77-
.PHONY: install clean
77+
.PHONY: install clean $(LIBRARY_RELEASE_$(OS))
7878

7979
all: $(LIBRARY_RELEASE_$(OS)) libkrun.pc
8080

src/devices/src/virtio/block/test_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use polly::event_manager::{EventManager, Subscriber};
88
use utils::epoll::{EpollEvent, EventSet};
99
use utils::tempfile::TempFile;
1010

11-
/// Create a default Block instance to be used in tests.
11+
/// Create a default Block instance to be used in test_cases.
1212
pub fn default_block() -> Block {
1313
// Create backing file.
1414
let f = TempFile::new().unwrap();
@@ -17,7 +17,7 @@ pub fn default_block() -> Block {
1717
default_block_with_path(f.as_path().to_str().unwrap().to_string())
1818
}
1919

20-
/// Create a default Block instance using file at the specified path to be used in tests.
20+
/// Create a default Block instance using file at the specified path to be used in test_cases.
2121
pub fn default_block_with_path(path: String) -> Block {
2222
let id = "test".to_string();
2323
// The default block device is read-write and non-root.

src/libkrun/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -859,9 +859,12 @@ pub unsafe extern "C" fn krun_set_exec(
859859
}
860860
}
861861
} else {
862-
env::vars()
862+
let env = env::vars()
863863
.map(|(key, value)| format!(" {key}=\"{value}\""))
864-
.collect()
864+
.take(45)
865+
.collect();
866+
eprintln!("env is {env}");
867+
env
865868
};
866869

867870
match CTX_MAP.lock().unwrap().entry(ctx_id) {

src/rutabaga_gfx/src/generated/virgl_debug_callback_bindings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* automatically generated by rust-bindgen
33
* $ bindgen /usr/include/stdio.h \
4-
* --no-layout-tests \
4+
* --no-layout-test_cases \
55
* --allowlist-function vsnprintf \
66
* -- \
77
* -target <target>

src/rutabaga_gfx/src/rutabaga_gralloc/gralloc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ impl RutabagaGralloc {
227227

228228
#[cfg(feature = "minigbm")]
229229
{
230-
// crosvm integration tests build with the "wl-dmabuf" feature, which translates in
231-
// rutabaga to the "minigbm" feature. These tests run on hosts where a rendernode is
230+
// crosvm integration test_cases build with the "wl-dmabuf" feature, which translates in
231+
// rutabaga to the "minigbm" feature. These test_cases run on hosts where a rendernode is
232232
// not present, and minigbm can not be initialized.
233233
//
234234
// Thus, to keep kokoro happy, allow minigbm initialization to fail silently for now.

src/vmm/src/linux/vstate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ impl Vcpu {
13811381
}
13821382

13831383
#[cfg(test)]
1384-
// In tests the main/vmm thread exits without 'exit()'ing the whole process.
1384+
// In test_cases the main/vmm thread exits without 'exit()'ing the whole process.
13851385
// All channels get closed on the other side while this Vcpu thread is still running.
13861386
// This Vcpu thread should just do a clean finish without reporting back to the main thread.
13871387
fn exit(&mut self, _: u8) -> StateMachine<Self> {
@@ -1439,7 +1439,7 @@ pub struct VcpuHandle {
14391439
event_sender: Sender<VcpuEvent>,
14401440
response_receiver: Receiver<VcpuResponse>,
14411441
// Rust JoinHandles have to be wrapped in Option if you ever plan on 'join()'ing them.
1442-
// We want to be able to join these threads in tests.
1442+
// We want to be able to join these threads in test_cases.
14431443
vcpu_thread: Option<thread::JoinHandle<()>>,
14441444
}
14451445

@@ -1492,7 +1492,7 @@ mod tests {
14921492

14931493
use utils::signal::validate_signal_num;
14941494

1495-
// In tests we need to close any pending Vcpu threads on test completion.
1495+
// In test_cases we need to close any pending Vcpu threads on test completion.
14961496
impl Drop for VcpuHandle {
14971497
fn drop(&mut self) {
14981498
// Make sure the Vcpu is out of KVM_RUN.
@@ -1505,7 +1505,7 @@ mod tests {
15051505
}
15061506
}
15071507

1508-
// Auxiliary function being used throughout the tests.
1508+
// Auxiliary function being used throughout the test_cases.
15091509
fn setup_vcpu(mem_size: usize) -> (Vm, Vcpu, GuestMemoryMmap) {
15101510
let kvm = KvmContext::new().unwrap();
15111511
let gm = GuestMemoryMmap::from_ranges(&[(GuestAddress(0), mem_size)]).unwrap();

src/vmm/src/macos/vstate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ mod tests {
632632

633633
use utils::signal::validate_signal_num;
634634

635-
// In tests we need to close any pending Vcpu threads on test completion.
635+
// In test_cases we need to close any pending Vcpu threads on test completion.
636636
impl Drop for VcpuHandle {
637637
fn drop(&mut self) {
638638
// Make sure the Vcpu is out of KVM_RUN.
@@ -645,7 +645,7 @@ mod tests {
645645
}
646646
}
647647

648-
// Auxiliary function being used throughout the tests.
648+
// Auxiliary function being used throughout the test_cases.
649649
fn setup_vcpu(mem_size: usize) -> (Vm, Vcpu, GuestMemoryMmap) {
650650
let kvm = KvmContext::new().unwrap();
651651
let gm = GuestMemoryMmap::from_ranges(&[(GuestAddress(0), mem_size)]).unwrap();

src/vmm/src/signal_handler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern "C" fn sigsys_handler(num: c_int, info: *mut siginfo_t, _unused: *mut c_v
4242
syscall
4343
);
4444
// Safe because we're terminating the process anyway. We don't actually do anything when
45-
// running unit tests.
45+
// running unit test_cases.
4646
#[cfg(not(test))]
4747
unsafe {
4848
_exit(i32::from(super::FC_EXIT_CODE_BAD_SYSCALL))
@@ -69,7 +69,7 @@ extern "C" fn sigbus_sigsegv_handler(num: c_int, info: *mut siginfo_t, _unused:
6969
);
7070

7171
// Safe because we're terminating the process anyway. We don't actually do anything when
72-
// running unit tests.
72+
// running unit test_cases.
7373
#[cfg(not(test))]
7474
unsafe {
7575
_exit(i32::from(match si_signo {

0 commit comments

Comments
 (0)