start adding unit test framework

macos/master
Dave Airlie 10 years ago
parent 57646ceb4e
commit 6d93aeb128
  1. 2
      Makefile.am
  2. 22
      configure.ac
  3. 27
      tests/Makefile.am
  4. 77
      tests/test_virgl_init.c

@ -19,7 +19,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
SUBDIRS = src SUBDIRS = src tests
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = virglrenderer.pc pkgconfig_DATA = virglrenderer.pc

@ -20,6 +20,27 @@ AC_DISABLE_STATIC
AC_PROG_LIBTOOL AC_PROG_LIBTOOL
AC_SYS_LARGEFILE AC_SYS_LARGEFILE
AC_ARG_ENABLE(tests,
AS_HELP_STRING([--enable-tests], [Build the tests (default=auto)]),
[build_tests="$enableval"],
[build_tests="auto"])
PKG_CHECK_MODULES(CHECK, [check >= 0.9.4], [HAVE_CHECK="yes"], [HAVE_CHECK="no"])
if test "x$build_tests" = "xauto"; then
build_tests="$HAVE_CHECK"
fi
if test "x$build_tests" = "xyes"; then
if test "x$HAVE_CHECK" = "xno"; then
AC_MSG_ERROR([Cannot build tests, check is missing])
fi
AC_PATH_PROG(VALGRIND, [valgrind])
fi
AM_CONDITIONAL(HAVE_VALGRIND, [test "x$VALGRIND" != "x"])
AM_CONDITIONAL(BUILD_TESTS, [test "x$build_tests" = "xyes"])
XORG_MACROS_VERSION(1.8) XORG_MACROS_VERSION(1.8)
XORG_DEFAULT_OPTIONS XORG_DEFAULT_OPTIONS
@ -43,6 +64,7 @@ AC_CONFIG_FILES([
Makefile Makefile
src/Makefile src/Makefile
src/gallium/auxiliary/Makefile src/gallium/auxiliary/Makefile
tests/Makefile
]) ])
AC_OUTPUT AC_OUTPUT

@ -0,0 +1,27 @@
if BUILD_TESTS
AM_CPPFLAGS = -I$(top_srcdir)/src $(CHECK_CFLAGS)
TEST_LIBS = $(top_builddir)/src/libvirglrenderer.la $(CHECK_LIBS)
run_tests = test_virgl_init
noinst_PROGRAMS = $(run_tests)
TESTS = $(run_tests)
test_virgl_init_SOURCES = test_virgl_init.c
test_virgl_init_LDADD = $(TEST_LIBS)
test_virgl_init_LDFLAGS = -no-install
if HAVE_VALGRIND
VALGRIND_FLAGS=--leak-check=full \
--quiet \
--error-exitcode=3
valgrind:
$(MAKE) check-TESTS LOG_COMPILER="$(VALGRIND)" LOG_FLAGS="$(VALGRIND_FLAGS)" CK_FORK=no
check: valgrind
endif
endif

@ -0,0 +1,77 @@
#include <check.h>
#include <stdlib.h>
#include <virglrenderer.h>
static void *mycookie;
static struct virgl_renderer_callbacks rcbs;
START_TEST(virgl_init_no_cbs)
{
int ret;
ret = virgl_renderer_init(mycookie, 0, NULL);
ck_assert_int_eq(ret, -1);
}
END_TEST
START_TEST(virgl_init_no_cookie)
{
int ret;
ret = virgl_renderer_init(NULL, 0, &rcbs);
ck_assert_int_eq(ret, -1);
}
END_TEST
START_TEST(virgl_init_cbs_wrong_ver)
{
int ret;
struct virgl_renderer_callbacks testcbs;
memset(&testcbs, 0, sizeof(testcbs));
testcbs.version = 2;
ret = virgl_renderer_init(mycookie, 0, &testcbs);
ck_assert_int_eq(ret, -1);
}
END_TEST
START_TEST(virgl_init_egl)
{
int ret;
rcbs.version = 1;
ret = virgl_renderer_init(mycookie, VIRGL_RENDERER_USE_EGL, &rcbs);
ck_assert_int_eq(ret, 0);
}
END_TEST
Suite *virgl_init_suite(void)
{
Suite *s;
TCase *tc_core;
s = suite_create("virgl_init");
tc_core = tcase_create("init");
tcase_add_test(tc_core, virgl_init_no_cbs);
tcase_add_test(tc_core, virgl_init_no_cookie);
tcase_add_test(tc_core, virgl_init_cbs_wrong_ver);
tcase_add_test(tc_core, virgl_init_egl);
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