Add integration tests that just try to create a device using uinput using bubblewrap. No further checks.

This commit is contained in:
Johannes Leupolz 2025-12-14 21:22:09 +00:00
parent 8784475eda
commit e4335df8e6
2 changed files with 54 additions and 3 deletions

View file

@ -118,6 +118,11 @@ impl BwrapBuilder {
self
}
pub fn dev_bind(mut self, src: &str, dst: &str) -> Self {
self.args.extend(["--dev-bind".into(), src.into(), dst.into()]);
self
}
/// Ensure the container dies if the parent dies.
///
/// This uses bwrap's `--die-with-parent` flag, which internally

View file

@ -8,8 +8,6 @@ use vuinputd_tests::bwrap;
#[cfg(all(feature = "requires-root", feature = "requires-bwrap"))]
#[test]
fn test_bwrap_simple() {
use std::vec;
let out = bwrap::BwrapBuilder::new()
.unshare_all()
.ro_bind("/", "/")
@ -60,9 +58,10 @@ fn test_bwrap_ipc() {
}
#[cfg(all(feature = "requires-root", feature = "requires-uinput"))]
#[test]
fn test_keyboard_in_container() {
fn test_keyboard_on_host() {
let keyboard_in_container = env!("CARGO_BIN_EXE_keyboard-in-container");
let status = Command::new(keyboard_in_container)
@ -71,3 +70,50 @@ fn test_keyboard_in_container() {
assert!(status.success());
}
#[cfg(all(feature = "requires-root", feature = "requires-uinput", feature = "requires-bwrap"))]
#[test]
fn test_keyboard_in_container_with_uinput() {
let keyboard_in_container = env!("CARGO_BIN_EXE_keyboard-in-container");
let out = bwrap::BwrapBuilder::new()
.unshare_net()
.ro_bind("/", "/")
.tmpfs("/tmp")
.dev_bind("/dev/uinput", "/dev/uinput")
.die_with_parent()
.command(keyboard_in_container,&[])
.run()
.unwrap_or_else(|e| panic!("failed to run bwrap!: {e}"));
println!("Output");
println!("stdout: {}", str::from_utf8(&out.stdout).unwrap());
println!("stderr: {}", str::from_utf8(&out.stderr).unwrap());
assert!(out.status.success());
}
#[cfg(all(feature = "requires-root", feature = "requires-uinput", feature = "requires-bwrap"))]
#[ignore]
#[test]
fn test_keyboard_in_container_with_vuinput() {
println!("Note that vuinputd needs to run for this test");
let keyboard_in_container = env!("CARGO_BIN_EXE_keyboard-in-container");
let out = bwrap::BwrapBuilder::new()
.unshare_net()
.ro_bind("/", "/")
.tmpfs("/tmp")
.dev_bind("/dev/vuinput", "/dev/uinput")
.die_with_parent()
.command(keyboard_in_container,&[])
.run()
.unwrap_or_else(|e| panic!("failed to run bwrap!: {e}"));
println!("Output");
println!("stdout: {}", str::from_utf8(&out.stdout).unwrap());
println!("stderr: {}", str::from_utf8(&out.stderr).unwrap());
assert!(out.status.success());
}