check/: wait on thread to die so we can check refcount correctly
authorThomas Vander Stichele <thomas@apestaart.org>
Wed, 19 Oct 2005 11:43:42 +0000 (11:43 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Wed, 19 Oct 2005 11:43:42 +0000 (11:43 +0000)
Original commit message from CVS:

* check/gst/gstbin.c: (GST_START_TEST):
* check/gst/gstghostpad.c: (GST_START_TEST):
* check/pipelines/cleanup.c: (GST_START_TEST):
wait on thread to die so we can check refcount correctly

ChangeLog
check/gst/gstbin.c
check/gst/gstghostpad.c
check/pipelines/cleanup.c
tests/check/gst/gstbin.c
tests/check/gst/gstghostpad.c
tests/check/pipelines/cleanup.c

index e61da3f..52a2293 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-10-19  Thomas Vander Stichele  <thomas at apestaart dot org>
+
+       * check/gst/gstbin.c: (GST_START_TEST):
+       * check/gst/gstghostpad.c: (GST_START_TEST):
+       * check/pipelines/cleanup.c: (GST_START_TEST):
+         wait on thread to die so we can check refcount correctly
+
 2005-10-18  Wim Taymans  <wim@fluendo.com>
 
        * check/pipelines/stress.c: (GST_START_TEST):
index 41fb65f..e3f0667 100644 (file)
@@ -270,6 +270,10 @@ GST_START_TEST (test_message_state_changed_children)
   fail_unless (current == GST_STATE_PAUSED);
   fail_unless (pending == GST_STATE_VOID_PENDING);
 
+  /* wait for async thread to settle down */
+  while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 2)
+    THREAD_SWITCH ();
+
   /* each object is referenced by a message;
    * base_sink_chain has taken a refcount on the sink, and is blocked on
    * preroll */
@@ -654,6 +658,9 @@ GST_START_TEST (test_children_state_change_order_semi_sink)
   pop_messages (bus, 4);        /* pop playing => paused messages off the bus */
   pop_messages (bus, 4);        /* pop paused => ready messages off the bus */
 
+  while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 1)
+    THREAD_SWITCH ();
+
   ASSERT_OBJECT_REFCOUNT (src, "src", 1);
   ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
   ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
index a5fd4fe..c410b52 100644 (file)
 
 #include <gst/check/gstcheck.h>
 
-static void
-assert_gstrefcount (gpointer p, gint i)
-{
-  if (GST_OBJECT_REFCOUNT_VALUE (p) != i)
-    g_critical ("Expected refcount %d for %s, got %d", i, GST_OBJECT_NAME (p),
-        GST_OBJECT_REFCOUNT_VALUE (p));
-}
-
 /* test if removing a bin also cleans up the ghostpads
  */
 GST_START_TEST (test_remove1)
@@ -237,15 +229,15 @@ GST_START_TEST (test_ghost_pads)
 
   /* all objects above have one refcount owned by us as well */
 
-  assert_gstrefcount (fsrc, 3); /* parent and gisrc */
-  assert_gstrefcount (gsink, 2);        /* parent */
-  assert_gstrefcount (gsrc, 2); /* parent */
-  assert_gstrefcount (fsink, 3);        /* parent and gisink */
+  ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 3);     /* parent and gisrc */
+  ASSERT_OBJECT_REFCOUNT (gsink, "gsink", 2);   /* parent */
+  ASSERT_OBJECT_REFCOUNT (gsrc, "gsrc", 2);     /* parent */
+  ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 3);   /* parent and gisink */
 
-  assert_gstrefcount (gisrc, 2);        /* parent */
-  assert_gstrefcount (isink, 3);        /* parent and gsink */
-  assert_gstrefcount (gisink, 2);       /* parent */
-  assert_gstrefcount (isrc, 3); /* parent and gsrc */
+  ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 2);   /* parent */
+  ASSERT_OBJECT_REFCOUNT (isink, "isink", 3);   /* parent and gsink */
+  ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 2); /* parent */
+  ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 3);     /* parent and gsrc */
 
   ret = gst_element_set_state (b1, GST_STATE_PLAYING);
   ret = gst_element_get_state (b1, NULL, NULL, GST_CLOCK_TIME_NONE);
@@ -259,29 +251,33 @@ GST_START_TEST (test_ghost_pads)
   /* unreffing the bin will unref all elements, which will unlink and unparent
    * all pads */
 
-  assert_gstrefcount (fsrc, 2); /* gisrc */
-  assert_gstrefcount (gsink, 1);
-  assert_gstrefcount (gsrc, 1);
-  assert_gstrefcount (fsink, 2);        /* gisink */
+  /* wait for thread to settle down */
+  while (GST_OBJECT_REFCOUNT_VALUE (fsrc) > 2)
+    THREAD_SWITCH ();
+
+  ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 2);     /* gisrc */
+  ASSERT_OBJECT_REFCOUNT (gsink, "gsink", 1);
+  ASSERT_OBJECT_REFCOUNT (gsrc, "gsink", 1);
+  ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 2);   /* gisink */
 
