Skip to content

Commit 0af5bd4

Browse files
rparolinclaude
andcommitted
test(cuda.core): cover AccessedBySet read methods (N7)
Per Leo's review on PR #1775 (test_managed_ops.py:1), add a test for the read side of AccessedBySet: __iter__, __len__, __eq__, __repr__. These are part of the public set-like API (alongside __contains__, add(), discard(), and the setter, which are already covered) but were untested. The cu12 batch fallback path (Leo's other coverage point) is now exercised by TestPrefetchBatch.test_same_location and test_per_buffer_location running on cu12 CI — the cuMemPrefetchBatchAsync skip was dropped in d75a7bd when the fallback landed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d75a7bd commit 0af5bd4

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎cuda_core/tests/memory/test_managed_ops.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,33 @@ def test_accessed_by_add_discard(self, init_cuda):
595595
finally:
596596
plain.close()
597597

598+
def test_accessed_by_read_methods(self, init_cuda):
599+
"""Cover __iter__, __len__, __eq__, __repr__ on AccessedBySet."""
600+
device = Device()
601+
_skip_if_managed_location_ops_unsupported(device)
602+
device.set_current()
603+
plain = DummyUnifiedMemoryResource(device).allocate(_MANAGED_TEST_ALLOCATION_SIZE)
604+
try:
605+
buf = ManagedBuffer.from_handle(plain.handle, plain.size, owner=plain)
606+
607+
# Empty initially
608+
assert len(buf.accessed_by) == 0
609+
assert list(buf.accessed_by) == []
610+
assert buf.accessed_by == set()
611+
assert "AccessedBySet" in repr(buf.accessed_by)
612+
613+
# After add
614+
buf.accessed_by.add(device)
615+
assert len(buf.accessed_by) == 1
616+
assert list(buf.accessed_by) == [device]
617+
assert buf.accessed_by == {device}
618+
assert buf.accessed_by != frozenset()
619+
620+
# __eq__ vs another AccessedBySet on the same buffer
621+
assert buf.accessed_by == buf.accessed_by
622+
finally:
623+
plain.close()
624+
598625
def test_accessed_by_set_assignment(self, init_cuda):
599626
device = Device()
600627
_skip_if_managed_location_ops_unsupported(device)

0 commit comments

Comments
 (0)