From 99ae4f7a89e9fa0eed715e7403dfb6f5d6ba9a22 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 4 Feb 2015 15:45:18 +1000 Subject: [PATCH] tests: add initial transfer API tests --- tests/Makefile.am | 6 +- tests/test_virgl_transfer.c | 192 ++++++++++++++++++++++++++++++++++++ tests/testvirgl.c | 8 ++ tests/testvirgl.h | 1 + 4 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 tests/test_virgl_transfer.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 1448843..1d573ba 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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_resource +run_tests = test_virgl_init test_virgl_transfer test_virgl_resource noinst_LTLIBRARIES = libvrtest.la libvrtest_la_SOURCES = testvirgl.c @@ -19,6 +19,10 @@ test_virgl_resource_SOURCES = test_virgl_resource.c test_virgl_resource_LDADD = $(TEST_LIBS) test_virgl_resource_LDFLAGS = -no-install +test_virgl_transfer_SOURCES = test_virgl_transfer.c +test_virgl_transfer_LDADD = $(TEST_LIBS) +test_virgl_transfer_LDFLAGS = -no-install + if HAVE_VALGRIND VALGRIND_FLAGS=--leak-check=full \ --quiet \ diff --git a/tests/test_virgl_transfer.c b/tests/test_virgl_transfer.c new file mode 100644 index 0000000..3b8ae40 --- /dev/null +++ b/tests/test_virgl_transfer.c @@ -0,0 +1,192 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/* transfer and iov related tests */ +#include +#include +#include +#include +#include +#include "virgl_hw.h" +#include "testvirgl.h" + +/* pass an illegal context to transfer fn */ +START_TEST(virgl_test_transfer_read_illegal_ctx) +{ + struct virgl_box box; + + virgl_renderer_transfer_read_iov(1, 2, 1, 1, 1, &box, 0, NULL, 0); +} +END_TEST + +START_TEST(virgl_test_transfer_write_illegal_ctx) +{ + struct virgl_box box; + + virgl_renderer_transfer_write_iov(1, 2, 1, 1, 1, &box, 0, NULL, 0); +} +END_TEST + +/* pass a resource not bound to the context to transfers */ +START_TEST(virgl_test_transfer_read_unbound_res) +{ + struct virgl_box box; + + virgl_renderer_transfer_read_iov(1, 1, 1, 1, 1, &box, 0, NULL, 0); +} +END_TEST + +START_TEST(virgl_test_transfer_write_unbound_res) +{ + struct virgl_box box; + + virgl_renderer_transfer_write_iov(1, 1, 1, 1, 1, &box, 0, NULL, 0); +} +END_TEST + +/* don't pass an IOV to read into */ +START_TEST(virgl_test_transfer_read_no_iov) +{ + struct virgl_box box; + struct virgl_renderer_resource_create_args res; + int ret; + + testvirgl_init_simple_1d_resource(&res, 1); + + ret = virgl_renderer_resource_create(&res, NULL, 0); + ck_assert_int_eq(ret, 0); + + virgl_renderer_ctx_attach_resource(1, res.handle); + + virgl_renderer_transfer_read_iov(1, 1, 1, 1, 1, &box, 0, NULL, 0); + + virgl_renderer_ctx_detach_resource(1, res.handle); + + virgl_renderer_resource_unref(1); +} +END_TEST + +START_TEST(virgl_test_transfer_write_no_iov) +{ + struct virgl_box box; + struct virgl_renderer_resource_create_args res; + int ret; + + testvirgl_init_simple_1d_resource(&res, 1); + + ret = virgl_renderer_resource_create(&res, NULL, 0); + ck_assert_int_eq(ret, 0); + + virgl_renderer_ctx_attach_resource(1, res.handle); + + virgl_renderer_transfer_write_iov(1, 1, 1, 1, 1, &box, 0, NULL, 0); + + virgl_renderer_ctx_detach_resource(1, res.handle); + + virgl_renderer_resource_unref(1); +} +END_TEST + +START_TEST(virgl_test_transfer_read_no_box) +{ + struct virgl_renderer_resource_create_args res; + struct iovec iovs[1]; + int niovs = 1; + int ret; + + testvirgl_init_simple_1d_resource(&res, 1); + + ret = virgl_renderer_resource_create(&res, NULL, 0); + ck_assert_int_eq(ret, 0); + + virgl_renderer_ctx_attach_resource(1, res.handle); + + virgl_renderer_transfer_read_iov(1, 1, 1, 1, 1, NULL, 0, iovs, niovs); + + virgl_renderer_ctx_detach_resource(1, res.handle); + + virgl_renderer_resource_unref(1); +} +END_TEST + +START_TEST(virgl_test_transfer_write_no_box) +{ + struct virgl_renderer_resource_create_args res; + struct iovec iovs[1]; + int niovs = 1; + int ret; + + testvirgl_init_simple_1d_resource(&res, 1); + + ret = virgl_renderer_resource_create(&res, NULL, 0); + ck_assert_int_eq(ret, 0); + + virgl_renderer_ctx_attach_resource(1, res.handle); + + virgl_renderer_transfer_write_iov(1, 1, 1, 1, 1, NULL, 0, iovs, niovs); + + virgl_renderer_ctx_detach_resource(1, res.handle); + + virgl_renderer_resource_unref(1); +} +END_TEST + +Suite *virgl_init_suite(void) +{ + Suite *s; + TCase *tc_core; + + s = suite_create("virgl_transfer"); + tc_core = tcase_create("transfer"); + + tcase_add_unchecked_fixture(tc_core, testvirgl_init_single_ctx_nr, testvirgl_fini_single_ctx); + tcase_add_test(tc_core, virgl_test_transfer_read_illegal_ctx); + tcase_add_test(tc_core, virgl_test_transfer_write_illegal_ctx); + tcase_add_test(tc_core, virgl_test_transfer_read_unbound_res); + tcase_add_test(tc_core, virgl_test_transfer_write_unbound_res); + tcase_add_test(tc_core, virgl_test_transfer_read_no_iov); + tcase_add_test(tc_core, virgl_test_transfer_write_no_iov); + tcase_add_test(tc_core, virgl_test_transfer_read_no_box); + tcase_add_test(tc_core, virgl_test_transfer_write_no_box); + 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; +} diff --git a/tests/testvirgl.c b/tests/testvirgl.c index a9f14e4..31a63d6 100644 --- a/tests/testvirgl.c +++ b/tests/testvirgl.c @@ -23,6 +23,7 @@ **************************************************************************/ /* helper functions for testing purposes */ +#include #include "pipe/p_defines.h" #include "pipe/p_format.h" #include "testvirgl.h" @@ -89,13 +90,20 @@ int testvirgl_init_single_ctx(void) test_cbs.version = 1; ret = virgl_renderer_init(&mystruct, VIRGL_RENDERER_USE_EGL, &test_cbs); + ck_assert_int_eq(ret, 0); if (ret) return ret; ret = virgl_renderer_context_create(1, strlen("test1"), "test1"); + ck_assert_int_eq(ret, 0); return ret; } +void testvirgl_init_single_ctx_nr(void) +{ + testvirgl_init_single_ctx(); +} + void testvirgl_fini_single_ctx(void) { virgl_renderer_context_destroy(1); diff --git a/tests/testvirgl.h b/tests/testvirgl.h index 4844c12..8ba93ab 100644 --- a/tests/testvirgl.h +++ b/tests/testvirgl.h @@ -31,6 +31,7 @@ void testvirgl_init_simple_buffer(struct virgl_renderer_resource_create_args *re void testvirgl_init_simple_1d_resource(struct virgl_renderer_resource_create_args *args, int handle); void testvirgl_init_simple_2d_resource(struct virgl_renderer_resource_create_args *res, int handle); int testvirgl_init_single_ctx(void); +void testvirgl_init_single_ctx_nr(void); void testvirgl_fini_single_ctx(void); #endif