From 971a49e94608a55c23977fb8cd6dac38de341f66 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 17 Mar 2022 17:08:31 -0700 Subject: [PATCH] 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 Tested-by: kokoro Commit-Queue: Daniel Verkamp --- devices/src/pci/pci_address.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/devices/src/pci/pci_address.rs b/devices/src/pci/pci_address.rs index ef4d9e7b03..f632d1188a 100644 --- a/devices/src/pci/pci_address.rs +++ b/devices/src/pci/pci_address.rs @@ -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" + ); + } }