()
| 428 | |
| 429 | #[test] |
| 430 | fn test_register_deregister_refcount() { |
| 431 | let _refcount_guard = test_refcounts::guard(); |
| 432 | test_refcounts::clear("10de 26b8"); |
| 433 | let (tmp, sysfs) = setup_mock_sysfs(); |
| 434 | |
| 435 | create_pci_device( |
| 436 | &sysfs, |
| 437 | tmp.path(), |
| 438 | "0000:2d:00.0", |
| 439 | "0x10de", |
| 440 | "0x26b8", |
| 441 | "0x030000", |
| 442 | 42, |
| 443 | ); |
| 444 | create_pci_device( |
| 445 | &sysfs, |
| 446 | tmp.path(), |
| 447 | "0000:3b:00.0", |
| 448 | "0x10de", |
| 449 | "0x26b8", |
| 450 | "0x030200", |
| 451 | 43, |
| 452 | ); |
| 453 | create_new_id_file(&sysfs); |
| 454 | create_remove_id_file(&sysfs); |
| 455 | |
| 456 | register_vfio_new_id(&sysfs, "0000:2d:00.0"); |
| 457 | let written = fs::read_to_string(sysfs.vfio_pci_new_id()).unwrap(); |
| 458 | assert_eq!( |
| 459 | written, "10de 26b8", |
| 460 | "first register should write to new_id" |
| 461 | ); |
| 462 | |
| 463 | fs::write(sysfs.vfio_pci_new_id(), "").unwrap(); |
| 464 | register_vfio_new_id(&sysfs, "0000:3b:00.0"); |
| 465 | let written = fs::read_to_string(sysfs.vfio_pci_new_id()).unwrap(); |
| 466 | assert_eq!( |
| 467 | written, "", |
| 468 | "second register should not write to new_id when refcount > 1" |
| 469 | ); |
| 470 | |
| 471 | deregister_vfio_new_id(&sysfs, "0000:2d:00.0"); |
| 472 | let written = fs::read_to_string(sysfs.vfio_pci_remove_id()).unwrap(); |
| 473 | assert_eq!( |
| 474 | written, "", |
| 475 | "first deregister should not write to remove_id" |
| 476 | ); |
| 477 | |
| 478 | deregister_vfio_new_id(&sysfs, "0000:3b:00.0"); |
| 479 | let written = fs::read_to_string(sysfs.vfio_pci_remove_id()).unwrap(); |
| 480 | assert_eq!( |
| 481 | written, "10de 26b8", |
| 482 | "second deregister should write to remove_id" |
| 483 | ); |
| 484 | } |
| 485 | |
| 486 | #[test] |
| 487 | fn test_deregister_by_cached_value_updates_refcount() { |
nothing calls this directly
no test coverage detected