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>
This commit is contained in:
Dylan Reid 2019-03-02 03:39:47 +00:00 committed by chrome-bot
parent 2de0088c9e
commit e4ece32798

View file

@ -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());
}
}