src/devices/bus/drivers/pci/test/unit/device_tests.cc
// This test checks for proper handling of capability pointers that are
// invalid by pointing to inside the config header.
This test checks for proper handling of capability pointers that are
invalid by pointing to inside the config header.
This test checks for proper handling of capability pointers that are invalid by pointing to inside the config header .
TEST_F(PciDeviceTests, InvalidPtrCapabilityTest) {
  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 kInvalidCap = 0x10;
  fake_dev.set_vendor_id(0x8086)
      .set_device_id(0x1234)
      .set_capabilities_list(1)
      .set_capabilities_ptr(kCap1);
  raw_cfg[kCap1] = static_cast<uint8_t>(Capability::Id::kPciPowerManagement);
  raw_cfg[kCap1 + 1] = kCap2;
  raw_cfg[kCap2] = static_cast<uint8_t>(Capability::Id::kMsiX);
  raw_cfg[kCap2 + 1] = kInvalidCap;
  std::unique_ptr<Config> cfg;
  ASSERT_OK(MmioConfig::Create(default_bdf(), &pciroot_proto().ecam().mmio(), 0, 1, &cfg));
  EXPECT_EQ(ZX_ERR_OUT_OF_RANGE,
            Device::Create(fake_ddk::kFakeParent, std::move(cfg), &upstream(), &bus()));
  EXPECT_TRUE(bus().devices().is_empty());
}
TEST_F ( PciDeviceTests , InvalidPtrCapabilityTest ) { 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 kInvalidCap = 0x10 ; fake_dev . set_vendor_id ( 0x8086 ) . set_device_id ( 0x1234 ) . set_capabilities_list ( 1 ) . set_capabilities_ptr ( kCap1 ) ; raw_cfg [ kCap1 ] = static_cast < uint8_t > ( Capability :: Id :: kPciPowerManagement ) ; raw_cfg [ kCap1 + 1 ] = kCap2 ; raw_cfg [ kCap2 ] = static_cast < uint8_t > ( Capability :: Id :: kMsiX ) ; raw_cfg [ kCap2 + 1 ] = kInvalidCap ; std :: unique_ptr < Config > cfg ; ASSERT_OK ( MmioConfig :: Create ( default_bdf ( ) , & pciroot_proto ( ) . ecam ( ) . mmio ( ) , 0 , 1 , & cfg ) ) ; EXPECT_EQ ( ZX_ERR_OUT_OF_RANGE , Device :: Create ( fake_ddk :: kFakeParent , std :: move ( cfg ) , & upstream ( ) , & bus ( ) ) ) ; EXPECT_TRUE ( bus ( ) . devices ( ) . is_empty ( ) ) ; }
This test checks for proper handling of capability pointers that are
invalid by pointing to inside the config header.
This test checks for proper handling of capability pointers that are invalid by pointing to inside the config header .
// Two valid locations, followed by a third capability pointing at BAR 1. // Point to 0x80 as the first capability. // Ensure no device was added.