From: Tim-Philipp Müller Date: Mon, 24 May 2010 18:07:35 +0000 (+0100) Subject: checks: add multi-thread test for tagsetter X-Git-Tag: RELEASE-0.10.30~157 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c37bae46392a8f7a9342525d98cce5b12d1ef6e;p=platform%2Fupstream%2Fgstreamer.git checks: add multi-thread test for tagsetter See #619533. --- diff --git a/tests/check/gst/gsttagsetter.c b/tests/check/gst/gsttagsetter.c index 48c1308..2b16694 100644 --- a/tests/check/gst/gsttagsetter.c +++ b/tests/check/gst/gsttagsetter.c @@ -223,6 +223,103 @@ GST_START_TEST (test_merge_modes_skip_empty) } } +GST_END_TEST static int spin_and_wait = 1; +static int threads_running = 0; + +#define THREADS_CYCLES 1000 + +static gpointer +test_threads_thread_func1 (gpointer data) +{ + GstTagSetter *setter = GST_TAG_SETTER (data); + int i; + + g_atomic_int_inc (&threads_running); + while (g_atomic_int_get (&spin_and_wait)) + g_usleep (0); + + GST_INFO ("Go!"); + + for (i = 0; i < THREADS_CYCLES; ++i) { + gst_tag_setter_add_tags (setter, GST_TAG_MERGE_APPEND, GST_TAG_ARTIST, + "some artist", GST_TAG_TITLE, "some title", GST_TAG_TRACK_NUMBER, 6, + NULL); + } + + GST_INFO ("Done"); + + return NULL; +} + +static gpointer +test_threads_thread_func2 (gpointer data) +{ + GstTagSetter *setter = GST_TAG_SETTER (data); + int i; + + g_atomic_int_inc (&threads_running); + while (g_atomic_int_get (&spin_and_wait)) + g_usleep (0); + + GST_INFO ("Go!"); + + for (i = 0; i < THREADS_CYCLES; ++i) { + gst_tag_setter_add_tags (setter, GST_TAG_MERGE_PREPEND, GST_TAG_CODEC, + "MP42", GST_TAG_COMMENT, "deep insights go here", GST_TAG_TRACK_COUNT, + 10, NULL); + } + + GST_INFO ("Done"); + + return NULL; +} + +static gpointer +test_threads_thread_func3 (gpointer data) +{ + GstTagSetter *setter = GST_TAG_SETTER (data); + int i; + + g_atomic_int_inc (&threads_running); + while (g_atomic_int_get (&spin_and_wait)) + g_usleep (0); + + GST_INFO ("Go!"); + + for (i = 0; i < THREADS_CYCLES; ++i) { + gst_tag_setter_reset_tags (setter); + g_usleep (10); + } + + GST_INFO ("Done"); + + return NULL; +} + +GST_START_TEST (test_threads) +{ + GstTagSetter *setter; + GThread *threads[3]; + + setter = GST_TAG_SETTER (g_object_new (GST_TYPE_DUMMY_ENC, NULL)); + + spin_and_wait = TRUE; + threads[0] = g_thread_create (test_threads_thread_func1, setter, TRUE, NULL); + threads[1] = g_thread_create (test_threads_thread_func2, setter, TRUE, NULL); + threads[2] = g_thread_create (test_threads_thread_func3, setter, TRUE, NULL); + + while (g_atomic_int_get (&threads_running) < 3) + g_usleep (10); + + g_atomic_int_set (&spin_and_wait, FALSE); + + g_thread_join (threads[0]); + g_thread_join (threads[1]); + g_thread_join (threads[2]); + + g_object_unref (G_OBJECT (setter)); +} + GST_END_TEST static Suite * gst_tag_setter_suite (void) { @@ -233,6 +330,7 @@ gst_tag_setter_suite (void) tcase_add_test (tc_chain, test_merge); tcase_add_test (tc_chain, test_merge_modes); tcase_add_test (tc_chain, test_merge_modes_skip_empty); + tcase_add_test (tc_chain, test_threads); return s; }