tests: add a simple backed resource creation utility

Then hook the cmd stream test into it to use it.
macos/master
Dave Airlie 10 years ago
parent 31c561de14
commit 50ccab6f6c
  1. 33
      tests/test_virgl_cmd.c
  2. 40
      tests/testvirgl.c
  3. 6
      tests/testvirgl.h

@ -35,40 +35,20 @@ START_TEST(virgl_test_clear)
{
struct virgl_context ctx;
struct virgl_resource res;
struct virgl_renderer_resource_create_args args;
struct virgl_surface surf;
struct pipe_framebuffer_state fb_state;
union pipe_color_union color;
struct virgl_box box;
struct iovec iovs[1];
int niovs = 1;
int ret;
int i;
ret = testvirgl_init_ctx_cmdbuf(&ctx);
ck_assert_int_eq(ret, 0);
/* clear buffer to green */
color.f[0] = 0.0;
color.f[1] = 1.0;
color.f[2] = 0.0;
color.f[3] = 1.0;
/* init and create simple 2D resource */
testvirgl_init_simple_2d_resource(&args, 1);
ret = virgl_renderer_resource_create(&args, NULL, 0);
ret = testvirgl_create_backed_simple_2d_res(&res, 1);
ck_assert_int_eq(ret, 0);
res.handle = 1;
res.base.target = PIPE_TEXTURE_2D;
/* create and attach some backing store for resource */
iovs[0].iov_base = calloc(1, 50*50*4);
iovs[0].iov_len = 50*50*4;
virgl_renderer_resource_attach_iov(res.handle, iovs, niovs);
ck_assert_int_eq(ret, 0);
/* attach resource to context */
virgl_renderer_ctx_attach_resource(ctx.ctx_id, res.handle);
@ -87,6 +67,11 @@ START_TEST(virgl_test_clear)
virgl_encoder_set_framebuffer_state(&ctx, &fb_state);
/* clear the resource */
/* clear buffer to green */
color.f[0] = 0.0;
color.f[1] = 1.0;
color.f[2] = 0.0;
color.f[3] = 1.0;
virgl_encode_clear(&ctx, PIPE_CLEAR_COLOR0, &color, 0.0, 0);
/* submit the cmd stream */
@ -104,15 +89,15 @@ START_TEST(virgl_test_clear)
/* check the returned values */
for (i = 0; i < 5; i++) {
uint32_t *ptr = iovs[0].iov_base;
uint32_t *ptr = res.iovs[0].iov_base;
ck_assert_int_eq(ptr[i], 0xff00ff00);
}
/* cleanup */
virgl_renderer_ctx_detach_resource(1, res.handle);
virgl_renderer_resource_detach_iov(res.handle, NULL, NULL);
free(iovs[0].iov_base);
testvirgl_destroy_backed_res(&res);
testvirgl_fini_ctx_cmdbuf(&ctx);
}
END_TEST

@ -25,9 +25,11 @@
/* helper functions for testing purposes */
#include <check.h>
#include <errno.h>
#include <sys/uio.h>
#include "pipe/p_defines.h"
#include "pipe/p_format.h"
#include "util/u_memory.h"
#include "util/u_format.h"
#include "testvirgl.h"
#include "virglrenderer.h"
@ -141,3 +143,41 @@ void testvirgl_fini_ctx_cmdbuf(struct virgl_context *ctx)
FREE(ctx->cbuf);
testvirgl_fini_single_ctx();
}
int testvirgl_create_backed_simple_2d_res(struct virgl_resource *res,
int handle)
{
struct virgl_renderer_resource_create_args args;
uint32_t backing_size;
int ret;
testvirgl_init_simple_2d_resource(&args, handle);
ret = virgl_renderer_resource_create(&args, NULL, 0);
ck_assert_int_eq(ret, 0);
res->handle = handle;
res->base.target = args.target;
res->base.format = args.format;
backing_size = args.width * args.height * util_format_get_blocksize(res->base.format);
res->iovs = malloc(sizeof(struct iovec));
res->iovs[0].iov_base = malloc(backing_size);
res->iovs[0].iov_len = backing_size;
res->niovs = 1;
virgl_renderer_resource_attach_iov(res->handle, res->iovs, res->niovs);
return 0;
}
void testvirgl_destroy_backed_res(struct virgl_resource *res)
{
struct iovec *iovs;
int niovs;
virgl_renderer_resource_detach_iov(res->handle, &iovs, &niovs);
free(iovs[0].iov_base);
free(iovs);
virgl_renderer_resource_unref(res->handle);
}

@ -50,6 +50,8 @@ struct virgl_sampler_view {
struct virgl_resource {
struct pipe_resource base;
uint32_t handle;
struct iovec *iovs;
int niovs;
};
@ -62,4 +64,8 @@ void testvirgl_fini_single_ctx(void);
int testvirgl_init_ctx_cmdbuf(struct virgl_context *ctx);
void testvirgl_fini_ctx_cmdbuf(struct virgl_context *ctx);
int testvirgl_create_backed_simple_2d_res(struct virgl_resource *res,
int handle);
void testvirgl_destroy_backed_res(struct virgl_resource *res);
#endif

Loading…
Cancel
Save