3 * Common code for GStreamer unittests
5 * Copyright (C) 2004,2006 Thomas Vander Stichele <thomas at apestaart dot org>
6 * Copyright (C) 2008 Thijs Vermeir <thijsvermeir@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 * @short_description: Common code for GStreamer unit tests
27 * These macros and functions are for internal use of the unit tests found
28 * inside the 'check' directories of various GStreamer packages.
30 * One notable feature is that one can use the environment variables GST_CHECK
31 * and GST_CHECK_IGNORE to select which tests to run or skip. Both variables
32 * can contain a comman separated list of test name globs (e.g. test_*).
40 GST_DEBUG_CATEGORY (check_debug);
42 /* logging function for tests
43 * a test uses g_message() to log a debug line
44 * a gst unit test can be run with GST_TEST_DEBUG env var set to see the
48 gboolean _gst_check_threads_running = FALSE;
49 GList *thread_list = NULL;
51 GCond start_cond; /* used to notify main thread of thread startups */
52 GCond sync_cond; /* used to synchronize all threads and main thread */
54 GList *buffers = NULL;
58 /* FIXME 0.11: shouldn't _gst_check_debug be static? Not used anywhere */
59 gboolean _gst_check_debug = FALSE;
60 gboolean _gst_check_raised_critical = FALSE;
61 gboolean _gst_check_raised_warning = FALSE;
62 gboolean _gst_check_expecting_log = FALSE;
64 static void gst_check_log_message_func
65 (const gchar * log_domain, GLogLevelFlags log_level,
66 const gchar * message, gpointer user_data)
68 if (_gst_check_debug) {
69 g_print ("%s", message);
73 static void gst_check_log_critical_func
74 (const gchar * log_domain, GLogLevelFlags log_level,
75 const gchar * message, gpointer user_data)
77 if (!_gst_check_expecting_log) {
78 g_print ("\n\nUnexpected critical/warning: %s\n", message);
79 fail ("Unexpected critical/warning: %s", message);
82 if (_gst_check_debug) {
83 g_print ("\nExpected critical/warning: %s\n", message);
86 if (log_level & G_LOG_LEVEL_CRITICAL)
87 _gst_check_raised_critical = TRUE;
88 if (log_level & G_LOG_LEVEL_WARNING)
89 _gst_check_raised_warning = TRUE;
93 sort_plugins (GstPlugin * a, GstPlugin * b)
97 ret = strcmp (gst_plugin_get_source (a), gst_plugin_get_source (b));
99 ret = strcmp (gst_plugin_get_name (a), gst_plugin_get_name (b));
108 plugins = gst_registry_get_plugin_list (gst_registry_get ());
109 plugins = g_list_sort (plugins, (GCompareFunc) sort_plugins);
110 for (l = plugins; l != NULL; l = l->next) {
111 GstPlugin *plugin = GST_PLUGIN (l->data);
113 if (strcmp (gst_plugin_get_source (plugin), "BLACKLIST") != 0) {
114 GST_LOG ("%20s@%s", gst_plugin_get_name (plugin),
115 GST_STR_NULL (gst_plugin_get_filename (plugin)));
118 gst_plugin_list_free (plugins);
121 /* initialize GStreamer testing */
123 gst_check_init (int *argc, char **argv[])
125 guint timeout_multiplier = 1;
127 gst_init (argc, argv);
129 GST_DEBUG_CATEGORY_INIT (check_debug, "check", 0, "check regression tests");
131 if (atexit (gst_deinit) != 0) {
132 GST_ERROR ("failed to set gst_deinit as exit function");
135 if (g_getenv ("GST_TEST_DEBUG"))
136 _gst_check_debug = TRUE;
138 g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gst_check_log_message_func,
140 g_log_set_handler (NULL, G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
141 gst_check_log_critical_func, NULL);
142 g_log_set_handler ("GStreamer", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
143 gst_check_log_critical_func, NULL);
144 g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
145 gst_check_log_critical_func, NULL);
146 g_log_set_handler ("GLib-GIO", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
147 gst_check_log_critical_func, NULL);
148 g_log_set_handler ("GLib", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
149 gst_check_log_critical_func, NULL);
154 GST_INFO ("target CPU: %s", TARGET_CPU);
158 timeout_multiplier = 10;
161 if (timeout_multiplier > 1) {
162 const gchar *tmult = g_getenv ("CK_TIMEOUT_MULTIPLIER");
167 g_snprintf (num_str, sizeof (num_str), "%d", timeout_multiplier);
168 GST_INFO ("slow CPU, setting CK_TIMEOUT_MULTIPLIER to %s", num_str);
169 g_setenv ("CK_TIMEOUT_MULTIPLIER", num_str, TRUE);
171 GST_INFO ("CK_TIMEOUT_MULTIPLIER already set to '%s'", tmult);
176 /* message checking */
178 gst_check_message_error (GstMessage * message, GstMessageType type,
179 GQuark domain, gint code)
184 fail_unless (GST_MESSAGE_TYPE (message) == type,
185 "message is of type %s instead of expected type %s",
186 gst_message_type_get_name (GST_MESSAGE_TYPE (message)),
187 gst_message_type_get_name (type));
188 gst_message_parse_error (message, &error, &debug);
189 fail_unless_equals_int (error->domain, domain);
190 fail_unless_equals_int (error->code, code);
191 g_error_free (error);
195 /* helper functions */
197 gst_check_chain_func (GstPad * pad, GstObject * parent, GstBuffer * buffer)
199 GST_DEBUG_OBJECT (pad, "chain_func: received buffer %p", buffer);
200 buffers = g_list_append (buffers, buffer);
202 g_mutex_lock (&check_mutex);
203 g_cond_signal (&check_cond);
204 g_mutex_unlock (&check_mutex);
210 * gst_check_setup_element:
213 * setup an element for a filter test with mysrcpad and mysinkpad
215 * Returns: (transfer full): a new element
218 gst_check_setup_element (const gchar * factory)
222 GST_DEBUG ("setup_element");
224 element = gst_element_factory_make (factory, factory);
225 fail_if (element == NULL, "Could not create a '%s' element", factory);
226 ASSERT_OBJECT_REFCOUNT (element, factory, 1);
231 gst_check_teardown_element (GstElement * element)
233 GST_DEBUG ("teardown_element");
235 fail_unless (gst_element_set_state (element, GST_STATE_NULL) ==
236 GST_STATE_CHANGE_SUCCESS, "could not set to null");
237 ASSERT_OBJECT_REFCOUNT (element, "element", 1);
238 gst_object_unref (element);
242 * gst_check_setup_src_pad:
243 * @element: element to setup pad on
244 * @tmpl: pad template
246 * Returns: (transfer full): a new pad
249 gst_check_setup_src_pad (GstElement * element, GstStaticPadTemplate * tmpl)
251 return gst_check_setup_src_pad_by_name (element, tmpl, "sink");
255 * gst_check_setup_src_pad_by_name:
256 * @element: element to setup pad on
257 * @tmpl: pad template
260 * Returns: (transfer full): a new pad
263 gst_check_setup_src_pad_by_name (GstElement * element,
264 GstStaticPadTemplate * tmpl, const gchar * name)
266 GstPadTemplate *ptmpl = gst_static_pad_template_get (tmpl);
270 gst_check_setup_src_pad_by_name_from_template (element, ptmpl, "sink");
272 gst_object_unref (ptmpl);
278 * gst_check_setup_src_pad_from_template:
279 * @element: element to setup pad on
280 * @tmpl: pad template
282 * Returns: (transfer full): a new pad
287 gst_check_setup_src_pad_from_template (GstElement * element,
288 GstPadTemplate * tmpl)
290 return gst_check_setup_src_pad_by_name_from_template (element, tmpl, "sink");
294 * gst_check_setup_src_pad_by_name_from_template:
295 * @element: element to setup pad on
296 * @tmpl: pad template
299 * Returns: (transfer full): a new pad
304 gst_check_setup_src_pad_by_name_from_template (GstElement * element,
305 GstPadTemplate * tmpl, const gchar * name)
307 GstPad *srcpad, *sinkpad;
310 srcpad = gst_pad_new_from_template (tmpl, "src");
311 GST_DEBUG_OBJECT (element, "setting up sending pad %p", srcpad);
312 fail_if (srcpad == NULL, "Could not create a srcpad");
313 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
315 sinkpad = gst_element_get_static_pad (element, name);
317 sinkpad = gst_element_get_request_pad (element, name);
318 fail_if (sinkpad == NULL, "Could not get sink pad from %s",
319 GST_ELEMENT_NAME (element));
320 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);
321 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
322 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
323 gst_object_unref (sinkpad); /* because we got it higher up */
324 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 1);
330 gst_check_teardown_pad_by_name (GstElement * element, const gchar * name)
332 GstPad *pad_peer, *pad_element;
334 /* clean up floating src pad */
335 pad_element = gst_element_get_static_pad (element, name);
336 /* We don't check the refcount here since there *might* be
337 * a pad cache holding an extra reference on pad_element.
338 * To get to a state where no pad cache will exist,
339 * we first unlink that pad. */
340 pad_peer = gst_pad_get_peer (pad_element);
343 if (gst_pad_get_direction (pad_element) == GST_PAD_SINK)
344 gst_pad_unlink (pad_peer, pad_element);
346 gst_pad_unlink (pad_element, pad_peer);
349 /* pad refs held by both creator and this function (through _get) */
350 ASSERT_OBJECT_REFCOUNT (pad_element, "element pad_element", 2);
351 gst_object_unref (pad_element);
352 /* one more ref is held by element itself */
355 /* pad refs held by both creator and this function (through _get_peer) */
356 ASSERT_OBJECT_REFCOUNT (pad_peer, "check pad_peer", 2);
357 gst_object_unref (pad_peer);
358 gst_object_unref (pad_peer);
363 gst_check_teardown_src_pad (GstElement * element)
365 gst_check_teardown_pad_by_name (element, "sink");
369 * gst_check_setup_sink_pad:
370 * @element: element to setup pad on
371 * @tmpl: pad template
373 * Returns: (transfer full): a new pad
376 gst_check_setup_sink_pad (GstElement * element, GstStaticPadTemplate * tmpl)
378 return gst_check_setup_sink_pad_by_name (element, tmpl, "src");
382 * gst_check_setup_sink_pad_by_name:
383 * @element: element to setup pad on
384 * @tmpl: pad template
387 * Returns: (transfer full): a new pad
390 gst_check_setup_sink_pad_by_name (GstElement * element,
391 GstStaticPadTemplate * tmpl, const gchar * name)
393 GstPadTemplate *ptmpl = gst_static_pad_template_get (tmpl);
397 gst_check_setup_sink_pad_by_name_from_template (element, ptmpl, "src");
399 gst_object_unref (ptmpl);
405 * gst_check_setup_sink_pad_from_template:
406 * @element: element to setup pad on
407 * @tmpl: pad template
409 * Returns: (transfer full): a new pad
414 gst_check_setup_sink_pad_from_template (GstElement * element,
415 GstPadTemplate * tmpl)
417 return gst_check_setup_sink_pad_by_name_from_template (element, tmpl, "src");
421 * gst_check_setup_sink_pad_by_name_from_template:
422 * @element: element to setup pad on
423 * @tmpl: pad template
426 * Returns: (transfer full): a new pad
431 gst_check_setup_sink_pad_by_name_from_template (GstElement * element,
432 GstPadTemplate * tmpl, const gchar * name)
434 GstPad *srcpad, *sinkpad;
437 sinkpad = gst_pad_new_from_template (tmpl, "sink");
438 GST_DEBUG_OBJECT (element, "setting up receiving pad %p", sinkpad);
439 fail_if (sinkpad == NULL, "Could not create a sinkpad");
441 srcpad = gst_element_get_static_pad (element, name);
443 srcpad = gst_element_get_request_pad (element, name);
444 fail_if (srcpad == NULL, "Could not get source pad from %s",
445 GST_ELEMENT_NAME (element));
446 gst_pad_set_chain_function (sinkpad, gst_check_chain_func);
448 GST_DEBUG_OBJECT (element, "Linking element src pad and receiving sink pad");
449 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
450 "Could not link %s source and sink pads", GST_ELEMENT_NAME (element));
451 gst_object_unref (srcpad); /* because we got it higher up */
452 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
454 GST_DEBUG_OBJECT (element, "set up srcpad, refcount is 1");
459 gst_check_teardown_sink_pad (GstElement * element)
461 gst_check_teardown_pad_by_name (element, "src");
465 * gst_check_drop_buffers:
467 * Unref and remove all buffers that are in the global @buffers GList,
471 gst_check_drop_buffers (void)
473 while (buffers != NULL) {
474 gst_buffer_unref (GST_BUFFER (buffers->data));
475 buffers = g_list_delete_link (buffers, buffers);
480 * gst_check_caps_equal:
481 * @caps1: first caps to compare
482 * @caps2: second caps to compare
484 * Compare two caps with gst_caps_is_equal and fail unless they are
488 gst_check_caps_equal (GstCaps * caps1, GstCaps * caps2)
490 gchar *name1 = gst_caps_to_string (caps1);
491 gchar *name2 = gst_caps_to_string (caps2);
493 fail_unless (gst_caps_is_equal (caps1, caps2),
494 "caps ('%s') is not equal to caps ('%s')", name1, name2);
501 * gst_check_buffer_data:
502 * @buffer: buffer to compare
503 * @data: data to compare to
504 * @size: size of data to compare
506 * Compare the buffer contents with @data and @size.
509 gst_check_buffer_data (GstBuffer * buffer, gconstpointer data, gsize size)
513 gst_buffer_map (buffer, &info, GST_MAP_READ);
514 GST_MEMDUMP ("Converted data", info.data, info.size);
515 GST_MEMDUMP ("Expected data", data, size);
516 if (memcmp (info.data, data, size) != 0) {
517 g_print ("\nConverted data:\n");
518 gst_util_dump_mem (info.data, info.size);
519 g_print ("\nExpected data:\n");
520 gst_util_dump_mem (data, size);
522 fail_unless (memcmp (info.data, data, size) == 0,
523 "buffer contents not equal");
524 gst_buffer_unmap (buffer, &info);
528 buffer_event_function (GstPad * pad, GstObject * noparent, GstEvent * event)
530 if (GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
532 GstCaps *expected_caps = gst_pad_get_element_private (pad);
534 gst_event_parse_caps (event, &event_caps);
535 fail_unless (gst_caps_is_fixed (expected_caps));
536 fail_unless (gst_caps_is_fixed (event_caps));
537 fail_unless (gst_caps_is_equal_fixed (event_caps, expected_caps));
538 gst_event_unref (event);
542 return gst_pad_event_default (pad, noparent, event);
546 * gst_check_element_push_buffer_list:
547 * @element_name: name of the element that needs to be created
548 * @buffer_in: (element-type GstBuffer) (transfer full): a list of buffers that needs to be
549 * pushed to the element
550 * @buffer_out: (element-type GstBuffer) (transfer full): a list of buffers that we expect from
552 * @last_flow_return: the last buffer push needs to give this GstFlowReturn
554 * Create an @element with the factory with the name and push the buffers in
555 * @buffer_in to this element. The element should create the buffers equal to
556 * the buffers in @buffer_out. We only check the caps, size and the data of the
557 * buffers. This function unrefs the buffers in the two lists.
558 * The last_flow_return parameter indicates the expected flow return value from
559 * pushing the final buffer in the list.
560 * This can be used to set up a test which pushes some buffers and then an
561 * invalid buffer, when the final buffer is expected to fail, for example.
563 /* FIXME 0.11: rename this function now that there's GstBufferList? */
565 gst_check_element_push_buffer_list (const gchar * element_name,
566 GList * buffer_in, GstCaps * caps_in, GList * buffer_out,
567 GstCaps * caps_out, GstFlowReturn last_flow_return)
571 GstPad *sink_pad = NULL;
575 /* check that there are no buffers waiting */
576 gst_check_drop_buffers ();
577 /* create the element */
578 element = gst_check_setup_element (element_name);
579 fail_if (element == NULL, "failed to create the element '%s'", element_name);
580 fail_unless (GST_IS_ELEMENT (element), "the element is no element");
581 /* create the src pad */
582 buffer = GST_BUFFER (buffer_in->data);
584 fail_unless (GST_IS_BUFFER (buffer), "There should be a buffer in buffer_in");
585 src_pad = gst_pad_new ("src", GST_PAD_SRC);
587 fail_unless (gst_caps_is_fixed (caps_in));
588 gst_pad_use_fixed_caps (src_pad);
590 /* activate the pad */
591 gst_pad_set_active (src_pad, TRUE);
592 GST_DEBUG ("src pad activated");
593 gst_check_setup_events (src_pad, element, caps_in, GST_FORMAT_BYTES);
594 pad_peer = gst_element_get_static_pad (element, "sink");
595 fail_if (pad_peer == NULL);
596 fail_unless (gst_pad_link (src_pad, pad_peer) == GST_PAD_LINK_OK,
597 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
598 gst_object_unref (pad_peer);
599 /* don't create the sink_pad if there is no buffer_out list */
600 if (buffer_out != NULL) {
602 GST_DEBUG ("buffer out detected, creating the sink pad");
603 /* get the sink caps */
607 fail_unless (gst_caps_is_fixed (caps_out));
608 temp = gst_caps_to_string (caps_out);
610 GST_DEBUG ("sink caps requested by buffer out: '%s'", temp);
614 /* get the sink pad */
615 sink_pad = gst_pad_new ("sink", GST_PAD_SINK);
616 fail_unless (GST_IS_PAD (sink_pad));
617 /* configure the sink pad */
618 gst_pad_set_chain_function (sink_pad, gst_check_chain_func);
619 gst_pad_set_active (sink_pad, TRUE);
621 gst_pad_set_element_private (sink_pad, caps_out);
622 gst_pad_set_event_function (sink_pad, buffer_event_function);
624 /* get the peer pad */
625 pad_peer = gst_element_get_static_pad (element, "src");
626 fail_unless (gst_pad_link (pad_peer, sink_pad) == GST_PAD_LINK_OK,
627 "Could not link sink and %s source pads", GST_ELEMENT_NAME (element));
628 gst_object_unref (pad_peer);
630 fail_unless (gst_element_set_state (element,
631 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
632 "could not set to playing");
633 /* push all the buffers in the buffer_in list */
634 fail_unless (g_list_length (buffer_in) > 0, "the buffer_in list is empty");
635 while (buffer_in != NULL) {
636 GstBuffer *next_buffer = GST_BUFFER (buffer_in->data);
638 fail_unless (GST_IS_BUFFER (next_buffer),
639 "data in buffer_in should be a buffer");
640 /* remove the buffer from the list */
641 buffer_in = g_list_remove (buffer_in, next_buffer);
642 if (buffer_in == NULL) {
643 fail_unless (gst_pad_push (src_pad, next_buffer) == last_flow_return,
644 "we expect something else from the last buffer");
646 fail_unless (gst_pad_push (src_pad, next_buffer) == GST_FLOW_OK,
647 "Failed to push buffer in");
650 fail_unless (gst_element_set_state (element,
651 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
652 /* check that there is a buffer out */
653 fail_unless_equals_int (g_list_length (buffers), g_list_length (buffer_out));
654 while (buffers != NULL) {
655 GstBuffer *new = GST_BUFFER (buffers->data);
656 GstBuffer *orig = GST_BUFFER (buffer_out->data);
657 GstMapInfo newinfo, originfo;
659 gst_buffer_map (new, &newinfo, GST_MAP_READ);
660 gst_buffer_map (orig, &originfo, GST_MAP_READ);
662 GST_LOG ("orig buffer: size %" G_GSIZE_FORMAT, originfo.size);
663 GST_LOG ("new buffer: size %" G_GSIZE_FORMAT, newinfo.size);
664 GST_MEMDUMP ("orig buffer", originfo.data, originfo.size);
665 GST_MEMDUMP ("new buffer", newinfo.data, newinfo.size);
667 /* remove the buffers */
668 buffers = g_list_remove (buffers, new);
669 buffer_out = g_list_remove (buffer_out, orig);
671 fail_unless (originfo.size == newinfo.size,
672 "size of the buffers are not the same");
673 fail_unless (memcmp (originfo.data, newinfo.data, newinfo.size) == 0,
674 "data is not the same");
676 gst_check_caps_equal (GST_BUFFER_CAPS (orig), GST_BUFFER_CAPS (new));
679 gst_buffer_unmap (orig, &originfo);
680 gst_buffer_unmap (new, &newinfo);
682 gst_buffer_unref (new);
683 gst_buffer_unref (orig);
685 /* teardown the element and pads */
686 gst_pad_set_active (src_pad, FALSE);
687 gst_check_teardown_src_pad (element);
688 gst_pad_set_active (sink_pad, FALSE);
689 gst_check_teardown_sink_pad (element);
690 gst_check_teardown_element (element);
694 * gst_check_element_push_buffer:
695 * @element_name: name of the element that needs to be created
696 * @buffer_in: push this buffer to the element
697 * @buffer_out: compare the result with this buffer
699 * Create an @element with the factory with the name and push the
700 * @buffer_in to this element. The element should create one buffer
701 * and this will be compared with @buffer_out. We only check the caps
702 * and the data of the buffers. This function unrefs the buffers.
705 gst_check_element_push_buffer (const gchar * element_name,
706 GstBuffer * buffer_in, GstCaps * caps_in, GstBuffer * buffer_out,
712 in = g_list_append (in, buffer_in);
713 out = g_list_append (out, buffer_out);
715 gst_check_element_push_buffer_list (element_name, in, caps_in, out, caps_out,
720 gst_check_abi_list (GstCheckABIStruct list[], gboolean have_abi_sizes)
722 if (have_abi_sizes) {
726 for (i = 0; list[i].name; i++) {
727 if (list[i].size != list[i].abi_size) {
729 g_print ("sizeof(%s) is %d, expected %d\n",
730 list[i].name, list[i].size, list[i].abi_size);
733 fail_unless (ok, "failed ABI check");
737 if ((fn = g_getenv ("GST_ABI"))) {
742 s = g_string_new ("\nGstCheckABIStruct list[] = {\n");
743 for (i = 0; list[i].name; i++) {
744 g_string_append_printf (s, " {\"%s\", sizeof (%s), %d},\n",
745 list[i].name, list[i].name, list[i].size);
747 g_string_append (s, " {NULL, 0, 0}\n");
748 g_string_append (s, "};\n");
749 if (!g_file_set_contents (fn, s->str, s->len, &err)) {
750 g_print ("%s", s->str);
751 g_printerr ("\nFailed to write ABI information: %s\n", err->message);
753 g_print ("\nWrote ABI information to '%s'.\n", fn);
755 g_string_free (s, TRUE);
757 g_print ("No structure size list was generated for this architecture.\n");
758 g_print ("Run with GST_ABI environment variable set to output header.\n");
764 gst_check_run_suite (Suite * suite, const gchar * name, const gchar * fname)
767 gchar *xmlfilename = NULL;
770 sr = srunner_create (suite);
772 if (g_getenv ("GST_CHECK_XML")) {
773 /* how lucky we are to have __FILE__ end in .c */
774 xmlfilename = g_strdup_printf ("%sheck.xml", fname);
776 srunner_set_xml (sr, xmlfilename);
779 srunner_run_all (sr, CK_NORMAL);
780 nf = srunner_ntests_failed (sr);
781 g_free (xmlfilename);
787 gst_check_have_checks_list (const gchar * env_var_name)
789 const gchar *env_val;
791 env_val = g_getenv (env_var_name);
792 return (env_val != NULL && *env_val != '\0');
796 gst_check_func_is_in_list (const gchar * env_var, const gchar * func_name)
798 const gchar *gst_checks;
799 gboolean res = FALSE;
802 gst_checks = g_getenv (env_var);
804 if (gst_checks == NULL || *gst_checks == '\0')
807 /* only run specified functions */
808 funcs = g_strsplit (gst_checks, ",", -1);
809 for (f = funcs; f != NULL && *f != NULL; ++f) {
810 if (g_pattern_match_simple (*f, func_name)) {
820 _gst_check_run_test_func (const gchar * func_name)
822 /* if we have a whitelist, run it only if it's in the whitelist */
823 if (gst_check_have_checks_list ("GST_CHECKS"))
824 return gst_check_func_is_in_list ("GST_CHECKS", func_name);
826 /* if we have a blacklist, run it only if it's not in the blacklist */
827 if (gst_check_have_checks_list ("GST_CHECKS_IGNORE"))
828 return !gst_check_func_is_in_list ("GST_CHECKS_IGNORE", func_name);
830 /* no filter specified => run all checks */
835 * gst_check_setup_events_with_stream_id:
836 * @srcpad: The src #GstPad to push on
837 * @element: The #GstElement use to create the stream id
838 * @caps: (allow-none): #GstCaps in case caps event must be sent
839 * @format: The #GstFormat of the default segment to send
840 * @stream_id: A unique identifier for the stream
842 * Push stream-start, caps and segment event, which consist of the minimum
843 * required events to allow streaming. Caps is optional to allow raw src
847 gst_check_setup_events_with_stream_id (GstPad * srcpad, GstElement * element,
848 GstCaps * caps, GstFormat format, const gchar * stream_id)
852 gst_segment_init (&segment, format);
854 fail_unless (gst_pad_push_event (srcpad,
855 gst_event_new_stream_start (stream_id)));
857 fail_unless (gst_pad_push_event (srcpad, gst_event_new_caps (caps)));
858 fail_unless (gst_pad_push_event (srcpad, gst_event_new_segment (&segment)));
862 * gst_check_setup_events:
863 * @srcpad: The src #GstPad to push on
864 * @element: The #GstElement use to create the stream id
865 * @caps: (allow-none): #GstCaps in case caps event must be sent
866 * @format: The #GstFormat of the default segment to send
868 * Push stream-start, caps and segment event, which consist of the minimum
869 * required events to allow streaming. Caps is optional to allow raw src
870 * testing. If @element has more than one src or sink pad, use
871 * gst_check_setup_events_with_stream_id() instead.
874 gst_check_setup_events (GstPad * srcpad, GstElement * element,
875 GstCaps * caps, GstFormat format)
879 stream_id = gst_pad_create_stream_id (srcpad, element, NULL);
880 gst_check_setup_events_with_stream_id (srcpad, element, caps, format,