(total_size, chunksize, buffer_size=0)
| 569 | return cbuf, writer |
| 570 | |
| 571 | def test_writes(total_size, chunksize, buffer_size=0): |
| 572 | cbuf, writer = allocate(total_size) |
| 573 | arr, buf = make_random_buffer(size=total_size, target='host') |
| 574 | |
| 575 | if buffer_size > 0: |
| 576 | writer.buffer_size = buffer_size |
| 577 | |
| 578 | position = writer.tell() |
| 579 | assert position == 0 |
| 580 | writer.write(buf.slice(length=chunksize)) |
| 581 | assert writer.tell() == chunksize |
| 582 | writer.seek(0) |
| 583 | position = writer.tell() |
| 584 | assert position == 0 |
| 585 | |
| 586 | while position < total_size: |
| 587 | bytes_to_write = min(chunksize, total_size - position) |
| 588 | writer.write(buf.slice(offset=position, length=bytes_to_write)) |
| 589 | position += bytes_to_write |
| 590 | |
| 591 | writer.flush() |
| 592 | assert cbuf.size == total_size |
| 593 | cbuf.context.synchronize() |
| 594 | buf2 = cbuf.copy_to_host() |
| 595 | cbuf.context.synchronize() |
| 596 | assert buf2.size == total_size |
| 597 | arr2 = np.frombuffer(buf2, dtype=np.uint8) |
| 598 | np.testing.assert_equal(arr, arr2) |
| 599 | |
| 600 | total_size, chunk_size = 1 << 16, 1000 |
| 601 | test_writes(total_size, chunk_size) |
no test coverage detected