src/devices/bus/drivers/pci/test/unit/device_tests.cc
// This test checks for proper handling (ZX_ERR_BAD_STATE) upon
// funding a pointer cycle while parsing capabilities.
This test checks for proper handling (ZX_ERR_BAD_STATE) upon
funding a pointer cycle while parsing capabilities.
This test checks for proper handling ( ZX_ERR_BAD_STATE ) upon funding a pointer cycle while parsing capabilities .
TEST_F(PciDeviceTests, PtrCycleCapabilityTest) {
  std::unique_ptr<Config> cfg;
  auto& raw_cfg = pciroot_proto().ecam().get(default_bdf()).config;
  auto& fake_dev = pciroot_proto().ecam().get(default_bdf()).device;
  const uint8_t kCap1 = 0x80;
  const uint8_t kCap2 = 0x90;
  const uint8_t kCap3 = 0xA0;
  fake_dev.set_vendor_id(0x8086)
      .set_device_id(0x1234)
      .set_capabilities_list(1)
      .set_capabilities_ptr(kCap1);
  auto cap_id = static_cast<uint8_t>(Capability::Id::kVendor);
  raw_cfg[kCap1] = cap_id;
  raw_cfg[kCap1 + 1] = kCap2;
  raw_cfg[kCap2] = cap_id;
  raw_cfg[kCap2 + 1] = kCap3;
  raw_cfg[kCap3] = cap_id;
  raw_cfg[kCap3 + 1] = kCap1;
  ASSERT_OK(MmioConfig::Create(default_bdf(), &pciroot_proto().ecam().mmio(), 0, 1, &cfg));
  EXPECT_EQ(ZX_ERR_BAD_STATE,
            Device::Create(fake_ddk::kFakeParent, std::move(cfg), &upstream(), &bus()));
  EXPECT_TRUE(bus().devices().is_empty());
}
TEST_F ( PciDeviceTests , PtrCycleCapabilityTest ) { std :: unique_ptr < Config > cfg ; auto & raw_cfg = pciroot_proto ( ) . ecam ( ) . get ( default_bdf ( ) ) . config ; auto & fake_dev = pciroot_proto ( ) . ecam ( ) . get ( default_bdf ( ) ) . device ; const uint8_t kCap1 = 0x80 ; const uint8_t kCap2 = 0x90 ; const uint8_t kCap3 = 0xA0 ; fake_dev . set_vendor_id ( 0x8086 ) . set_device_id ( 0x1234 ) . set_capabilities_list ( 1 ) . set_capabilities_ptr ( kCap1 ) ; auto cap_id = static_cast < uint8_t > ( Capability :: Id :: kVendor ) ; raw_cfg [ kCap1 ] = cap_id ; raw_cfg [ kCap1 + 1 ] = kCap2 ; raw_cfg [ kCap2 ] = cap_id ; raw_cfg [ kCap2 + 1 ] = kCap3 ; raw_cfg [ kCap3 ] = cap_id ; raw_cfg [ kCap3 + 1 ] = kCap1 ; ASSERT_OK ( MmioConfig :: Create ( default_bdf ( ) , & pciroot_proto ( ) . ecam ( ) . mmio ( ) , 0 , 1 , & cfg ) ) ; EXPECT_EQ ( ZX_ERR_BAD_STATE , Device :: Create ( fake_ddk :: kFakeParent , std :: move ( cfg ) , & upstream ( ) , & bus ( ) ) ) ; EXPECT_TRUE ( bus ( ) . devices ( ) . is_empty ( ) ) ; }
This test checks for proper handling (ZX_ERR_BAD_STATE) upon
funding a pointer cycle while parsing capabilities.
This test checks for proper handling ( ZX_ERR_BAD_STATE ) upon funding a pointer cycle while parsing capabilities .
// Boilerplate to get a device corresponding to the default_bdf(). // Two valid locations, followed by a third capability pointing at BAR 1. // Create a Cycle of Cap1 -> Cap2 -> Cap3 -> Cap1 // Ensure no device was added.