devices: pci: add domain to PciAddress fmt output

This was accidentally omitted in the original change. Add some basic
tests to make sure it doesn't regress.

BUG=None
TEST=cargo test -p devices pci_address

Change-Id: Iaedf2357ae02d6203e8296e9765f5ce3bf5bdc84
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3534507
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2022-03-17 17:08:31 -07:00 committed by Chromeos LUCI
parent 67e64f7810
commit 971a49e946

View file

@ -41,7 +41,12 @@ pub struct PciAddress {
impl Display for PciAddress {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:04x}:{:02x}.{:0x}", self.bus, self.dev, self.func)
let domain = 0;
write!(
f,
"{:04x}:{:02x}:{:02x}.{:0x}",
domain, self.bus, self.dev, self.func,
)
}
}
@ -284,4 +289,20 @@ mod tests {
Error::ComponentOutOfRange(PciAddressComponent::Domain)
);
}
#[test]
fn format_simple() {
assert_eq!(
PciAddress::new(0, 1, 2, 3).unwrap().to_string(),
"0000:01:02.3"
);
}
#[test]
fn format_max() {
assert_eq!(
PciAddress::new(0, 0xff, 0x1f, 7).unwrap().to_string(),
"0000:ff:1f.7"
);
}
}