summary refs log tree commit diff
path: root/devices
diff options
context:
space:
mode:
authorDylan Reid <dgreid@chromium.org>2019-03-02 03:39:47 +0000
committerchrome-bot <chrome-bot@chromium.org>2019-03-04 17:44:58 -0800
commite4ece32798ba436fbfa88466c571f46dab99e2be (patch)
tree0f40e73a34934faf582cb92908e1d1e4b006361b /devices
parent2de0088c9eda27fd68a17736228199b4d97de409 (diff)
downloadcrosvm-e4ece32798ba436fbfa88466c571f46dab99e2be.tar
crosvm-e4ece32798ba436fbfa88466c571f46dab99e2be.tar.gz
crosvm-e4ece32798ba436fbfa88466c571f46dab99e2be.tar.bz2
crosvm-e4ece32798ba436fbfa88466c571f46dab99e2be.tar.lz
crosvm-e4ece32798ba436fbfa88466c571f46dab99e2be.tar.xz
crosvm-e4ece32798ba436fbfa88466c571f46dab99e2be.tar.zst
crosvm-e4ece32798ba436fbfa88466c571f46dab99e2be.zip
ac97: Add top level unit test
Check that the device can be created. This test would have caught the
bug with adding pci bars.

Change-Id: Ib0cc2edf0d8d1b2d95d9c3588ac325b5da886603
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1497738
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Diffstat (limited to 'devices')
-rw-r--r--devices/src/pci/ac97.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/devices/src/pci/ac97.rs b/devices/src/pci/ac97.rs
index 29f554f..58fe5b3 100644
--- a/devices/src/pci/ac97.rs
+++ b/devices/src/pci/ac97.rs
@@ -210,3 +210,24 @@ impl PciDevice for Ac97Dev {
         }
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use audio_streams::DummyStreamSource;
+    use resources::AddressRanges;
+    use sys_util::GuestAddress;
+
+    #[test]
+    fn create() {
+        let mem = GuestMemory::new(&[(GuestAddress(0u64), 4 * 1024 * 1024)]).unwrap();
+        let mut ac97_dev = Ac97Dev::new(mem, Box::new(DummyStreamSource::new()));
+        let mut allocator = AddressRanges::new()
+            .add_io_addresses(0x1000_0000, 0x1000_0000)
+            .add_mmio_addresses(0x2000_0000, 0x1000_0000)
+            .add_device_addresses(0x3000_0000, 0x1000_0000)
+            .create_allocator(5, false)
+            .unwrap();
+        assert!(ac97_dev.allocate_io_bars(&mut allocator).is_ok());
+    }
+}