-  assert_gstrefcount (gisrc, 1);        /* gsink */
-  assert_gstrefcount (isink, 2);        /* gsink */
-  assert_gstrefcount (gisink, 1);       /* gsrc */
-  assert_gstrefcount (isrc, 2); /* gsrc */
+  ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 1);   /* gsink */
+  ASSERT_OBJECT_REFCOUNT (isink, "isink", 2);   /* gsink */
+  ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 1); /* gsrc */
+  ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 2);     /* gsrc */
 
   gst_object_unref (gsink);
-  assert_gstrefcount (isink, 1);
-  assert_gstrefcount (gisrc, 1);
-  assert_gstrefcount (fsrc, 2); /* gisrc */
+  ASSERT_OBJECT_REFCOUNT (isink, "isink", 1);
+  ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 1);
+  ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 2);     /* gisrc */
   gst_object_unref (gisrc);
-  assert_gstrefcount (fsrc, 1);
+  ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 1);
 
   gst_object_unref (gsrc);
-  assert_gstrefcount (isrc, 1);
-  assert_gstrefcount (gisink, 1);
-  assert_gstrefcount (fsink, 2);        /* gisrc */
+  ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 1);
+  ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 1);
+  ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 2);   /* gisrc */
   gst_object_unref (gisink);
-  assert_gstrefcount (fsink, 1);
+  ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 1);
 
   gst_object_unref (fsrc);
   gst_object_unref (isrc);
index a35c923..b268e46 100644 (file)
@@ -78,7 +78,6 @@ run_pipeline (GstElement * pipeline, gchar * descr,
 GST_START_TEST (test_pipeline_unref)
 {
   gchar *s;
-  gint count;
   GstElement *pipeline, *src, *sink;
 
   s = "fakesrc name=src num-buffers=20 ! fakesink name=sink";
@@ -91,15 +90,17 @@ GST_START_TEST (test_pipeline_unref)
 
   run_pipeline (pipeline, s, GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED,
       GST_MESSAGE_EOS);
-  count = GST_OBJECT_REFCOUNT_VALUE (src);
-  fail_unless (count == 1, "src has a refcount of %d instead of 1", count);
-  count = GST_OBJECT_REFCOUNT_VALUE (sink);
-  fail_unless (count == 1, "sink has a refcount of %d instead of 1", count);
+  while (GST_OBJECT_REFCOUNT_VALUE (src) > 1)
+    THREAD_SWITCH ();
+  ASSERT_OBJECT_REFCOUNT (src, "src", 1);
+  ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
   gst_object_unref (src);
   gst_object_unref (sink);
 }
 
-GST_END_TEST Suite *
+GST_END_TEST;
+
+Suite *
 cleanup_suite (void)
 {
   Suite *s = suite_create ("Pipeline cleanup");
index 41fb65f..e3f0667 100644 (file)
@@ -270,6 +270,10 @@ GST_START_TEST (test_message_state_changed_children)
   fail_unless (current == GST_STATE_PAUSED);
   fail_unless (pending == GST_STATE_VOID_PENDING);
 
+  /* wait for async thread to settle down */
+  while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 2)
+    THREAD_SWITCH ();
+
   /* each object is referenced by a message;
    * base_sink_chain has taken a refcount on the sink, and is blocked on
    * preroll */
@@ -654,6 +658,9 @@ GST_START_TEST (test_children_state_change_order_semi_sink)
   pop_messages (bus, 4);        /* pop playing => paused messages off the bus */
   pop_messages (bus, 4);        /* pop paused => ready messages off the bus */
 
+  while (GST_OBJECT_REFCOUNT_VALUE (pipeline) > 1)
+    THREAD_SWITCH ();
+
   ASSERT_OBJECT_REFCOUNT (src, "src", 1);
   ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
   ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
index a5fd4fe..c410b52 100644 (file)
 
 #include <gst/check/gstcheck.h>
 
-static void
-assert_gstrefcount (gpointer p, gint i)
-{
-  if (GST_OBJECT_REFCOUNT_VALUE (p) != i)
-    g_critical ("Expected refcount %d for %s, got %d", i, GST_OBJECT_NAME (p),
-        GST_OBJECT_REFCOUNT_VALUE (p));
-}
-
 /* test if removing a bin also cleans up the ghostpads
  */
 GST_START_TEST (test_remove1)
@@ -237,15 +229,15 @@ GST_START_TEST (test_ghost_pads)
 
   /* all objects above have one refcount owned by us as well */
 
-  assert_gstrefcount (fsrc, 3); /* parent and gisrc */
-  assert_gstrefcount (gsink, 2);        /* parent */
-  assert_gstrefcount (gsrc, 2); /* parent */
-  assert_gstrefcount (fsink, 3);        /* parent and gisink */
+  ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 3);     /* parent and gisrc */
+  ASSERT_OBJECT_REFCOUNT (gsink, "gsink", 2);   /* parent */
+  ASSERT_OBJECT_REFCOUNT (gsrc, "gsrc", 2);     /* parent */
+  ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 3);   /* parent and gisink */
 
