tests/prime_nv_pcopy: Use asserts in nv_bo_alloc

Step one to untangle the control flow in this test and replace it all
with igt assert magic.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Daniel Vetter 2014-05-14 10:49:40 +02:00
parent d502ae6f77
commit 782cda17b9

View File

@ -56,13 +56,12 @@ typedef struct {
uint32_t pitch, lines; uint32_t pitch, lines;
} rect; } rect;
static int nv_bo_alloc(struct nouveau_bo **bo, rect *r, static void nv_bo_alloc(struct nouveau_bo **bo, rect *r,
uint32_t w, uint32_t h, uint32_t tile_mode, uint32_t w, uint32_t h, uint32_t tile_mode,
int handle, uint32_t dom) int handle, uint32_t dom)
{ {
uint32_t size; uint32_t size;
uint32_t dx = 1, dy = 1, memtype = 0; uint32_t dx = 1, dy = 1, memtype = 0;
int ret;
*bo = NULL; *bo = NULL;
if (tile_mode) { if (tile_mode) {
@ -104,15 +103,8 @@ static int nv_bo_alloc(struct nouveau_bo **bo, rect *r,
cfg.nv50.tile_mode = tile_mode; cfg.nv50.tile_mode = tile_mode;
if (dom == NOUVEAU_BO_GART) if (dom == NOUVEAU_BO_GART)
dom |= NOUVEAU_BO_MAP; dom |= NOUVEAU_BO_MAP;
ret = nouveau_bo_new(ndev, dom, 4096, size, &cfg, bo); igt_assert(nouveau_bo_new(ndev, dom, 4096, size, &cfg, bo) == 0);
if (!ret) igt_assert(nouveau_bo_map(*bo, NOUVEAU_BO_RDWR, nclient) == 0);
ret = nouveau_bo_map(*bo, NOUVEAU_BO_RDWR, nclient);
if (ret) {
fprintf(stderr, "creating bo failed with %i %s\n",
ret, strerror(-ret));
nouveau_bo_ref(NULL, bo);
return ret;
}
igt_debug("new flags %08x memtype %08x tile %08x\n", igt_debug("new flags %08x memtype %08x tile %08x\n",
(*bo)->flags, (*bo)->config.nv50.memtype, (*bo)->flags, (*bo)->config.nv50.memtype,
@ -124,19 +116,11 @@ static int nv_bo_alloc(struct nouveau_bo **bo, rect *r,
(*bo)->config.nv50.tile_mode = tile_mode; (*bo)->config.nv50.tile_mode = tile_mode;
} }
} else { } else {
ret = nouveau_bo_prime_handle_ref(ndev, handle, bo); igt_assert(nouveau_bo_prime_handle_ref(ndev, handle, bo) == 0);
close(handle); close(handle);
if (ret < 0) { igt_assert_f((*bo)->size >= size,
fprintf(stderr, "receiving bo failed with %i %s\n", "expected bo size to be at least %u,"
ret, strerror(-ret));
return ret;
}
if ((*bo)->size < size) {
fprintf(stderr, "expected bo size to be at least %u,"
"but received %"PRIu64"\n", size, (*bo)->size); "but received %"PRIu64"\n", size, (*bo)->size);
nouveau_bo_ref(NULL, bo);
return -1;
}
igt_debug("prime flags %08x memtype %08x tile %08x\n", igt_debug("prime flags %08x memtype %08x tile %08x\n",
(*bo)->flags, (*bo)->config.nv50.memtype, (*bo)->flags, (*bo)->config.nv50.memtype,
(*bo)->config.nv50.tile_mode); (*bo)->config.nv50.tile_mode);
@ -144,8 +128,6 @@ static int nv_bo_alloc(struct nouveau_bo **bo, rect *r,
(*bo)->config.nv50.tile_mode = tile_mode; (*bo)->config.nv50.tile_mode = tile_mode;
} }
igt_debug("size: %"PRIu64"\n", (*bo)->size); igt_debug("size: %"PRIu64"\n", (*bo)->size);
return ret;
} }
static inline void static inline void
@ -655,11 +637,8 @@ static int test1_macro(void)
uint8_t *ptr; uint8_t *ptr;
uint32_t w = 2 * 128, h = 2 * 32, x, y; uint32_t w = 2 * 128, h = 2 * 32, x, y;
ret = nv_bo_alloc(&nvbi, &src, w, h, 0, -1, NOUVEAU_BO_GART); nv_bo_alloc(&nvbi, &src, w, h, 0, -1, NOUVEAU_BO_GART);
if (ret >= 0) nv_bo_alloc(&nvbo, &dst, w, h, tile_intel_y, -1, NOUVEAU_BO_GART);
ret = nv_bo_alloc(&nvbo, &dst, w, h, tile_intel_y, -1, NOUVEAU_BO_GART);
if (ret < 0)
goto out;
nouveau_bo_set_prime(nvbo, &prime_fd); nouveau_bo_set_prime(nvbo, &prime_fd);
@ -699,7 +678,6 @@ static int test1_macro(void)
if (!ret) if (!ret)
ret = check1_macro(nvbo->map, w/128, h/32); ret = check1_macro(nvbo->map, w/128, h/32);
out:
nouveau_bo_ref(NULL, &nvbo); nouveau_bo_ref(NULL, &nvbo);
nouveau_bo_ref(NULL, &nvbi); nouveau_bo_ref(NULL, &nvbi);
close(prime_fd); close(prime_fd);
@ -774,13 +752,9 @@ static int test1_micro(void)
} }
noop_intel(test_intel_bo); noop_intel(test_intel_bo);
ret = nv_bo_alloc(&bo_intel, &intel, w, h, tile_intel_y, prime_fd, 0); nv_bo_alloc(&bo_intel, &intel, w, h, tile_intel_y, prime_fd, 0);
if (!ret) nv_bo_alloc(&bo_nvidia, &nvidia, w, h, 0x10, -1, NOUVEAU_BO_VRAM);
ret = nv_bo_alloc(&bo_nvidia, &nvidia, w, h, 0x10, -1, NOUVEAU_BO_VRAM); nv_bo_alloc(&bo_linear, &linear, w, h, 0, -1, NOUVEAU_BO_GART);
if (!ret)
ret = nv_bo_alloc(&bo_linear, &linear, w, h, 0, -1, NOUVEAU_BO_GART);
if (ret)
goto out;
for (y = 0; y < linear.h; ++y) { for (y = 0; y < linear.h; ++y) {
uint8_t *map = bo_linear->map; uint8_t *map = bo_linear->map;
@ -905,13 +879,9 @@ static int test1_swizzle(void)
goto out; goto out;
} }
ret = nv_bo_alloc(&bo_intel, &intel, w, h, tile_intel_y, prime_fd, 0); nv_bo_alloc(&bo_intel, &intel, w, h, tile_intel_y, prime_fd, 0);
if (!ret) nv_bo_alloc(&bo_nvidia, &nvidia, w, h, 0x10, -1, NOUVEAU_BO_VRAM);
ret = nv_bo_alloc(&bo_nvidia, &nvidia, w, h, 0x10, -1, NOUVEAU_BO_VRAM); nv_bo_alloc(&bo_linear, &linear, w, h, 0, -1, NOUVEAU_BO_GART);
if (!ret)
ret = nv_bo_alloc(&bo_linear, &linear, w, h, 0, -1, NOUVEAU_BO_GART);
if (ret)
goto out;
noop_intel(test_intel_bo); noop_intel(test_intel_bo);
ptr = bo_linear->map; ptr = bo_linear->map;
@ -968,11 +938,8 @@ static int test2(void)
uint8_t *ptr; uint8_t *ptr;
uint32_t w = 1024, h = 16, x, y; uint32_t w = 1024, h = 16, x, y;
ret = nv_bo_alloc(&nvbi, &src, w, h, 0, -1, NOUVEAU_BO_GART); nv_bo_alloc(&nvbi, &src, w, h, 0, -1, NOUVEAU_BO_GART);
if (ret >= 0) nv_bo_alloc(&nvbo, &dst, w, h, tile_intel_x, -1, NOUVEAU_BO_GART);
ret = nv_bo_alloc(&nvbo, &dst, w, h, tile_intel_x, -1, NOUVEAU_BO_GART);
if (ret < 0)
goto out;
/* Set up something for our tile that should map into the first /* Set up something for our tile that should map into the first
* y-major tile, assuming my understanding of documentation is * y-major tile, assuming my understanding of documentation is
@ -1008,7 +975,6 @@ static int test2(void)
if (!ret) if (!ret)
ret = check1_macro(nvbo->map, w/512, h/8); ret = check1_macro(nvbo->map, w/512, h/8);
out:
nouveau_bo_ref(NULL, &nvbo); nouveau_bo_ref(NULL, &nvbo);
nouveau_bo_ref(NULL, &nvbi); nouveau_bo_ref(NULL, &nvbi);
return ret; return ret;
@ -1070,13 +1036,9 @@ static int test3_base(int tile_src, int tile_dst)
return -1; return -1;
} }
ret = nv_bo_alloc(&bo_intel, &intel, 2048 * cpp, 768, tile_dst, prime_fd, 0); nv_bo_alloc(&bo_intel, &intel, 2048 * cpp, 768, tile_dst, prime_fd, 0);
if (!ret) nv_bo_alloc(&bo_nvidia, &nvidia, 300 * cpp, 300, tile_src, -1, NOUVEAU_BO_VRAM);
ret = nv_bo_alloc(&bo_nvidia, &nvidia, 300 * cpp, 300, tile_src, -1, NOUVEAU_BO_VRAM); nv_bo_alloc(&bo_linear, &linear, 2048 * cpp, 768, 0, -1, NOUVEAU_BO_GART);
if (!ret)
ret = nv_bo_alloc(&bo_linear, &linear, 2048 * cpp, 768, 0, -1, NOUVEAU_BO_GART);
if (ret)
goto out;
noop_intel(test_intel_bo); noop_intel(test_intel_bo);
memset(bo_linear->map, 0x80, bo_linear->size); memset(bo_linear->map, 0x80, bo_linear->size);