tests/check/: enable queue test again, add tests for the leaky behaviour
authorStefan Kost <ensonic@users.sourceforge.net>
Thu, 4 Jan 2007 13:37:08 +0000 (13:37 +0000)
committerStefan Kost <ensonic@users.sourceforge.net>
Thu, 4 Jan 2007 13:37:08 +0000 (13:37 +0000)
Original commit message from CVS:
* tests/check/Makefile.am:
* tests/check/elements/queue.c: (queue_overrun), (queue_underrun),
(GST_START_TEST), (queue_suite):
enable queue test again, add tests for the leaky behaviour

ChangeLog
tests/check/Makefile.am
tests/check/elements/queue.c

index 0df4ae1..44a3b42 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-01-04  Stefan Kost  <ensonic@users.sf.net>
+
+       * tests/check/Makefile.am:
+       * tests/check/elements/queue.c: (queue_overrun), (queue_underrun),
+       (GST_START_TEST), (queue_suite):
+         enable queue test again, add tests for the leaky behaviour
+
 2007-01-02  Tim-Philipp Müller  <tim at centricular dot net>
 
        * configure.ac:
index b6940a1..eef41cb 100644 (file)
@@ -57,6 +57,7 @@ REGISTRY_CHECKS =                             \
        elements/fdsrc                          \
        elements/filesrc                                \
        elements/identity                       \
+       elements/queue                          \
        libs/basesrc                            \
        libs/controller                         \
        libs/typefindhelper                     \
@@ -91,11 +92,9 @@ check_PROGRAMS =                                     \
        libs/gstnettimeprovider
 
 # failing tests
-# queue : seems to work with installed gstcheck
 noinst_PROGRAMS =                              \
        gst/gstpipeline                           \
-       libs/collectpads                                \
-       elements/queue
+       libs/collectpads
 
 TESTS = $(check_PROGRAMS)
 
index 37179a4..d422834 100644 (file)
@@ -104,7 +104,6 @@ GST_START_TEST (test_non_leaky_underrun)
           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
       "could not set to playing");
 
-  /* FIXME: there seems to be a race here */
   g_mutex_lock (check_mutex);
   g_cond_wait (check_cond, check_mutex);
   g_mutex_unlock (check_mutex);
@@ -184,6 +183,152 @@ GST_START_TEST (test_non_leaky_overrun)
 
 GST_END_TEST;
 
