From b25231d5c8dca60458357c217b25ca6949bf33a9 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 18 Nov 2002 22:48:26 +0000 Subject: [PATCH] some more thread tests Original commit message from CVS: some more thread tests --- tests/old/testsuite/threads/threadd.c | 91 +++++++++++++++++++++++++++++++++++ tests/old/testsuite/threads/threade.c | 80 ++++++++++++++++++++++++++++++ tests/old/testsuite/threads/threadf.c | 82 +++++++++++++++++++++++++++++++ testsuite/threads/threadd.c | 91 +++++++++++++++++++++++++++++++++++ testsuite/threads/threade.c | 80 ++++++++++++++++++++++++++++++ testsuite/threads/threadf.c | 82 +++++++++++++++++++++++++++++++ 6 files changed, 506 insertions(+) create mode 100644 tests/old/testsuite/threads/threadd.c create mode 100644 tests/old/testsuite/threads/threade.c create mode 100644 tests/old/testsuite/threads/threadf.c create mode 100644 testsuite/threads/threadd.c create mode 100644 testsuite/threads/threade.c create mode 100644 testsuite/threads/threadf.c diff --git a/tests/old/testsuite/threads/threadd.c b/tests/old/testsuite/threads/threadd.c new file mode 100644 index 0000000..e38d266 --- /dev/null +++ b/tests/old/testsuite/threads/threadd.c @@ -0,0 +1,91 @@ +#include + +/* threadc.c + * this tests if we can make a GstThread, with enough cothreads to stress it + */ + +#define MAX_IDENTITIES 29 +#define RUNS_PER_IDENTITY 5 + +gboolean running = FALSE; +gboolean done = FALSE; + +static void +construct_pipeline (GstElement *pipeline, gint identities) +{ + GstElement *src, *sink, *identity; + GstElement *from; + int i; + + src = gst_element_factory_make ("fakesrc", NULL); + sink = gst_element_factory_make ("fakesink", NULL); + g_assert (src); + g_assert (sink); + gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); + from = src; + + for (i = 0; i < identities; ++i) + { + identity = gst_element_factory_make ("identity", NULL); + g_assert (identity); + gst_bin_add (GST_BIN (pipeline), identity); + gst_element_connect (from, identity); + from = identity; + } + gst_element_connect (identity, sink); + + g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL); +} + +void +state_changed (GstElement *el, gint arg1, gint arg2, gpointer user_data) +{ + GstElementState state = gst_element_get_state (el); + + g_print ("element %s has changed state to %s\n", + GST_ELEMENT_NAME (el), + gst_element_state_get_name (state)); + if (state == GST_STATE_PLAYING) running = TRUE; + /* if we move from PLAYING to PAUSED, we're done */ + if (state == GST_STATE_PAUSED && running) + done = TRUE; +} + +int +main (gint argc, gchar *argv[]) +{ + int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY; + int i; + gulong id; + GstElement *thread; + + gst_init (&argc, &argv); + + for (i = 0; i < runs; ++i) + { + thread = gst_thread_new ("main_thread"); + g_assert (thread); + + /* connect state change signal */ + id = g_signal_connect (G_OBJECT (thread), "state_change", + G_CALLBACK (state_changed), NULL); + construct_pipeline (thread, i / RUNS_PER_IDENTITY + 1); + + g_print ("Setting thread to play with %d identities\n", + i / RUNS_PER_IDENTITY + 1); + done = FALSE; + gst_element_set_state (thread, GST_STATE_PLAYING); + + g_print ("Waiting for thread PLAYING->PAUSED\n"); + while (!done) /* do nothing */; + running = FALSE; + g_print ("Coming out of the main GStreamer loop\n"); + g_signal_handler_disconnect (G_OBJECT (thread), id); + gst_element_set_state (thread, GST_STATE_NULL); + g_print ("Unreffing thread\n"); + g_object_unref (G_OBJECT (thread)); + } + + return 0; +} + diff --git a/tests/old/testsuite/threads/threade.c b/tests/old/testsuite/threads/threade.c new file mode 100644 index 0000000..9765459 --- /dev/null +++ b/tests/old/testsuite/threads/threade.c @@ -0,0 +1,80 @@ +#include + +/* threadc.c + * this tests if we can make a GstBin and iterate it inside a GThread + */ + +#define MAX_IDENTITIES 29 +#define RUNS_PER_IDENTITY 5 + +gboolean running = FALSE; +gboolean done = FALSE; + +static void +construct_pipeline (GstElement *pipeline, gint identities) +{ + GstElement *src, *sink, *identity; + GstElement *from; + int i; + + src = gst_element_factory_make ("fakesrc", NULL); + sink = gst_element_factory_make ("fakesink", NULL); + g_assert (src); + g_assert (sink); + gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); + from = src; + + for (i = 0; i < identities; ++i) + { + identity = gst_element_factory_make ("identity", NULL); + g_assert (identity); + gst_bin_add (GST_BIN (pipeline), identity); + gst_element_connect (from, identity); + from = identity; + } + gst_element_connect (identity, sink); + + g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL); +} + +static void +iterator (GstElement *bin) +{ + gst_element_set_state (bin, GST_STATE_PLAYING); + while (gst_bin_iterate (GST_BIN (bin))) g_print ("+"); + g_print ("\n"); + done = TRUE; +} + +int +main (gint argc, gchar *argv[]) +{ + int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY; + int i; + GstElement *pipeline; + + g_thread_init (NULL); + gst_init (&argc, &argv); + + for (i = 0; i < runs; ++i) + { + pipeline = gst_pipeline_new ("main_pipeline"); + g_assert (pipeline); + + /* connect state change signal */ + construct_pipeline (pipeline, i / RUNS_PER_IDENTITY + 1); + + done = FALSE; + g_thread_create ((GThreadFunc) iterator, pipeline, FALSE, NULL); + g_print ("Created GThread\n"); + + g_print ("Waiting for thread PLAYING->PAUSED\n"); + while (!done) /* do nothing */; + running = FALSE; + g_print ("Unreffing pipeline\n"); + g_object_unref (G_OBJECT (pipeline)); + } + + return 0; +} + diff --git a/tests/old/testsuite/threads/threadf.c b/tests/old/testsuite/threads/threadf.c new file mode 100644 index 0000000..32b66aa --- /dev/null +++ b/tests/old/testsuite/threads/threadf.c @@ -0,0 +1,82 @@ +#include + +/* threadf.c + * this tests if we can make a GThread and construct and interate a pipeline + * inside it + * used to fail because of cothread ctx key not being reset on context + * destroy + */ + +#define MAX_IDENTITIES 29 +#define RUNS_PER_IDENTITY 5 + +gboolean running = FALSE; +gboolean done = FALSE; + +static void +construct_pipeline (GstElement *pipeline, gint identities) +{ + GstElement *src, *sink, *identity; + GstElement *from; + int i; + + src = gst_element_factory_make ("fakesrc", NULL); + sink = gst_element_factory_make ("fakesink", NULL); + g_assert (src); + g_assert (sink); + gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); + from = src; + + for (i = 0; i < identities; ++i) + { + identity = gst_element_factory_make ("identity", NULL); + g_assert (identity); + gst_bin_add (GST_BIN (pipeline), identity); + if (!(gst_element_connect (from, identity))) + g_print ("Warning: can't connect identity with previous element\n"); + from = identity; + } + gst_element_connect (identity, sink); + + g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL); +} + +static void +thread (void) +{ + int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY; + int i; + GstElement *pipeline; + + for (i = 0; i < runs; ++i) + { + pipeline = gst_pipeline_new ("main_pipeline"); + g_assert (pipeline); + + g_print ("Run %d, using %d identities\n", i, i / RUNS_PER_IDENTITY + 1); + construct_pipeline (pipeline, i / RUNS_PER_IDENTITY + 1); + if (!gst_element_set_state (pipeline, GST_STATE_PLAYING)) + g_print ("WARNING: can't set pipeline to play\n"); + while (gst_bin_iterate (GST_BIN (pipeline))) + g_print ("+"); + g_print ("\n"); + g_print ("Unreffing pipeline\n"); + g_object_unref (G_OBJECT (pipeline)); + } +} + +int +main (gint argc, gchar *argv[]) +{ + done = FALSE; + + g_thread_init (NULL); + gst_init (&argc, &argv); + + g_thread_create ((GThreadFunc) thread, NULL, FALSE, NULL); + g_print ("main: created GThread\n"); + while (!done) sleep (1); + g_print ("main: done\n"); + return 0; +} + diff --git a/testsuite/threads/threadd.c b/testsuite/threads/threadd.c new file mode 100644 index 0000000..e38d266 --- /dev/null +++ b/testsuite/threads/threadd.c @@ -0,0 +1,91 @@ +#include + +/* threadc.c + * this tests if we can make a GstThread, with enough cothreads to stress it + */ + +#define MAX_IDENTITIES 29 +#define RUNS_PER_IDENTITY 5 + +gboolean running = FALSE; +gboolean done = FALSE; + +static void +construct_pipeline (GstElement *pipeline, gint identities) +{ + GstElement *src, *sink, *identity; + GstElement *from; + int i; + + src = gst_element_factory_make ("fakesrc", NULL); + sink = gst_element_factory_make ("fakesink", NULL); + g_assert (src); + g_assert (sink); + gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); + from = src; + + for (i = 0; i < identities; ++i) + { + identity = gst_element_factory_make ("identity", NULL); + g_assert (identity); + gst_bin_add (GST_BIN (pipeline), identity); + gst_element_connect (from, identity); + from = identity; + } + gst_element_connect (identity, sink); + + g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL); +} + +void +state_changed (GstElement *el, gint arg1, gint arg2, gpointer user_data) +{ + GstElementState state = gst_element_get_state (el); + + g_print ("element %s has changed state to %s\n", + GST_ELEMENT_NAME (el), + gst_element_state_get_name (state)); + if (state == GST_STATE_PLAYING) running = TRUE; + /* if we move from PLAYING to PAUSED, we're done */ + if (state == GST_STATE_PAUSED && running) + done = TRUE; +} + +int +main (gint argc, gchar *argv[]) +{ + int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY; + int i; + gulong id; + GstElement *thread; + + gst_init (&argc, &argv); + + for (i = 0; i < runs; ++i) + { + thread = gst_thread_new ("main_thread"); + g_assert (thread); + + /* connect state change signal */ + id = g_signal_connect (G_OBJECT (thread), "state_change", + G_CALLBACK (state_changed), NULL); + construct_pipeline (thread, i / RUNS_PER_IDENTITY + 1); + + g_print ("Setting thread to play with %d identities\n", + i / RUNS_PER_IDENTITY + 1); + done = FALSE; + gst_element_set_state (thread, GST_STATE_PLAYING); + + g_print ("Waiting for thread PLAYING->PAUSED\n"); + while (!done) /* do nothing */; + running = FALSE; + g_print ("Coming out of the main GStreamer loop\n"); + g_signal_handler_disconnect (G_OBJECT (thread), id); + gst_element_set_state (thread, GST_STATE_NULL); + g_print ("Unreffing thread\n"); + g_object_unref (G_OBJECT (thread)); + } + + return 0; +} + diff --git a/testsuite/threads/threade.c b/testsuite/threads/threade.c new file mode 100644 index 0000000..9765459 --- /dev/null +++ b/testsuite/threads/threade.c @@ -0,0 +1,80 @@ +#include + +/* threadc.c + * this tests if we can make a GstBin and iterate it inside a GThread + */ + +#define MAX_IDENTITIES 29 +#define RUNS_PER_IDENTITY 5 + +gboolean running = FALSE; +gboolean done = FALSE; + +static void +construct_pipeline (GstElement *pipeline, gint identities) +{ + GstElement *src, *sink, *identity; + GstElement *from; + int i; + + src = gst_element_factory_make ("fakesrc", NULL); + sink = gst_element_factory_make ("fakesink", NULL); + g_assert (src); + g_assert (sink); + gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); + from = src; + + for (i = 0; i < identities; ++i) + { + identity = gst_element_factory_make ("identity", NULL); + g_assert (identity); + gst_bin_add (GST_BIN (pipeline), identity); + gst_element_connect (from, identity); + from = identity; + } + gst_element_connect (identity, sink); + + g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL); +} + +static void +iterator (GstElement *bin) +{ + gst_element_set_state (bin, GST_STATE_PLAYING); + while (gst_bin_iterate (GST_BIN (bin))) g_print ("+"); + g_print ("\n"); + done = TRUE; +} + +int +main (gint argc, gchar *argv[]) +{ + int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY; + int i; + GstElement *pipeline; + + g_thread_init (NULL); + gst_init (&argc, &argv); + + for (i = 0; i < runs; ++i) + { + pipeline = gst_pipeline_new ("main_pipeline"); + g_assert (pipeline); + + /* connect state change signal */ + construct_pipeline (pipeline, i / RUNS_PER_IDENTITY + 1); + + done = FALSE; + g_thread_create ((GThreadFunc) iterator, pipeline, FALSE, NULL); + g_print ("Created GThread\n"); + + g_print ("Waiting for thread PLAYING->PAUSED\n"); + while (!done) /* do nothing */; + running = FALSE; + g_print ("Unreffing pipeline\n"); + g_object_unref (G_OBJECT (pipeline)); + } + + return 0; +} + diff --git a/testsuite/threads/threadf.c b/testsuite/threads/threadf.c new file mode 100644 index 0000000..32b66aa --- /dev/null +++ b/testsuite/threads/threadf.c @@ -0,0 +1,82 @@ +#include + +/* threadf.c + * this tests if we can make a GThread and construct and interate a pipeline + * inside it + * used to fail because of cothread ctx key not being reset on context + * destroy + */ + +#define MAX_IDENTITIES 29 +#define RUNS_PER_IDENTITY 5 + +gboolean running = FALSE; +gboolean done = FALSE; + +static void +construct_pipeline (GstElement *pipeline, gint identities) +{ + GstElement *src, *sink, *identity; + GstElement *from; + int i; + + src = gst_element_factory_make ("fakesrc", NULL); + sink = gst_element_factory_make ("fakesink", NULL); + g_assert (src); + g_assert (sink); + gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); + from = src; + + for (i = 0; i < identities; ++i) + { + identity = gst_element_factory_make ("identity", NULL); + g_assert (identity); + gst_bin_add (GST_BIN (pipeline), identity); + if (!(gst_element_connect (from, identity))) + g_print ("Warning: can't connect identity with previous element\n"); + from = identity; + } + gst_element_connect (identity, sink); + + g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL); +} + +static void +thread (void) +{ + int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY; + int i; + GstElement *pipeline; + + for (i = 0; i < runs; ++i) + { + pipeline = gst_pipeline_new ("main_pipeline"); + g_assert (pipeline); + + g_print ("Run %d, using %d identities\n", i, i / RUNS_PER_IDENTITY + 1); + construct_pipeline (pipeline, i / RUNS_PER_IDENTITY + 1); + if (!gst_element_set_state (pipeline, GST_STATE_PLAYING)) + g_print ("WARNING: can't set pipeline to play\n"); + while (gst_bin_iterate (GST_BIN (pipeline))) + g_print ("+"); + g_print ("\n"); + g_print ("Unreffing pipeline\n"); + g_object_unref (G_OBJECT (pipeline)); + } +} + +int +main (gint argc, gchar *argv[]) +{ + done = FALSE; + + g_thread_init (NULL); + gst_init (&argc, &argv); + + g_thread_create ((GThreadFunc) thread, NULL, FALSE, NULL); + g_print ("main: created GThread\n"); + while (!done) sleep (1); + g_print ("main: done\n"); + return 0; +} + -- 2.7.4