tests: add initial resource tests

This tests some illegal resource creation types.
macos/master
Dave Airlie 10 years ago
parent 4240d2e8f5
commit ae6a662940
  1. 6
      tests/Makefile.am
  2. 159
      tests/test_virgl_resource.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
run_tests = test_virgl_init test_virgl_resource
noinst_LTLIBRARIES = libvrtest.la
libvrtest_la_SOURCES = testvirgl.c
@ -15,6 +15,10 @@ test_virgl_init_SOURCES = test_virgl_init.c
test_virgl_init_LDADD = $(TEST_LIBS)
test_virgl_init_LDFLAGS = -no-install
test_virgl_resource_SOURCES = test_virgl_resource.c
test_virgl_resource_LDADD = $(TEST_LIBS)
test_virgl_resource_LDFLAGS = -no-install
if HAVE_VALGRIND
VALGRIND_FLAGS=--leak-check=full \
--quiet \

@ -0,0 +1,159 @@
/**************************************************************************
*
* 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.
*
**************************************************************************/
/*
* resource tests
* test illegal resource combinations
- 1D resources with height or depth
- 2D with depth
*/
#include <check.h>
#include <stdlib.h>
#include <errno.h>
#include <virglrenderer.h>
#include "testvirgl.h"
/* create a 1D texture */
START_TEST(virgl_res_create_1d)
{
int ret;
struct virgl_renderer_resource_create_args res;
ret = testvirgl_init_single_ctx();
testvirgl_init_simple_1d_resource(&res, 1);
ret = virgl_renderer_resource_create(&res, NULL, 0);
ck_assert_int_eq(ret, 0);
testvirgl_fini_single_ctx();
}
END_TEST
/* create a 1D texture with height - this should fail */
START_TEST(virgl_res_create_1d_with_height)
{
int ret;
struct virgl_renderer_resource_create_args res;
ret = testvirgl_init_single_ctx();
testvirgl_init_simple_1d_resource(&res, 1);
res.height = 50;
ret = virgl_renderer_resource_create(&res, NULL, 0);
ck_assert_int_eq(ret, EINVAL);
testvirgl_fini_single_ctx();
}
END_TEST
/* create a 1D texture with depth - this should fail */
START_TEST(virgl_res_create_1d_with_depth)
{
int ret;
struct virgl_renderer_resource_create_args res;
ret = testvirgl_init_single_ctx();
testvirgl_init_simple_1d_resource(&res, 1);
res.depth = 2;
ret = virgl_renderer_resource_create(&res, NULL, 0);
ck_assert_int_eq(ret, EINVAL);
testvirgl_fini_single_ctx();
}
END_TEST
/* create a 2D texture */
START_TEST(virgl_res_create_2d)
{
int ret;
struct virgl_renderer_resource_create_args res;
ret = testvirgl_init_single_ctx();
testvirgl_init_simple_2d_resource(&res, 1);
ret = virgl_renderer_resource_create(&res, NULL, 0);
ck_assert_int_eq(ret, 0);
testvirgl_fini_single_ctx();
}
END_TEST
/* create a 2D texture with depth - this should fail */
START_TEST(virgl_res_create_2d_with_depth)
{
int ret;
struct virgl_renderer_resource_create_args res;
ret = testvirgl_init_single_ctx();
testvirgl_init_simple_1d_resource(&res, 1);
res.depth = 2;
ret = virgl_renderer_resource_create(&res, NULL, 0);
ck_assert_int_eq(ret, EINVAL);
testvirgl_fini_single_ctx();
}
END_TEST
Suite *virgl_init_suite(void)
{
Suite *s;
TCase *tc_core;
s = suite_create("virgl_resource");
tc_core = tcase_create("resource");
tcase_add_test(tc_core, virgl_res_create_1d);
tcase_add_test(tc_core, virgl_res_create_1d_with_height);
tcase_add_test(tc_core, virgl_res_create_1d_with_depth);
tcase_add_test(tc_core, virgl_res_create_2d);
tcase_add_test(tc_core, virgl_res_create_2d_with_depth);
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