Skip to content

Commit 64c309e

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 c33415a commit 64c309e

File tree

5 files changed

+972
-3
lines changed

5 files changed

+972
-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
@@ -190,3 +190,63 @@ impl<M: GuestMemory> IoMemory for M {
190190
Some(self)
191191
}
192192
}
193+
194+
#[cfg(test)]
195+
mod tests {
196+
use super::Permissions;
197+
198+
// Note that `IoMemory` is tested primarily in src/iommu.rs via `IommuMemory`.
199+
200+
/// Test `Permissions & Permissions`.
201+
#[test]
202+
fn test_perm_and() {
203+
use Permissions::*;
204+
205+
for p in [No, Read, Write, ReadWrite] {
206+
assert_eq!(p & p, p);
207+
}
208+
for p1 in [No, Read, Write, ReadWrite] {
209+
for p2 in [No, Read, Write, ReadWrite] {
210+
assert_eq!(p1 & p2, p2 & p1);
211+
}
212+
}
213+
for p in [No, Read, Write, ReadWrite] {
214+
assert_eq!(No & p, No);
215+
}
216+
for p in [No, Read, Write, ReadWrite] {
217+
assert_eq!(ReadWrite & p, p);
218+
}
219+
assert_eq!(Read & Write, No);
220+
}
221+
222+
/// Test `Permissions | Permissions`.
223+
#[test]
224+
fn test_perm_or() {
225+
use Permissions::*;
226+
227+
for p in [No, Read, Write, ReadWrite] {
228+
assert_eq!(p | p, p);
229+
}
230+
for p1 in [No, Read, Write, ReadWrite] {
231+
for p2 in [No, Read, Write, ReadWrite] {
232+
assert_eq!(p1 | p2, p2 | p1);
233+
}
234+
}
235+
for p in [No, Read, Write, ReadWrite] {
236+
assert_eq!(No | p, p);
237+
}
238+
for p in [No, Read, Write, ReadWrite] {
239+
assert_eq!(ReadWrite | p, ReadWrite);
240+
}
241+
assert_eq!(Read | Write, ReadWrite);
242+
}
243+
244+
/// Test `Permissions::has_write()`.
245+
#[test]
246+
fn test_perm_has_write() {
247+
assert!(!Permissions::No.has_write());
248+
assert!(!Permissions::Read.has_write());
249+
assert!(Permissions::Write.has_write());
250+
assert!(Permissions::ReadWrite.has_write());
251+
}
252+
}

0 commit comments

Comments
 (0)