3 * Copyright (C) 2013 Collabora Ltd.
4 * Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>
6 * gst-validate-runner.c - Validate Runner class
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.1 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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
28 #include "gst-validate-internal.h"
29 #include "gst-validate-report.h"
30 #include "gst-validate-monitor-factory.h"
31 #include "gst-validate-override-registry.h"
32 #include "gst-validate-runner.h"
35 * SECTION:gst-validate-runner
36 * @short_description: Class that runs Gst Validate tests for a pipeline
38 * Allows you to test a pipeline within GstValidate. It is the object where
39 * all issue reporting is done.
41 * In the tools using GstValidate the only minimal code to be able to monitor
45 * GstPipeline *pipeline = gst_pipeline_new ("monitored-pipeline");
46 * GstValidateRunner *runner = gst_validate_runner_new ();
47 * GstValidateMonitor *monitor = gst_validate_monitor_factory_create (
48 * GST_OBJECT (pipeline), runner, NULL);
50 * // Run the pipeline and do whatever you want with it
52 * // In that same order
53 * gst_object_unref (pipeline);
54 * gst_object_unref (runner);
55 * gst_object_unref (monitor);
59 struct _GstValidateRunnerPrivate
63 GstValidateReportingLevel default_level;
66 #define GST_VALIDATE_RUNNER_LOCK(r) \
68 GST_LOG_OBJECT (r, "About to lock %p", &GST_VALIDATE_RUNNER_CAST(r)->priv->mutex); \
69 (g_mutex_lock (&GST_VALIDATE_RUNNER_CAST(r)->priv->mutex)); \
70 GST_LOG_OBJECT (r, "Acquired lock %p", &GST_VALIDATE_RUNNER_CAST(r)->priv->mutex); \
73 #define GST_VALIDATE_RUNNER_UNLOCK(r) \
75 GST_LOG_OBJECT (r, "About to unlock %p", &GST_VALIDATE_RUNNER_CAST(r)->priv->mutex); \
76 (g_mutex_unlock (&GST_VALIDATE_RUNNER_CAST(r)->priv->mutex)); \
77 GST_LOG_OBJECT (r, "Released lock %p", &GST_VALIDATE_RUNNER_CAST(r)->priv->mutex); \
80 #define gst_validate_runner_parent_class parent_class
81 G_DEFINE_TYPE (GstValidateRunner, gst_validate_runner, G_TYPE_OBJECT);
91 static guint _signals[LAST_SIGNAL] = { 0 };
94 _set_report_levels_from_string (GstValidateRunner * self, const gchar * list)
96 GST_DEBUG_OBJECT (self, "setting report levels from string [%s]", list);
100 _init_report_levels (GstValidateRunner * self)
104 env = g_getenv ("GST_VALIDATE_REPORT_LEVEL");
106 _set_report_levels_from_string (self, env);
110 gst_validate_runner_dispose (GObject * object)
112 GstValidateRunner *runner = GST_VALIDATE_RUNNER_CAST (object);
114 g_list_free_full (runner->priv->reports,
115 (GDestroyNotify) gst_validate_report_unref);
117 g_mutex_clear (&runner->priv->mutex);
119 G_OBJECT_CLASS (parent_class)->dispose (object);
123 gst_validate_runner_class_init (GstValidateRunnerClass * klass)
125 GObjectClass *gobject_class;
127 gobject_class = G_OBJECT_CLASS (klass);
129 gobject_class->dispose = gst_validate_runner_dispose;
131 g_type_class_add_private (klass, sizeof (GstValidateRunnerPrivate));
133 _signals[REPORT_ADDED_SIGNAL] =
134 g_signal_new ("report-added", G_TYPE_FROM_CLASS (klass),
135 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1,
136 GST_TYPE_VALIDATE_REPORT);
140 gst_validate_runner_init (GstValidateRunner * runner)
142 runner->priv = G_TYPE_INSTANCE_GET_PRIVATE (runner, GST_TYPE_VALIDATE_RUNNER,
143 GstValidateRunnerPrivate);
144 g_mutex_init (&runner->priv->mutex);
146 runner->priv->default_level = GST_VALIDATE_REPORTING_LEVEL_DEFAULT;
147 _init_report_levels (runner);
151 * gst_validate_runner_new:
153 * Create a new #GstValidateRunner
155 * Returns: A newly created #GstValidateRunner
158 gst_validate_runner_new (void)
160 return g_object_new (GST_TYPE_VALIDATE_RUNNER, NULL);
163 GstValidateReportingLevel
164 gst_validate_runner_get_default_reporting_level (GstValidateRunner * runner)
166 return runner->priv->default_level;
170 gst_validate_runner_add_report (GstValidateRunner * runner,
171 GstValidateReport * report)
173 GST_VALIDATE_RUNNER_LOCK (runner);
174 runner->priv->reports = g_list_append (runner->priv->reports, report);
175 GST_VALIDATE_RUNNER_UNLOCK (runner);
177 g_signal_emit (runner, _signals[REPORT_ADDED_SIGNAL], 0, report);
181 * gst_validate_runner_get_reports_count:
182 * @runner: The $GstValidateRunner to get the number of report from
184 * Get the number of reports present in the runner:
186 * Returns: The number of report present in the runner.
189 gst_validate_runner_get_reports_count (GstValidateRunner * runner)
193 g_return_val_if_fail (runner != NULL, 0);
195 GST_VALIDATE_RUNNER_LOCK (runner);
196 l = g_list_length (runner->priv->reports);
197 GST_VALIDATE_RUNNER_UNLOCK (runner);
203 gst_validate_runner_get_reports (GstValidateRunner * runner)
207 GST_VALIDATE_RUNNER_LOCK (runner);
209 g_list_copy_deep (runner->priv->reports,
210 (GCopyFunc) gst_validate_report_ref, NULL);
211 GST_VALIDATE_RUNNER_UNLOCK (runner);
217 * gst_validate_runner_printf:
218 * @runner: The #GstValidateRunner to print all the reports for
220 * Prints all the report on the terminal or on wherever set
221 * in the #GST_VALIDATE_FILE env variable.
223 * Returns: 0 if no critical error has been found and 18 if a critical
224 * error has been detected. That return value is usually to be used as
225 * exit code of the application.
228 gst_validate_runner_printf (GstValidateRunner * runner)
230 GList *reports, *tmp;
233 GList *criticals = NULL;
235 reports = gst_validate_runner_get_reports (runner);
236 for (tmp = reports; tmp; tmp = tmp->next) {
237 GstValidateReport *report = tmp->data;
239 if (gst_validate_report_should_print (report))
240 gst_validate_report_printf (report);
242 if (ret == 0 && report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) {
243 criticals = g_list_append (criticals, tmp->data);
252 g_printerr ("\n\n==== Got criticals, Return value set to 18 ====\n");
254 for (iter = criticals; iter; iter = iter->next) {
255 g_printerr (" Critical error %s\n",
256 ((GstValidateReport *) (iter->data))->message);
261 g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
262 gst_validate_printf (NULL, "Issues found: %u\n", count);
263 g_list_free (criticals);