diff options
author | Alexander Schrab <alexas@axis.com> | 2013-01-29 12:40:52 +0100 |
---|---|---|
committer | Tim-Philipp Müller <tim.muller@collabora.co.uk> | 2013-01-30 12:12:58 +0000 |
commit | fd366ce62834ac2065437531665431e775d726b8 (patch) | |
tree | 32805ae3f5376e734e1d4ddc12d1097d61140ac0 | |
parent | ca5628ad8c39ad8735430a2091970926cde3bd76 (diff) |
tests: unit test to trigger the queue/flushing race condition bug for allocation queries
https://bugzilla.gnome.org/show_bug.cgi?id=692691
-rw-r--r-- | tests/check/elements/queue.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/check/elements/queue.c b/tests/check/elements/queue.c index 6682d186dc..386bfb4cc6 100644 --- a/tests/check/elements/queue.c +++ b/tests/check/elements/queue.c @@ -756,6 +756,76 @@ GST_START_TEST (test_newsegment) GST_END_TEST; #endif +static gpointer +thread_func (gpointer data) +{ + int i = 0; + for (i = 0; i < 100; i++) { + GstCaps *caps; + GstQuery *query; + gboolean ok; + caps = gst_caps_new_any (); + query = gst_query_new_allocation (caps, FALSE); + ok = gst_pad_peer_query (mysrcpad, query); + gst_query_unref (query); + gst_caps_unref (caps); + query = NULL; + caps = NULL; + + if (!ok) + break; + } + + return NULL; +} + +static gboolean query_func (GstPad * pad, GstObject * parent, GstQuery * query); + +static gboolean +query_func (GstPad * pad, GstObject * parent, GstQuery * query) +{ + + g_usleep (1000); + return TRUE; +} + +GST_START_TEST (test_queries_while_flushing) +{ + GstEvent *event; + GThread *thread; + int i; + + mysinkpad = gst_check_setup_sink_pad (queue, &sinktemplate); + gst_pad_set_query_function (mysinkpad, query_func); + gst_pad_set_active (mysinkpad, TRUE); + + /* hard to reproduce, so just run it a few times in a row */ + for (i = 0; i < 500; ++i) { + GST_DEBUG ("starting"); + UNDERRUN_LOCK (); + fail_unless (gst_element_set_state (queue, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + UNDERRUN_WAIT (); + UNDERRUN_UNLOCK (); + + thread = g_thread_new ("deactivating thread", thread_func, NULL); + g_usleep (1000); + + event = gst_event_new_flush_start (); + gst_pad_push_event (mysrcpad, event); + + g_thread_join (thread); + + GST_DEBUG ("stopping"); + fail_unless (gst_element_set_state (queue, + GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, + "could not set to null"); + } +} + +GST_END_TEST; + static Suite * queue_suite (void) { @@ -770,6 +840,7 @@ queue_suite (void) tcase_add_test (tc_chain, test_leaky_downstream); tcase_add_test (tc_chain, test_time_level); tcase_add_test (tc_chain, test_time_level_task_not_started); + tcase_add_test (tc_chain, test_queries_while_flushing); #if 0 tcase_add_test (tc_chain, test_newsegment); #endif |