-  assert_gstrefcount (gisrc, 2);        /* parent */
-  assert_gstrefcount (isink, 3);        /* parent and gsink */
-  assert_gstrefcount (gisink, 2);       /* parent */
-  assert_gstrefcount (isrc, 3); /* parent and gsrc */
+  ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 2);   /* parent */
+  ASSERT_OBJECT_REFCOUNT (isink, "isink", 3);   /* parent and gsink */
+  ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 2); /* parent */
+  ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 3);     /* parent and gsrc */
 
   ret = gst_element_set_state (b1, GST_STATE_PLAYING);
   ret = gst_element_get_state (b1, NULL, NULL, GST_CLOCK_TIME_NONE);
@@ -259,29 +251,33 @@ GST_START_TEST (test_ghost_pads)
   /* unreffing the bin will unref all elements, which will unlink and unparent
    * all pads */
 
-  assert_gstrefcount (fsrc, 2); /* gisrc */
-  assert_gstrefcount (gsink, 1);
-  assert_gstrefcount (gsrc, 1);
-  assert_gstrefcount (fsink, 2);        /* gisink */
+  /* wait for thread to settle down */
+  while (GST_OBJECT_REFCOUNT_VALUE (fsrc) > 2)
+    THREAD_SWITCH ();
+
+  ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 2);     /* gisrc */
+  ASSERT_OBJECT_REFCOUNT (gsink, "gsink", 1);
+  ASSERT_OBJECT_REFCOUNT (gsrc, "gsink", 1);
+  ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 2);   /* gisink */
 
-  assert_gstrefcount (gisrc, 1);        /* gsink */
-  assert_gstrefcount (isink, 2);        /* gsink */
-  assert_gstrefcount (gisink, 1);       /* gsrc */
-  assert_gstrefcount (isrc, 2); /* gsrc */
+  ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 1);   /* gsink */
+  ASSERT_OBJECT_REFCOUNT (isink, "isink", 2);   /* gsink */
+  ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 1); /* gsrc */
+  ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 2);     /* gsrc */
 
   gst_object_unref (gsink);
-  assert_gstrefcount (isink, 1);
-  assert_gstrefcount (gisrc, 1);
-  assert_gstrefcount (fsrc, 2); /* gisrc */
+  ASSERT_OBJECT_REFCOUNT (isink, "isink", 1);
+  ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 1);
+  ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 2);     /* gisrc */
   gst_object_unref (gisrc);
-  assert_gstrefcount (fsrc, 1);
+  ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 1);
 
   gst_object_unref (gsrc);
-  assert_gstrefcount (isrc, 1);
-  assert_gstrefcount (gisink, 1);
-  assert_gstrefcount (fsink, 2);        /* gisrc */
+  ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 1);
+  ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 1);
+  ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 2);   /* gisrc */
   gst_object_unref (gisink);
-  assert_gstrefcount (fsink, 1);
+  ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 1);
 
   gst_object_unref (fsrc);
   gst_object_unref (isrc);
index a35c923..b268e46 100644 (file)
@@ -78,7 +78,6 @@ run_pipeline (GstElement * pipeline, gchar * descr,
 GST_START_TEST (test_pipeline_unref)
 {
   gchar *s;
-  gint count;
   GstElement *pipeline, *src, *sink;
 
   s = "fakesrc name=src num-buffers=20 ! fakesink name=sink";
@@ -91,15 +90,17 @@ GST_START_TEST (test_pipeline_unref)
 
   run_pipeline (pipeline, s, GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED,
       GST_MESSAGE_EOS);
-  count = GST_OBJECT_REFCOUNT_VALUE (src);
-  fail_unless (count == 1, "src has a refcount of %d instead of 1", count);
-  count = GST_OBJECT_REFCOUNT_VALUE (sink);
-  fail_unless (count == 1, "sink has a refcount of %d instead of 1", count);
+  while (GST_OBJECT_REFCOUNT_VALUE (src) > 1)
+    THREAD_SWITCH ();
+  ASSERT_OBJECT_REFCOUNT (src, "src", 1);
+  ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
   gst_object_unref (src);
   gst_object_unref (sink);
 }
 
-GST_END_TEST Suite *
+GST_END_TEST;
+
+Suite *
 cleanup_suite (void)
 {
   Suite *s = suite_create ("Pipeline cleanup");