Skip to content

Commit 354dd56

Browse files
stefano-garzarellajiangliu
authored andcommitted
vhost_kern/vdpa: skip tests if device is not found
vDPA simulators are available since Linux 5.7. The CI may have an older kernel, so to avoid CI failures, for now we skip the tests if we don't find the device. Signed-off-by: Stefano Garzarella <[email protected]>
1 parent 82d1a3c commit 354dd56

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/vhost_kern/vdpa.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,33 @@ mod tests {
207207
VhostBackend, VhostUserDirtyLogRegion, VhostUserMemoryRegionInfo, VringConfigData,
208208
};
209209
use serial_test::serial;
210+
use std::io::ErrorKind;
211+
212+
/// macro to skip test if vhost-vdpa device path is not found.
213+
///
214+
/// vDPA simulators are available since Linux 5.7, but the CI may have
215+
/// an older kernel, so for now we skip the test if we don't find
216+
/// the device.
217+
macro_rules! unwrap_not_found {
218+
( $e:expr ) => {
219+
match $e {
220+
Ok(v) => v,
221+
Err(error) => match error {
222+
Error::VhostOpen(ref e) if e.kind() == ErrorKind::NotFound => {
223+
println!("Err: {:?} SKIPPED", e);
224+
return;
225+
}
226+
e => panic!("Err: {:?}", e),
227+
},
228+
}
229+
};
230+
}
210231

211232
#[test]
212233
#[serial]
213234
fn test_vdpa_kern_new_device() {
214235
let m = GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x10_0000)]).unwrap();
215-
let vdpa = VhostKernVdpa::new(VHOST_VDPA_PATH, &m).unwrap();
236+
let vdpa = unwrap_not_found!(VhostKernVdpa::new(VHOST_VDPA_PATH, &m));
216237

217238
assert!(vdpa.as_raw_fd() >= 0);
218239
assert!(vdpa.mem().find_region(GuestAddress(0x100)).is_some());
@@ -223,7 +244,7 @@ mod tests {
223244
#[serial]
224245
fn test_vdpa_kern_is_valid() {
225246
let m = GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x10_0000)]).unwrap();
226-
let vdpa = VhostKernVdpa::new(VHOST_VDPA_PATH, &m).unwrap();
247+
let vdpa = unwrap_not_found!(VhostKernVdpa::new(VHOST_VDPA_PATH, &m));
227248

228249
let mut config = VringConfigData {
229250
queue_max_size: 32,
@@ -248,7 +269,7 @@ mod tests {
248269
#[serial]
249270
fn test_vdpa_kern_ioctls() {
250271
let m = GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x10_0000)]).unwrap();
251-
let vdpa = VhostKernVdpa::new(VHOST_VDPA_PATH, &m).unwrap();
272+
let vdpa = unwrap_not_found!(VhostKernVdpa::new(VHOST_VDPA_PATH, &m));
252273

253274
let features = vdpa.get_features().unwrap();
254275
// VIRTIO_F_VERSION_1 (bit 32) should be set
@@ -325,7 +346,7 @@ mod tests {
325346
#[serial]
326347
fn test_vdpa_kern_dma() {
327348
let m = GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x10_0000)]).unwrap();
328-
let mut vdpa = VhostKernVdpa::new(VHOST_VDPA_PATH, &m).unwrap();
349+
let mut vdpa = unwrap_not_found!(VhostKernVdpa::new(VHOST_VDPA_PATH, &m));
329350

330351
let features = vdpa.get_features().unwrap();
331352
// VIRTIO_F_VERSION_1 (bit 32) should be set

0 commit comments

Comments
 (0)