summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2014-02-27 15:14:59 +0100
committerWim Taymans <wtaymans@redhat.com>2014-02-27 15:43:13 +0100
commitf22d8f08e0a52c6f23520d67fba6b7e1aae61e6e (patch)
treeff4d1bf2ac72d9a208b985ad61d52ded4daeff36 /tests
parent5bca002f4bcb37e3c5453c77a750bb741e3cfea1 (diff)
bufferpool: Use TAG_MEMORY to check memory before releasing
Tag allocated buffers with TAG_MEMORY. When they are released later, only add them back to the pool if the tag is still there and the memory has not been changed, otherwise throw the buffer away. Add unit test to check various scenarios. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=724481
Diffstat (limited to 'tests')
-rw-r--r--tests/check/gst/gstbufferpool.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/check/gst/gstbufferpool.c b/tests/check/gst/gstbufferpool.c
index 7809ba2f92..fd201b4b56 100644
--- a/tests/check/gst/gstbufferpool.c
+++ b/tests/check/gst/gstbufferpool.c
@@ -125,6 +125,46 @@ GST_START_TEST (test_inactive_pool_returns_flushing)
GST_END_TEST;
+GST_START_TEST (test_buffer_modify_discard)
+{
+
+ GstBufferPool *pool = create_pool (10, 0, 0);
+ GstBuffer *buf = NULL, *prev;
+ GstMemory *mem;
+
+ gst_buffer_pool_set_active (pool, TRUE);
+ gst_buffer_pool_acquire_buffer (pool, &buf, NULL);
+ prev = buf;
+ /* remove all memory, pool should not reuse this buffer */
+ gst_buffer_remove_all_memory (buf);
+ gst_buffer_unref (buf);
+
+ gst_buffer_pool_acquire_buffer (pool, &buf, NULL);
+ fail_if (buf == prev, "got a reused buffer instead of new one");
+ prev = buf;
+ /* do resize, pool should not reuse this buffer */
+ gst_buffer_resize (buf, 5, 2);
+ gst_buffer_unref (buf);
+
+ gst_buffer_pool_acquire_buffer (pool, &buf, NULL);
+ fail_if (buf == prev, "got a reused buffer instead of new one");
+ prev = buf;
+ /* keep ref to memory, not exclusive so pool should reuse this buffer */
+ mem = gst_buffer_get_memory (buf, 0);
+ gst_buffer_unref (buf);
+ gst_memory_unref (mem);
+
+ gst_buffer_pool_acquire_buffer (pool, &buf, NULL);
+ fail_unless (buf == prev, "got a fresh buffer instead of previous");
+ mem = gst_buffer_get_memory (buf, 0);
+
+ gst_buffer_unref (buf);
+
+ gst_buffer_pool_set_active (pool, FALSE);
+ gst_object_unref (pool);
+}
+
+GST_END_TEST;
static Suite *
gst_buffer_pool_suite (void)
@@ -140,6 +180,7 @@ gst_buffer_pool_suite (void)
tcase_add_test (tc_chain, test_buffer_out_of_order_reuse);
tcase_add_test (tc_chain, test_pool_config_buffer_size);
tcase_add_test (tc_chain, test_inactive_pool_returns_flushing);
+ tcase_add_test (tc_chain, test_buffer_modify_discard);
return s;
}