(size)
| 383 | |
| 384 | @pytest.mark.parametrize("size", [0, 1, 1000]) |
| 385 | def test_copy_to_host(size): |
| 386 | arr, dbuf = make_random_buffer(size, target='device') |
| 387 | |
| 388 | buf = dbuf.copy_to_host() |
| 389 | assert buf.is_cpu |
| 390 | np.testing.assert_equal(arr, np.frombuffer(buf, dtype=np.uint8)) |
| 391 | |
| 392 | buf = dbuf.copy_to_host(position=size//4) |
| 393 | assert buf.is_cpu |
| 394 | np.testing.assert_equal(arr[size//4:], np.frombuffer(buf, dtype=np.uint8)) |
| 395 | |
| 396 | buf = dbuf.copy_to_host(position=size//4, nbytes=size//8) |
| 397 | assert buf.is_cpu |
| 398 | np.testing.assert_equal(arr[size//4:size//4+size//8], |
| 399 | np.frombuffer(buf, dtype=np.uint8)) |
| 400 | |
| 401 | buf = dbuf.copy_to_host(position=size//4, nbytes=0) |
| 402 | assert buf.is_cpu |
| 403 | assert buf.size == 0 |
| 404 | |
| 405 | for (position, nbytes) in [ |
| 406 | (size+2, -1), (-2, -1), (size+1, 0), (-3, 0), |
| 407 | ]: |
| 408 | with pytest.raises(ValueError, |
| 409 | match='position argument is out-of-range'): |
| 410 | dbuf.copy_to_host(position=position, nbytes=nbytes) |
| 411 | |
| 412 | for (position, nbytes) in [ |
| 413 | (0, size+1), (size//2, (size+1)//2+1), (size, 1) |
| 414 | ]: |
| 415 | with pytest.raises(ValueError, |
| 416 | match=('requested more to copy than' |
| 417 | ' available from device buffer')): |
| 418 | dbuf.copy_to_host(position=position, nbytes=nbytes) |
| 419 | |
| 420 | buf = pa.allocate_buffer(size//4) |
| 421 | dbuf.copy_to_host(buf=buf) |
| 422 | np.testing.assert_equal(arr[:size//4], np.frombuffer(buf, dtype=np.uint8)) |
| 423 | |
| 424 | if size < 12: |
| 425 | return |
| 426 | |
| 427 | dbuf.copy_to_host(buf=buf, position=12) |
| 428 | np.testing.assert_equal(arr[12:12+size//4], |
| 429 | np.frombuffer(buf, dtype=np.uint8)) |
| 430 | |
| 431 | dbuf.copy_to_host(buf=buf, nbytes=12) |
| 432 | np.testing.assert_equal(arr[:12], np.frombuffer(buf, dtype=np.uint8)[:12]) |
| 433 | |
| 434 | dbuf.copy_to_host(buf=buf, nbytes=12, position=6) |
| 435 | np.testing.assert_equal(arr[6:6+12], |
| 436 | np.frombuffer(buf, dtype=np.uint8)[:12]) |
| 437 | |
| 438 | for (position, nbytes) in [ |
| 439 | (0, size+10), (10, size-5), |
| 440 | (0, size//2), (size//4, size//4+1) |
| 441 | ]: |
| 442 | with pytest.raises(ValueError, |
nothing calls this directly
no test coverage detected