Added scheduler refcount test
authorWim Taymans <wim.taymans@gmail.com>
Mon, 10 Mar 2003 20:38:22 +0000 (20:38 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Mon, 10 Mar 2003 20:38:22 +0000 (20:38 +0000)
Original commit message from CVS:
Added scheduler refcount test

tests/old/testsuite/refcounting/Makefile.am
tests/old/testsuite/refcounting/sched.c [new file with mode: 0644]
testsuite/refcounting/Makefile.am
testsuite/refcounting/sched.c [new file with mode: 0644]

index 7df3fc4..0413c20 100644 (file)
@@ -3,7 +3,7 @@ tests_failing = element bin element_pad pad
 else
 tests_failing =
 endif
-tests_working = mainloop
+tests_working = mainloop sched
 
 element_SOURCES = element.c mem.c
 pad_SOURCES = pad.c mem.c
diff --git a/tests/old/testsuite/refcounting/sched.c b/tests/old/testsuite/refcounting/sched.c
new file mode 100644 (file)
index 0000000..a9e8629
--- /dev/null
@@ -0,0 +1,61 @@
+#include <gst/gst.h>
+
+gint i = 0;
+GstElement *pipeline;
+GstPadChainFunction oss_chain;
+
+static void
+create_pipeline (void)
+{
+  GstElement *src; 
+  GstElement *sink;
+  GstElement *id;
+  
+  pipeline = gst_pipeline_new ("pipeline");
+  src = gst_element_factory_make ("sinesrc", "src");
+  /**
+   * You need a sink with a loop-based element in here, if you want to kill opt, too.
+   * Osssink (chain-based) only breaks the basic scheduler.
+   */
+  sink = gst_element_factory_make ("alsasink", "sink");
+
+  gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
+  gst_element_link (src, sink);
+  
+  /** 
+   * now make the bug appear
+   * I believe it has something to do with 2 chains being created in the scheduler
+   * but I haven't looked at it yet
+   * If you comment out the next 4 lines, everything works fine.
+   * And no, it's not because of identity, you may use any other element.
+   */
+  gst_element_unlink (src, sink);
+  id = gst_element_factory_make ("identity", "id");
+  gst_bin_add (GST_BIN (pipeline), id);
+  gst_element_link_many (src, id, sink, NULL);
+  
+  /* This pipeline will not be removed properly once we unref it */
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+}  
+
+gint 
+main (gint argc, gchar *argv[]) 
+{
+  gst_init (&argc, &argv);
+  create_pipeline();
+  
+  while (i < 300) {
+    /**
+     * only inc i when it works, so the program hangs when _iterate returns false,
+     * which it does after the first pipeline isn't unref'd properly and the next
+     * osssink refuses to work.
+     */
+    if (gst_bin_iterate (GST_BIN (pipeline)))
+      i++;
+    if (i % 50 == 0) {
+      gst_object_unref (GST_OBJECT (pipeline));
+      create_pipeline ();
+    }
+  }
+  return 0;
+}
index 7df3fc4..0413c20 100644 (file)
@@ -3,7 +3,7 @@ tests_failing = element bin element_pad pad
 else
 tests_failing =
 endif
-tests_working = mainloop
+tests_working = mainloop sched
 
 element_SOURCES = element.c mem.c
 pad_SOURCES = pad.c mem.c
diff --git a/testsuite/refcounting/sched.c b/testsuite/refcounting/sched.c
new file mode 100644 (file)
index 0000000..a9e8629
--- /dev/null
@@ -0,0 +1,61 @@
+#include <gst/gst.h>
+
+gint i = 0;
+GstElement *pipeline;
+GstPadChainFunction oss_chain;
+
+static void
+create_pipeline (void)
+{
+  GstElement *src; 
+  GstElement *sink;
+  GstElement *id;
+  
+  pipeline = gst_pipeline_new ("pipeline");
+  src = gst_element_factory_make ("sinesrc", "src");
+  /**
+   * You need a sink with a loop-based element in here, if you want to kill opt, too.
+   * Osssink (chain-based) only breaks the basic scheduler.
+   */
+  sink = gst_element_factory_make ("alsasink", "sink");
+
+  gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
+  gst_element_link (src, sink);
+  
+  /** 
+   * now make the bug appear
+   * I believe it has something to do with 2 chains being created in the scheduler
+   * but I haven't looked at it yet
+   * If you comment out the next 4 lines, everything works fine.
+   * And no, it's not because of identity, you may use any other element.
+   */
+  gst_element_unlink (src, sink);
+  id = gst_element_factory_make ("identity", "id");
+  gst_bin_add (GST_BIN (pipeline), id);
+  gst_element_link_many (src, id, sink, NULL);
+  
+  /* This pipeline will not be removed properly once we unref it */
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+}  
+
+gint 
+main (gint argc, gchar *argv[]) 
+{
+  gst_init (&argc, &argv);
+  create_pipeline();
+  
+  while (i < 300) {
+    /**
+     * only inc i when it works, so the program hangs when _iterate returns false,
+     * which it does after the first pipeline isn't unref'd properly and the next
+     * osssink refuses to work.
+     */
+    if (gst_bin_iterate (GST_BIN (pipeline)))
+      i++;
+    if (i % 50 == 0) {
+      gst_object_unref (GST_OBJECT (pipeline));
+      create_pipeline ();
+    }
+  }
+  return 0;
+}