(size)
| 506 | |
| 507 | @pytest.mark.parametrize("size", [0, 1, 1000]) |
| 508 | def test_copy_from_host(size): |
| 509 | arr, buf = make_random_buffer(size=size, target='host') |
| 510 | lst = arr.tolist() |
| 511 | dbuf = global_context.new_buffer(size) |
| 512 | |
| 513 | def put(*args, **kwargs): |
| 514 | dbuf.copy_from_host(buf, *args, **kwargs) |
| 515 | rbuf = dbuf.copy_to_host() |
| 516 | return np.frombuffer(rbuf, dtype=np.uint8).tolist() |
| 517 | assert put() == lst |
| 518 | if size > 4: |
| 519 | assert put(position=size//4) == lst[:size//4]+lst[:-size//4] |
| 520 | assert put() == lst |
| 521 | assert put(position=1, nbytes=size//2) == \ |
| 522 | lst[:1] + lst[:size//2] + lst[-(size-size//2-1):] |
| 523 | |
| 524 | for (position, nbytes) in [ |
| 525 | (size+2, -1), (-2, -1), (size+1, 0), (-3, 0), |
| 526 | ]: |
| 527 | with pytest.raises(ValueError, |
| 528 | match='position argument is out-of-range'): |
| 529 | put(position=position, nbytes=nbytes) |
| 530 | |
| 531 | for (position, nbytes) in [ |
| 532 | (0, size+1), |
| 533 | ]: |
| 534 | with pytest.raises(ValueError, |
| 535 | match=('requested more to copy than' |
| 536 | ' available from host buffer')): |
| 537 | put(position=position, nbytes=nbytes) |
| 538 | |
| 539 | if size < 4: |
| 540 | return |
| 541 | |
| 542 | for (position, nbytes) in [ |
| 543 | (size//2, (size+1)//2+1) |
| 544 | ]: |
| 545 | with pytest.raises(ValueError, |
| 546 | match=('requested more to copy than' |
| 547 | ' available in device buffer')): |
| 548 | put(position=position, nbytes=nbytes) |
| 549 | |
| 550 | |
| 551 | def test_buffer_device(): |
nothing calls this directly
no test coverage detected