Skip to content
Merged
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
16 changes: 10 additions & 6 deletions src/iommu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,9 @@ where

#[cfg(test)]
mod tests {
use super::{Error, IotlbIterator, IovaRange, MappedRange};
#[cfg(feature = "backend-mmap")]
use super::IotlbIterator;
use super::{Error, IovaRange, MappedRange};
#[cfg(all(feature = "backend-bitmap", feature = "backend-mmap"))]
use crate::bitmap::AtomicBitmap;
#[cfg(feature = "backend-mmap")]
Expand All @@ -670,17 +672,20 @@ mod tests {
use crate::GuestMemoryRegion;
#[cfg(feature = "backend-mmap")]
use crate::{
Bytes, GuestMemoryError, GuestMemoryMmap, GuestMemoryResult, IoMemory, IommuMemory,
Bytes, GuestMemoryError, GuestMemoryMmap, GuestMemoryResult, IoMemory, Iommu, IommuMemory,
};
use crate::{GuestAddress, Iommu, Iotlb, Permissions};
use crate::{GuestAddress, Iotlb, Permissions};
use std::fmt::Debug;
#[cfg(all(feature = "backend-bitmap", feature = "backend-mmap"))]
use std::num::NonZeroUsize;
use std::ops::Deref;
#[cfg(feature = "backend-mmap")]
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
#[cfg(feature = "backend-mmap")]
use std::sync::{RwLock, RwLockReadGuard};

#[derive(Debug)]
#[cfg(feature = "backend-mmap")]
struct SimpleIommu {
iotlb: RwLock<Iotlb>,
/// Records the last fail event's base IOVA
Expand All @@ -693,8 +698,8 @@ mod tests {
next_map_to: AtomicU64,
}

#[cfg(feature = "backend-mmap")]
impl SimpleIommu {
#[cfg(feature = "backend-mmap")]
fn new() -> Self {
SimpleIommu {
iotlb: Iotlb::new().into(),
Expand All @@ -705,22 +710,21 @@ mod tests {
}
}

#[cfg(feature = "backend-mmap")]
fn expect_mapping_request(&self, to_phys: GuestAddress) {
// Clear failed range info so it can be tested after the request
self.fail_base.store(0, Ordering::Relaxed);
self.fail_len.store(0, Ordering::Relaxed);
self.next_map_to.store(to_phys.0, Ordering::Relaxed);
}

#[cfg(feature = "backend-mmap")]
fn verify_mapping_request(&self, virt: GuestAddress, len: usize, was_miss: bool) {
assert_eq!(self.fail_base.load(Ordering::Relaxed), virt.0);
assert_eq!(self.fail_len.load(Ordering::Relaxed), len);
assert_eq!(self.fail_was_miss.load(Ordering::Relaxed), was_miss);
}
}

#[cfg(feature = "backend-mmap")]
impl Iommu for SimpleIommu {
type IotlbGuard<'a> = RwLockReadGuard<'a, Iotlb>;

Expand Down