mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-08 10:31:05 +00:00
64086e2970
Original commit message from CVS: * tests/check/elements/fakesink.c: * tests/check/elements/fakesrc.c: * tests/check/elements/fdsrc.c: * tests/check/elements/identity.c: * tests/check/generic/sinks.c: (gst_sinks_suite): * tests/check/generic/states.c: * tests/check/gst/gst.c: * tests/check/gst/gstabi.c: * tests/check/gst/gstbin.c: * tests/check/gst/gstbuffer.c: (gst_buffer_suite): * tests/check/gst/gstbus.c: (gst_bus_suite): * tests/check/gst/gstcaps.c: (GST_START_TEST): * tests/check/gst/gstelement.c: * tests/check/gst/gstevent.c: (gst_event_suite): * tests/check/gst/gstghostpad.c: * tests/check/gst/gstiterator.c: (gst_iterator_suite): * tests/check/gst/gstmessage.c: (gst_message_suite): * tests/check/gst/gstminiobject.c: * tests/check/gst/gstobject.c: * tests/check/gst/gstpad.c: * tests/check/gst/gstpipeline.c: * tests/check/gst/gstplugin.c: * tests/check/gst/gstquery.c: (gst_query_suite): * tests/check/gst/gstsegment.c: (gst_segment_suite): * tests/check/gst/gststructure.c: * tests/check/gst/gstsystemclock.c: * tests/check/gst/gsttag.c: * tests/check/gst/gsttask.c: (gst_task_suite): * tests/check/gst/gstutils.c: * tests/check/gst/gstvalue.c: * tests/check/libs/adapter.c: * tests/check/libs/basesrc.c: * tests/check/libs/collectpads.c: * tests/check/libs/controller.c: * tests/check/libs/gdp.c: (gst_dp_suite): * tests/check/libs/gstnetclientclock.c: * tests/check/libs/gstnettimeprovider.c: * tests/check/libs/libsabi.c: (libsabi_suite): * tests/check/libs/typefindhelper.c: * tests/check/pipelines/cleanup.c: * tests/check/pipelines/parse-launch.c: * tests/check/pipelines/simple-launch-lines.c: * tests/check/pipelines/stress.c: (stress_suite): use the new macro
203 lines
4.2 KiB
C
203 lines
4.2 KiB
C
/* GStreamer
|
|
* Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
|
|
*
|
|
* gstelement.c: Unit test for GstElement
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
static GMutex *task_lock;
|
|
static GCond *task_cond;
|
|
|
|
static GStaticRecMutex task_mutex = G_STATIC_REC_MUTEX_INIT;
|
|
|
|
static void
|
|
task_func2 (void *data)
|
|
{
|
|
gboolean ret;
|
|
GstTask *t = *((GstTask **) data);
|
|
|
|
g_mutex_lock (task_lock);
|
|
GST_DEBUG ("signal");
|
|
g_cond_signal (task_cond);
|
|
g_mutex_unlock (task_lock);
|
|
|
|
ASSERT_WARNING (ret = gst_task_join (t));
|
|
fail_unless (ret == FALSE);
|
|
}
|
|
|
|
GST_START_TEST (test_join)
|
|
{
|
|
GstTask *t;
|
|
gboolean ret;
|
|
|
|
t = gst_task_create (task_func2, &t);
|
|
fail_if (t == NULL);
|
|
|
|
gst_task_set_lock (t, &task_mutex);
|
|
|
|
task_cond = g_cond_new ();
|
|
task_lock = g_mutex_new ();
|
|
|
|
g_mutex_lock (task_lock);
|
|
GST_DEBUG ("starting");
|
|
ret = gst_task_start (t);
|
|
fail_unless (ret == TRUE);
|
|
/* wait for it to spin up */
|
|
GST_DEBUG ("waiting");
|
|
g_cond_wait (task_cond, task_lock);
|
|
GST_DEBUG ("done waiting");
|
|
g_mutex_unlock (task_lock);
|
|
|
|
GST_DEBUG ("joining");
|
|
ret = gst_task_join (t);
|
|
fail_unless (ret == TRUE);
|
|
|
|
gst_object_unref (t);
|
|
}
|
|
|
|
GST_END_TEST;
|
|
|
|
static void
|
|
task_func (void *data)
|
|
{
|
|
g_mutex_lock (task_lock);
|
|
GST_DEBUG ("signal");
|
|
g_cond_signal (task_cond);
|
|
g_mutex_unlock (task_lock);
|
|
}
|
|
|
|
GST_START_TEST (test_lock_start)
|
|
{
|
|
GstTask *t;
|
|
gboolean ret;
|
|
|
|
t = gst_task_create (task_func, NULL);
|
|
fail_if (t == NULL);
|
|
|
|
gst_task_set_lock (t, &task_mutex);
|
|
|
|
task_cond = g_cond_new ();
|
|
task_lock = g_mutex_new ();
|
|
|
|
g_mutex_lock (task_lock);
|
|
GST_DEBUG ("starting");
|
|
ret = gst_task_start (t);
|
|
fail_unless (ret == TRUE);
|
|
/* wait for it to spin up */
|
|
GST_DEBUG ("waiting");
|
|
g_cond_wait (task_cond, task_lock);
|
|
GST_DEBUG ("done waiting");
|
|
g_mutex_unlock (task_lock);
|
|
|
|
/* cannot set mutex now */
|
|
ASSERT_WARNING (gst_task_set_lock (t, &task_mutex));
|
|
|
|
GST_DEBUG ("joining");
|
|
ret = gst_task_join (t);
|
|
fail_unless (ret == TRUE);
|
|
|
|
gst_object_unref (t);
|
|
}
|
|
|
|
GST_END_TEST;
|
|
|
|
GST_START_TEST (test_lock)
|
|
{
|
|
GstTask *t;
|
|
gboolean ret;
|
|
|
|
t = gst_task_create (task_func, NULL);
|
|
fail_if (t == NULL);
|
|
|
|
gst_task_set_lock (t, &task_mutex);
|
|
|
|
GST_DEBUG ("pause");
|
|
ret = gst_task_pause (t);
|
|
fail_unless (ret == TRUE);
|
|
|
|
g_usleep (1 * G_USEC_PER_SEC / 2);
|
|
|
|
GST_DEBUG ("joining");
|
|
ret = gst_task_join (t);
|
|
fail_unless (ret == TRUE);
|
|
|
|
g_usleep (1 * G_USEC_PER_SEC / 2);
|
|
|
|
gst_object_unref (t);
|
|
}
|
|
|
|
GST_END_TEST;
|
|
|
|
GST_START_TEST (test_no_lock)
|
|
{
|
|
GstTask *t;
|
|
gboolean ret;
|
|
|
|
t = gst_task_create (task_func, NULL);
|
|
fail_if (t == NULL);
|
|
|
|
/* stop should be possible without lock */
|
|
gst_task_stop (t);
|
|
|
|
/* pause should give a warning */
|
|
ASSERT_WARNING (ret = gst_task_pause (t));
|
|
fail_unless (ret == FALSE);
|
|
|
|
/* start should give a warning */
|
|
ASSERT_WARNING (ret = gst_task_start (t));
|
|
fail_unless (ret == FALSE);
|
|
|
|
/* stop should be possible without lock */
|
|
gst_task_stop (t);
|
|
|
|
gst_object_unref (t);
|
|
}
|
|
|
|
GST_END_TEST;
|
|
|
|
GST_START_TEST (test_create)
|
|
{
|
|
GstTask *t;
|
|
|
|
t = gst_task_create (task_func, NULL);
|
|
fail_if (t == NULL);
|
|
|
|
gst_object_unref (t);
|
|
}
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
Suite *
|
|
gst_task_suite (void)
|
|
{
|
|
Suite *s = suite_create ("GstTask");
|
|
TCase *tc_chain = tcase_create ("task tests");
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
tcase_add_test (tc_chain, test_create);
|
|
tcase_add_test (tc_chain, test_no_lock);
|
|
tcase_add_test (tc_chain, test_lock);
|
|
tcase_add_test (tc_chain, test_lock_start);
|
|
tcase_add_test (tc_chain, test_join);
|
|
|
|
return s;
|
|
}
|
|
|
|
GST_CHECK_MAIN (gst_task);
|