Skip to content

Commit a5540fc

Browse files
committed
Add tests for IOMMU functionality
This commit also adds the iommu feature to the coverage_config feature list. (I left the aarch64 coverage value unchanged; I cannot find out how to get the current value on my system, and it isn’t include in CI.) Signed-off-by: Hanna Czenczek <[email protected]>
1 parent 5fa263d commit a5540fc

File tree

5 files changed

+976
-3
lines changed

5 files changed

+976
-3
lines changed

coverage_config_aarch64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"coverage_score": 85.2,
33
"exclude_path": "mmap/windows.rs",
4-
"crate_features": "backend-mmap,backend-atomic,backend-bitmap"
4+
"crate_features": "backend-mmap,backend-atomic,backend-bitmap,iommu"
55
}

coverage_config_x86_64.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 91.78,
2+
"coverage_score": 92.48,
33
"exclude_path": "mmap_windows.rs",
4-
"crate_features": "backend-mmap,backend-atomic,backend-bitmap"
4+
"crate_features": "backend-mmap,backend-atomic,backend-bitmap,iommu"
55
}

src/io_memory.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,63 @@ impl<M: GuestMemory + ?Sized> IoMemory for M {
209209
Some(self)
210210
}
211211
}
212+
213+
#[cfg(test)]
214+
mod tests {
215+
use super::Permissions;
216+
217+
// Note that `IoMemory` is tested primarily in src/iommu.rs via `IommuMemory`.
218+
219+
/// Test `Permissions & Permissions`.
220+
#[test]
221+
fn test_perm_and() {
222+
use Permissions::*;
223+
224+
for p in [No, Read, Write, ReadWrite] {
225+
assert_eq!(p & p, p);
226+
}
227+
for p1 in [No, Read, Write, ReadWrite] {
228+
for p2 in [No, Read, Write, ReadWrite] {
229+
assert_eq!(p1 & p2, p2 & p1);
230+
}
231+
}
232+
for p in [No, Read, Write, ReadWrite] {
233+
assert_eq!(No & p, No);
234+
}
235+
for p in [No, Read, Write, ReadWrite] {
236+
assert_eq!(ReadWrite & p, p);
237+
}
238+
assert_eq!(Read & Write, No);
239+
}
240+
241+
/// Test `Permissions | Permissions`.
242+
#[test]
243+
fn test_perm_or() {
244+
use Permissions::*;
245+
246+
for p in [No, Read, Write, ReadWrite] {
247+
assert_eq!(p | p, p);
248+
}
249+
for p1 in [No, Read, Write, ReadWrite] {
250+
for p2 in [No, Read, Write, ReadWrite] {
251+
assert_eq!(p1 | p2, p2 | p1);
252+
}
253+
}
254+
for p in [No, Read, Write, ReadWrite] {
255+
assert_eq!(No | p, p);
256+
}
257+
for p in [No, Read, Write, ReadWrite] {
258+
assert_eq!(ReadWrite | p, ReadWrite);
259+
}
260+
assert_eq!(Read | Write, ReadWrite);
261+
}
262+
263+
/// Test `Permissions::has_write()`.
264+
#[test]
265+
fn test_perm_has_write() {
266+
assert!(!Permissions::No.has_write());
267+
assert!(!Permissions::Read.has_write());
268+
assert!(Permissions::Write.has_write());
269+
assert!(Permissions::ReadWrite.has_write());
270+
}
271+
}

0 commit comments

Comments
 (0)