From ff4d88ae5cf310d01f17c487089841c07b73faca Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 3 Feb 2015 17:00:31 +1000 Subject: [PATCH] tests: test dangling resources. If we leave a resource in the resource table it shouldn't cause a memory leak. --- tests/test_virgl_init.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_virgl_init.c b/tests/test_virgl_init.c index b317927..15e28c0 100644 --- a/tests/test_virgl_init.c +++ b/tests/test_virgl_init.c @@ -96,8 +96,45 @@ START_TEST(virgl_init_egl_create_ctx_create_bind_res) virgl_renderer_context_destroy(1); virgl_renderer_cleanup(&mystruct); } +END_TEST + +START_TEST(virgl_init_egl_create_ctx_create_bind_res_leak) +{ + int ret; + struct virgl_renderer_resource_create_args res; + test_cbs.version = 1; + ret = virgl_renderer_init(&mystruct, VIRGL_RENDERER_USE_EGL, &test_cbs); + ck_assert_int_eq(ret, 0); + ret = virgl_renderer_context_create(1, strlen("test1"), "test1"); + ck_assert_int_eq(ret, 0); + + res.handle = 1; + res.target = 1; + res.format = 2; + res.width = 50; + res.height = 50; + res.depth = 1; + res.array_size = 1; + res.last_level = 0; + res.nr_samples = 0; + res.bind = 0; + res.flags = 0; + + ret = virgl_renderer_resource_create(&res, NULL, 0); + ck_assert_int_eq(ret, 0); + + virgl_renderer_ctx_attach_resource(1, res.handle); + + /*virgl_renderer_ctx_detach_resource(1, res.handle);*/ + + /*virgl_renderer_resource_unref(1);*/ + /* don't detach or destroy resource - it should still get cleanedup */ + virgl_renderer_context_destroy(1); + virgl_renderer_cleanup(&mystruct); +} END_TEST + Suite *virgl_init_suite(void) { Suite *s; @@ -112,6 +149,7 @@ Suite *virgl_init_suite(void) tcase_add_test(tc_core, virgl_init_egl); tcase_add_test(tc_core, virgl_init_egl_create_ctx); tcase_add_test(tc_core, virgl_init_egl_create_ctx_create_bind_res); + tcase_add_test(tc_core, virgl_init_egl_create_ctx_create_bind_res_leak); suite_add_tcase(s, tc_core); return s;