checks: add multi-thread test for tagsetter

See #619533.
This commit is contained in:
Tim-Philipp Müller 2010-05-24 19:07:35 +01:00
parent 3ea8b47445
commit 4c37bae463

View file

@ -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;
}