MCPcopy Index your code
hub / github.com/cloud-hypervisor/cloud-hypervisor / add_capability

Function add_capability

pci/src/configuration.rs:1266–1309  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1264
1265 #[test]
1266 fn add_capability() {
1267 let mut cfg = PciConfiguration::new(
1268 0x1234,
1269 0x5678,
1270 0x1,
1271 PciClassCode::MultimediaController,
1272 &PciMultimediaSubclass::AudioController,
1273 None,
1274 PciHeaderType::Device,
1275 0xABCD,
1276 0x2468,
1277 None,
1278 None,
1279 );
1280
1281 // Add two capabilities with different contents.
1282 let cap1 = TestCap { len: 4, foo: 0xAA };
1283 let cap1_offset = cfg.add_capability(&cap1).unwrap();
1284 assert_eq!(cap1_offset % 4, 0);
1285
1286 let cap2 = TestCap {
1287 len: 0x04,
1288 foo: 0x55,
1289 };
1290 let cap2_offset = cfg.add_capability(&cap2).unwrap();
1291 assert_eq!(cap2_offset % 4, 0);
1292
1293 // The capability list head should be pointing to cap1.
1294 let cap_ptr = cfg.read_reg(CAPABILITY_LIST_HEAD_OFFSET / 4) & 0xFF;
1295 assert_eq!(cap1_offset, cap_ptr as usize);
1296
1297 // Verify the contents of the capabilities.
1298 let cap1_data = cfg.read_reg(cap1_offset / 4);
1299 assert_eq!(cap1_data & 0xFF, 0x09); // capability ID
1300 assert_eq!((cap1_data >> 8) & 0xFF, cap2_offset as u32); // next capability pointer
1301 assert_eq!((cap1_data >> 16) & 0xFF, 0x04); // cap1.len
1302 assert_eq!((cap1_data >> 24) & 0xFF, 0xAA); // cap1.foo
1303
1304 let cap2_data = cfg.read_reg(cap2_offset / 4);
1305 assert_eq!(cap2_data & 0xFF, 0x09); // capability ID
1306 assert_eq!((cap2_data >> 8) & 0xFF, 0x00); // next capability pointer
1307 assert_eq!((cap2_data >> 16) & 0xFF, 0x04); // cap2.len
1308 assert_eq!((cap2_data >> 24) & 0xFF, 0x55); // cap2.foo
1309 }
1310
1311 #[derive(Copy, Clone)]
1312 enum TestPi {

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
add_capabilityMethod · 0.80
read_regMethod · 0.45

Tested by

no test coverage detected