validate: Add a way to avoid printing all the issue in reports
[platform/upstream/gstreamer.git] / validate / gst / validate / gst-validate-runner.c
1 /* GStreamer
2  *
3  * Copyright (C) 2013 Collabora Ltd.
4  *  Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>
5  *
6  * gst-validate-runner.c - Validate Runner class
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
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"
33
34 /**
35  * SECTION:gst-validate-runner
36  * @short_description: Class that runs Gst Validate tests for a pipeline
37  *
38  * TODO
39  */
40
41 #define gst_validate_runner_parent_class parent_class
42 G_DEFINE_TYPE (GstValidateRunner, gst_validate_runner, G_TYPE_OBJECT);
43
44 /* signals */
45 enum
46 {
47   REPORT_ADDED_SIGNAL,
48   /* add more above */
49   LAST_SIGNAL
50 };
51
52 static guint _signals[LAST_SIGNAL] = { 0 };
53
54 static void
55 gst_validate_runner_dispose (GObject * object)
56 {
57   GstValidateRunner *runner = GST_VALIDATE_RUNNER_CAST (object);
58
59   g_slist_free_full (runner->reports,
60       (GDestroyNotify) gst_validate_report_unref);
61
62   G_OBJECT_CLASS (parent_class)->dispose (object);
63 }
64
65 static void
66 gst_validate_runner_class_init (GstValidateRunnerClass * klass)
67 {
68   GObjectClass *gobject_class;
69
70   gobject_class = G_OBJECT_CLASS (klass);
71
72   gobject_class->dispose = gst_validate_runner_dispose;
73
74   _signals[REPORT_ADDED_SIGNAL] =
75       g_signal_new ("report-added", G_TYPE_FROM_CLASS (klass),
76       G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1,
77       GST_TYPE_VALIDATE_REPORT);
78 }
79
80 static void
81 gst_validate_runner_init (GstValidateRunner * runner)
82 {
83   runner->setup = FALSE;
84   runner->max_printed_level = GST_VALIDATE_REPORT_LEVEL_NUM_ENTRIES;
85 }
86
87 /**
88  * gst_validate_runner_new:
89  */
90 GstValidateRunner *
91 gst_validate_runner_new (void)
92 {
93   return g_object_new (GST_TYPE_VALIDATE_RUNNER, NULL);
94 }
95
96 void
97 gst_validate_runner_add_report (GstValidateRunner * runner,
98     GstValidateReport * report)
99 {
100   runner->reports = g_slist_prepend (runner->reports, report);
101
102   g_signal_emit (runner, _signals[REPORT_ADDED_SIGNAL], 0, report);
103 }
104
105 guint
106 gst_validate_runner_get_reports_count (GstValidateRunner * runner)
107 {
108   g_return_val_if_fail (runner != NULL, 0);
109   return g_slist_length (runner->reports);
110 }
111
112 GSList *
113 gst_validate_runner_get_reports (GstValidateRunner * runner)
114 {
115   /* TODO should we need locking or put in htte docs to always call this
116    * after pipeline ends? */
117   return runner->reports;
118 }
119
120 int
121 gst_validate_runner_printf (GstValidateRunner * runner)
122 {
123   GSList *tmp;
124   guint count = 0;
125   int ret = 0;
126   GList *criticals = NULL;
127
128   for (tmp = gst_validate_runner_get_reports (runner); tmp; tmp = tmp->next) {
129     GstValidateReport *report = tmp->data;
130
131     if (gst_validate_report_should_print (report))
132       gst_validate_report_printf (report);
133
134     if (ret == 0 && report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) {
135       criticals = g_list_append (criticals, tmp->data);
136       ret = 18;
137     }
138     count++;
139   }
140
141   if (criticals) {
142     GList *iter;
143
144     g_printerr ("\n\n==== Got criticals, Return value set to 18 ====\n");
145
146     for (iter = criticals; iter; iter = iter->next) {
147       g_printerr ("     Critical error %s\n",
148           ((GstValidateReport *) (iter->data))->message);
149     }
150     g_printerr ("\n");
151   }
152
153   gst_validate_printf (NULL, "Pipeline finished, issues found: %u\n", count);
154   return ret;
155 }