tests: add a cmdbuf test that verifies a clear on a buffer.

Signed-off-by: Dave Airlie <airlied@redhat.com>
macos/master
Dave Airlie 10 years ago
parent 94946a6ea6
commit 31c561de14
  1. 6
      tests/Makefile.am
  2. 148
      tests/test_virgl_cmd.c

@ -4,7 +4,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/gallium/include $(CHECK_CF
TEST_LIBS = libvrtest.la $(top_builddir)/src/libvirglrenderer.la $(CHECK_LIBS)
run_tests = test_virgl_init test_virgl_transfer test_virgl_resource
run_tests = test_virgl_init test_virgl_transfer test_virgl_resource test_virgl_cmd
noinst_LTLIBRARIES = libvrtest.la
libvrtest_la_SOURCES = testvirgl.c testvirgl_encode.c
@ -23,6 +23,10 @@ test_virgl_transfer_SOURCES = test_virgl_transfer.c
test_virgl_transfer_LDADD = $(TEST_LIBS)
test_virgl_transfer_LDFLAGS = -no-install
test_virgl_cmd_SOURCES = test_virgl_cmd.c
test_virgl_cmd_LDADD = $(TEST_LIBS)
test_virgl_cmd_LDFLAGS = -no-install
if HAVE_VALGRIND
VALGRIND_FLAGS=--leak-check=full \
--quiet \

@ -0,0 +1,148 @@
/**************************************************************************
*
* Copyright (C) 2014 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include <check.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/uio.h>
#include <virglrenderer.h>
#include "virgl_hw.h"
#include "pipe/p_format.h"
#include "testvirgl_encode.h"
/* create a resource - clear it to a color, do a transfer */
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);
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);
/* create a surface for the resource */
memset(&surf, 0, sizeof(surf));
surf.base.format = PIPE_FORMAT_B8G8R8X8_UNORM;
surf.handle = 1;
surf.base.texture = &res.base;
virgl_encoder_create_surface(&ctx, surf.handle, &res, &surf.base);
/* set the framebuffer state */
fb_state.nr_cbufs = 1;
fb_state.zsbuf = NULL;
fb_state.cbufs[0] = &surf.base;
virgl_encoder_set_framebuffer_state(&ctx, &fb_state);
/* clear the resource */
virgl_encode_clear(&ctx, PIPE_CLEAR_COLOR0, &color, 0.0, 0);
/* submit the cmd stream */
virgl_renderer_submit_cmd(ctx.cbuf->buf, 1, ctx.cbuf->cdw);
/* read back the cleared values in the resource */
box.x = 0;
box.y = 0;
box.z = 0;
box.w = 5;
box.h = 1;
box.d = 1;
ret = virgl_renderer_transfer_read_iov(res.handle, ctx.ctx_id, 0, 50, 0, &box, 0, NULL, 0);
ck_assert_int_eq(ret, 0);
/* check the returned values */
for (i = 0; i < 5; i++) {
uint32_t *ptr = 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_fini_ctx_cmdbuf(&ctx);
}
END_TEST
Suite *virgl_init_suite(void)
{
Suite *s;
TCase *tc_core;
s = suite_create("virgl_clear");
tc_core = tcase_create("clear");
tcase_add_test(tc_core, virgl_test_clear);
suite_add_tcase(s, tc_core);
return s;
}
int main(void)
{
Suite *s;
SRunner *sr;
int number_failed;
s = virgl_init_suite();
sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return number_failed == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
Loading…
Cancel
Save