+/* set queue size to 2 buffers
+ * push 2 buffers
+ * check over/underuns
+ * push 1 more buffer
+ * check over/underuns again
+ * check which buffer was leaked
+ */
+GST_START_TEST (test_leaky_upstream)
+{
+  GstElement *queue;
+  GstBuffer *buffer1, *buffer2, *buffer3;
+  GstBuffer *buffer;
+
+  queue = setup_queue ();
+  mysrcpad = gst_check_setup_src_pad (queue, &srctemplate, NULL);
+  mysinkpad = gst_check_setup_sink_pad (queue, &sinktemplate, NULL);
+  g_object_set (G_OBJECT (queue), "max-size-buffers", 2, "leaky", 1, NULL);
+  gst_pad_set_active (mysrcpad, TRUE);
+
+  GST_DEBUG ("starting");
+
+  fail_unless (gst_element_set_state (queue,
+          GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+      "could not set to playing");
+
+  buffer1 = gst_buffer_new_and_alloc (4);
+  ASSERT_BUFFER_REFCOUNT (buffer1, "buffer", 1);
+  /* pushing gives away my reference ... */
+  gst_pad_push (mysrcpad, buffer1);
+
+  GST_DEBUG ("added 1st");
+  fail_unless (overrun_count == 0);
+  fail_unless (underrun_count == 0);
+
+  buffer2 = gst_buffer_new_and_alloc (4);
+  ASSERT_BUFFER_REFCOUNT (buffer2, "buffer", 1);
+  /* pushing gives away my reference ... */
+  gst_pad_push (mysrcpad, buffer2);
+
+  GST_DEBUG ("added 2nd");
+  fail_unless (overrun_count == 0);
+  fail_unless (underrun_count == 0);
+
+  buffer3 = gst_buffer_new_and_alloc (4);
+  ASSERT_BUFFER_REFCOUNT (buffer3, "buffer", 1);
+  /* pushing gives away my reference ... */
+  gst_pad_push (mysrcpad, gst_buffer_ref (buffer3));
+
+  /* start the src-task briefly leak buffer3 */
+  gst_pad_set_active (mysinkpad, TRUE);
+
+  g_mutex_lock (check_mutex);
+  g_cond_wait (check_cond, check_mutex);
+  g_mutex_unlock (check_mutex);
+
+  gst_pad_set_active (mysinkpad, FALSE);
+
+  GST_DEBUG ("stopping");
+
+  fail_unless (g_list_length (buffers) > 0);
+  buffer = g_list_first (buffers)->data;
+  fail_unless (buffer == buffer1);
+  ASSERT_BUFFER_REFCOUNT (buffer3, "buffer", 1);
+
+  /* it still triggers overrun when leaking */
+  fail_unless (overrun_count == 1);
+
+  /* cleanup */
+  gst_pad_set_active (mysrcpad, FALSE);
+  gst_buffer_unref (buffer3);
+  gst_check_teardown_src_pad (queue);
+  gst_check_teardown_sink_pad (queue);
+  cleanup_queue (queue);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_leaky_downstream)
+{
+  GstElement *queue;
+  GstBuffer *buffer1, *buffer2, *buffer3;
+  GstBuffer *buffer;
+
+  queue = setup_queue ();
+  mysrcpad = gst_check_setup_src_pad (queue, &srctemplate, NULL);
+  mysinkpad = gst_check_setup_sink_pad (queue, &sinktemplate, NULL);
+  g_object_set (G_OBJECT (queue), "max-size-buffers", 2, "leaky", 2, NULL);
+  gst_pad_set_active (mysrcpad, TRUE);
+
+  GST_DEBUG ("starting");
+
+  fail_unless (gst_element_set_state (queue,
+          GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+      "could not set to playing");
+
+  buffer1 = gst_buffer_new_and_alloc (4);
+  ASSERT_BUFFER_REFCOUNT (buffer1, "buffer", 1);
+  /* pushing gives away my reference ... */
+  gst_pad_push (mysrcpad, gst_buffer_ref (buffer1));
+
+  GST_DEBUG ("added 1st");
+  fail_unless (overrun_count == 0);
+  fail_unless (underrun_count == 0);
+
+  buffer2 = gst_buffer_new_and_alloc (4);
+  ASSERT_BUFFER_REFCOUNT (buffer2, "buffer", 1);
+  /* pushing gives away my reference ... */
+  gst_pad_push (mysrcpad, buffer2);
+
+  GST_DEBUG ("added 2nd");
+  fail_unless (overrun_count == 0);
+  fail_unless (underrun_count == 0);
+
+  buffer3 = gst_buffer_new_and_alloc (4);
+  ASSERT_BUFFER_REFCOUNT (buffer3, "buffer", 1);
+  /* pushing gives away my reference ... */
+  gst_pad_push (mysrcpad, buffer3);
+
+  /* start the src-task briefly and leak buffer1 */
+  gst_pad_set_active (mysinkpad, TRUE);
+
+  g_mutex_lock (check_mutex);
+  g_cond_wait (check_cond, check_mutex);
+  g_mutex_unlock (check_mutex);
+
+  gst_pad_set_active (mysinkpad, FALSE);
+
+  GST_DEBUG ("stopping");
+
+  fail_unless (g_list_length (buffers) > 0);
+  buffer = g_list_first (buffers)->data;
+  fail_unless (buffer == buffer2);
+  ASSERT_BUFFER_REFCOUNT (buffer1, "buffer", 1);
+
+  /* it still triggers overrun when leaking */
+  fail_unless (overrun_count == 1);
+
+  /* cleanup */
+  gst_pad_set_active (mysrcpad, FALSE);
+  gst_buffer_unref (buffer1);
+  gst_check_teardown_src_pad (queue);
+  gst_check_teardown_sink_pad (queue);
+  cleanup_queue (queue);
+}
+
+GST_END_TEST;
 
 Suite *
 queue_suite (void)
@@ -194,6 +339,8 @@ queue_suite (void)
   suite_add_tcase (s, tc_chain);
   tcase_add_test (tc_chain, test_non_leaky_underrun);
   tcase_add_test (tc_chain, test_non_leaky_overrun);
+  tcase_add_test (tc_chain, test_leaky_upstream);
+  tcase_add_test (tc_chain, test_leaky_downstream);
 
   return s;
 }