Skip to content

Commit 3e444c0

Browse files
committed
wip
Signed-off-by: Matej Hrica <mhrica@redhat.com>
1 parent fb19b1b commit 3e444c0

File tree

9 files changed

+90
-34
lines changed

9 files changed

+90
-34
lines changed

tests/runner/src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use std::panic::catch_unwind;
88
use std::path::{Path, PathBuf};
99
use std::process::{Command, Stdio};
1010
use tempdir::TempDir;
11-
use test_cases::{test_cases, rootfs_images, Report, ShouldRun, Test, TestCase, TestOutcome, TestSetup};
11+
use test_cases::{
12+
rootfs_images, test_cases, Report, ShouldRun, Test, TestCase, TestOutcome, TestSetup,
13+
};
1214

1315
struct TestResult {
1416
name: String,
@@ -328,8 +330,10 @@ fn build_images() -> anyhow::Result<()> {
328330

329331
for (name, _) in rootfs_images() {
330332
eprint!("Building rootfs image {name}...");
331-
rootfs::build_rootfs(name)?;
332-
eprintln!(" done");
333+
match rootfs::build_rootfs(name) {
334+
Ok(()) => eprintln!(" done"),
335+
Err(e) => eprintln!(" skipped ({e})"),
336+
}
333337
}
334338
Ok(())
335339
}

tests/test_cases/src/common.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ pub fn setup_existing_rootfs_and_enter(
5858
test_setup: TestSetup,
5959
rootfs_dir: &Path,
6060
) -> anyhow::Result<()> {
61-
anyhow::ensure!(rootfs_dir.is_dir(), "rootfs directory not found: {}", rootfs_dir.display());
61+
anyhow::ensure!(
62+
rootfs_dir.is_dir(),
63+
"rootfs directory not found: {}",
64+
rootfs_dir.display()
65+
);
6266
let path_str = CString::new(rootfs_dir.as_os_str().as_bytes()).context("CString::new")?;
6367
copy_guest_agent(rootfs_dir)?;
6468
unsafe {

tests/test_cases/src/lib.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,44 @@ pub fn test_cases() -> Vec<TestCase> {
7272
TestCase::new("net-tap", Box::new(TestNet::new_tap())),
7373
TestCase::new("net-gvproxy", Box::new(TestNet::new_gvproxy())),
7474
TestCase::new("multiport-console", Box::new(TestMultiportConsole)),
75-
TestCase::new("perf-net-passt-upload", Box::new(TestNetPerf::new_passt_upload())),
76-
TestCase::new("perf-net-passt-download", Box::new(TestNetPerf::new_passt_download())),
77-
TestCase::new("perf-net-tap-upload", Box::new(TestNetPerf::new_tap_upload())),
78-
TestCase::new("perf-net-tap-download", Box::new(TestNetPerf::new_tap_download())),
79-
TestCase::new("perf-net-gvproxy-upload", Box::new(TestNetPerf::new_gvproxy_upload())),
80-
TestCase::new("perf-net-gvproxy-download", Box::new(TestNetPerf::new_gvproxy_download())),
75+
TestCase::new(
76+
"perf-net-passt-upload",
77+
Box::new(TestNetPerf::new_passt_upload()),
78+
),
79+
TestCase::new(
80+
"perf-net-passt-download",
81+
Box::new(TestNetPerf::new_passt_download()),
82+
),
83+
TestCase::new(
84+
"perf-net-tap-upload",
85+
Box::new(TestNetPerf::new_tap_upload()),
86+
),
87+
TestCase::new(
88+
"perf-net-tap-download",
89+
Box::new(TestNetPerf::new_tap_download()),
90+
),
91+
TestCase::new(
92+
"perf-net-gvproxy-upload",
93+
Box::new(TestNetPerf::new_gvproxy_upload()),
94+
),
95+
TestCase::new(
96+
"perf-net-gvproxy-download",
97+
Box::new(TestNetPerf::new_gvproxy_download()),
98+
),
8199
]
82100
}
83101

84102
/// Registry of container images used by tests.
85103
/// Each entry maps a name to a Containerfile that will be built and cached via podman.
86104
#[host]
87105
pub fn rootfs_images() -> &'static [(&'static str, &'static str)] {
88-
&[
89-
("fedora-iperf3", "\
106+
&[(
107+
"fedora-iperf3",
108+
"\
90109
FROM fedora:43
91110
RUN dnf install -y iperf3 && dnf clean all
92-
"),
93-
]
111+
",
112+
)]
94113
}
95114

96115
////////////////////

tests/test_cases/src/net_config.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ pub fn make_sockaddr_in(ip: [u8; 4]) -> nix::libc::sockaddr {
5959

6060
/// Configure a network interface with IP address and netmask, and bring it UP
6161
pub fn configure_interface(name: &str, ip: [u8; 4], netmask: [u8; 4]) -> nix::Result<()> {
62-
let sock = socket(AddressFamily::Inet, SockType::Datagram, SockFlag::empty(), None)?;
62+
let sock = socket(
63+
AddressFamily::Inet,
64+
SockType::Datagram,
65+
SockFlag::empty(),
66+
None,
67+
)?;
6368
let fd = sock.as_raw_fd();
6469

6570
// Set IP address

tests/test_cases/src/rootfs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ pub fn build_rootfs(name: &str) -> anyhow::Result<()> {
6666
.write_all(containerfile.as_bytes())
6767
.context("writing containerfile to podman stdin")?;
6868

69-
let output = build.wait_with_output().context("waiting for podman build")?;
69+
let output = build
70+
.wait_with_output()
71+
.context("waiting for podman build")?;
7072
if !output.status.success() {
7173
let stderr = String::from_utf8_lossy(&output.stderr);
7274
bail!("podman build failed: {stderr}");

tests/test_cases/src/test_net/gvproxy.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ fn gvproxy_path() -> Option<String> {
3939
.ok()
4040
.and_then(|o| {
4141
if o.status.success() {
42-
String::from_utf8(o.stdout).ok().map(|s| s.trim().to_string())
42+
String::from_utf8(o.stdout)
43+
.ok()
44+
.map(|s| s.trim().to_string())
4345
} else {
4446
None
4547
}
@@ -101,10 +103,7 @@ pub(crate) fn setup_backend(ctx: u32, test_setup: &TestSetup) -> anyhow::Result<
101103
let socket_path = tmp_dir.join("gvproxy.sock");
102104
let gvproxy_log = tmp_dir.join("gvproxy.log");
103105

104-
let _gvproxy_child = start_gvproxy(
105-
socket_path.to_str().unwrap(),
106-
&gvproxy_log,
107-
)?;
106+
let _gvproxy_child = start_gvproxy(socket_path.to_str().unwrap(), &gvproxy_log)?;
108107

109108
anyhow::ensure!(
110109
wait_for_socket(&socket_path, 5000),

tests/test_cases/src/test_net/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use macros::{guest, host};
1111
#[host]
1212
use crate::{ShouldRun, TestSetup};
1313

14+
#[cfg(feature = "host")]
15+
pub(crate) mod gvproxy;
1416
#[cfg(feature = "host")]
1517
pub(crate) mod passt;
1618
#[cfg(feature = "host")]
1719
pub(crate) mod tap;
18-
#[cfg(feature = "host")]
19-
pub(crate) mod gvproxy;
2020

2121
/// Virtio-net test with configurable backend
2222
pub struct TestNet {
@@ -93,7 +93,8 @@ mod host {
9393

9494
impl Test for TestNet {
9595
fn should_run(&self) -> ShouldRun {
96-
if unsafe { krun_call_u32!(krun_has_feature(KRUN_FEATURE_NET.into())) }.ok() != Some(1) {
96+
if unsafe { krun_call_u32!(krun_has_feature(KRUN_FEATURE_NET.into())) }.ok() != Some(1)
97+
{
9798
return ShouldRun::No("libkrun compiled without NET");
9899
}
99100
(self.should_run)()
@@ -148,8 +149,12 @@ mod guest {
148149
}
149150

150151
fn set_timeouts(stream: &mut TcpStream) {
151-
stream.set_read_timeout(Some(Duration::from_secs(10))).unwrap();
152-
stream.set_write_timeout(Some(Duration::from_secs(10))).unwrap();
152+
stream
153+
.set_read_timeout(Some(Duration::from_secs(10)))
154+
.unwrap();
155+
stream
156+
.set_write_timeout(Some(Duration::from_secs(10)))
157+
.unwrap();
153158
}
154159

155160
impl Test for TestNet {
@@ -161,7 +166,9 @@ mod guest {
161166
// Connect to host TCP server
162167
let host_ip = self.host_ip;
163168
let addr = SocketAddr::new(
164-
IpAddr::V4(Ipv4Addr::new(host_ip[0], host_ip[1], host_ip[2], host_ip[3])),
169+
IpAddr::V4(Ipv4Addr::new(
170+
host_ip[0], host_ip[1], host_ip[2], host_ip[3],
171+
)),
165172
self.port,
166173
);
167174

tests/test_cases/src/test_net/tap.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ fn make_sockaddr_in(ip: [u8; 4]) -> libc::sockaddr {
7777
}
7878

7979
fn create_tap(name: &str) -> std::io::Result<()> {
80-
let tun = OpenOptions::new().read(true).write(true).open("/dev/net/tun")?;
80+
let tun = OpenOptions::new()
81+
.read(true)
82+
.write(true)
83+
.open("/dev/net/tun")?;
8184
let mut ifr: Ifreq = unsafe { std::mem::zeroed() };
8285
set_interface_name(&mut ifr, name);
8386
ifr.ifr_ifru.ifru_flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR;
@@ -89,7 +92,12 @@ fn create_tap(name: &str) -> std::io::Result<()> {
8992
}
9093

9194
fn configure_host_interface(name: &str, ip: [u8; 4], netmask: [u8; 4]) -> nix::Result<()> {
92-
let sock = socket(AddressFamily::Inet, SockType::Datagram, SockFlag::empty(), None)?;
95+
let sock = socket(
96+
AddressFamily::Inet,
97+
SockType::Datagram,
98+
SockFlag::empty(),
99+
None,
100+
)?;
93101
let fd = sock.as_raw_fd();
94102

95103
let mut ifr: Ifreq = unsafe { std::mem::zeroed() };
@@ -126,7 +134,11 @@ pub(crate) fn should_run() -> ShouldRun {
126134
}
127135

128136
pub(crate) fn cleanup() {
129-
if let Ok(tun) = OpenOptions::new().read(true).write(true).open("/dev/net/tun") {
137+
if let Ok(tun) = OpenOptions::new()
138+
.read(true)
139+
.write(true)
140+
.open("/dev/net/tun")
141+
{
130142
let mut ifr: Ifreq = unsafe { std::mem::zeroed() };
131143
set_interface_name(&mut ifr, DEFAULT_TAP_NAME);
132144
ifr.ifr_ifru.ifru_flags = IFF_TAP | IFF_NO_PI;

tests/test_cases/src/test_net_perf/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ mod host {
212212
fn fmt_text(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
213213
let i = f.width().unwrap_or(0);
214214
writeln!(f, "{:i$}iperf3 — {}\n", "", self.label())?;
215-
writeln!(f, "{:i$}{:<9} {:>18} {:>14}", "", "Interval", "Throughput", "Transferred")?;
215+
writeln!(
216+
f,
217+
"{:i$}{:<9} {:>18} {:>14}",
218+
"", "Interval", "Throughput", "Transferred"
219+
)?;
216220
writeln!(f, "{:i$}{:-<9} {:-<18} {:-<14}", "", "", "", "")?;
217221
for interval in &self.output.intervals {
218222
let s = &interval.sum;
@@ -268,7 +272,8 @@ mod host {
268272
if option_env!("IPERF_DURATION").is_none() {
269273
return ShouldRun::No("IPERF_DURATION not set");
270274
}
271-
if unsafe { krun_call_u32!(krun_has_feature(KRUN_FEATURE_NET.into())) }.ok() != Some(1) {
275+
if unsafe { krun_call_u32!(krun_has_feature(KRUN_FEATURE_NET.into())) }.ok() != Some(1)
276+
{
272277
return ShouldRun::No("libkrun compiled without NET");
273278
}
274279
let backend_result = (self.should_run)();
@@ -376,8 +381,7 @@ mod guest {
376381

377382
if output.status.success() {
378383
// Print JSON output to stdout (host will read it)
379-
let stdout =
380-
String::from_utf8(output.stdout).expect("iperf3 output not UTF-8");
384+
let stdout = String::from_utf8(output.stdout).expect("iperf3 output not UTF-8");
381385
print!("{}", stdout);
382386
return;
383387
}

0 commit comments

Comments
 (0)