gst-qa-override-registry: load overrides dynamically
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Tue, 30 Jul 2013 09:20:43 +0000 (10:20 +0100)
committerThiago Santos <thiago.sousa.santos@collabora.com>
Tue, 30 Jul 2013 12:41:00 +0000 (09:41 -0300)
Shared objects listed in GST_QA_OVERRIDE are loaded on startup,
and the symbol gst_qa_create_overrides is run. It should create
any override needed. While it can do anything it wants, this
is discouraged.

GST_QA_OVERRIDE should be a comma separated list of shared objects,
any relative paths should be from the current working directory
at the time they are loaded (ie, if the process to be traced
changes cwd, use absolute paths).

No attempt whatsoever is made at not running what was not meant.

Includes a sample shared object for illustration purposes.

validate/gst/qa/Makefile.am
validate/gst/qa/gst-qa-default-overrides.c [new file with mode: 0644]
validate/gst/qa/gst-qa-override-registry.c
validate/gst/qa/gst-qa-override-registry.h
validate/gst/qa/gst-qa-runner.c

index 68cb1137aee74b9b359b240a6ee613f0c01fb714..3815dd90284c929c4b48a72c16738143b766e6e4 100644 (file)
@@ -19,7 +19,8 @@ noinst_HEADERS =
        gst-qa-i18n-lib.h
 
 lib_LTLIBRARIES = \
-       libgstqa-@GST_API_VERSION@.la
+       libgstqa-@GST_API_VERSION@.la \
+       libgstqa-default-overrides-@GST_API_VERSION@.la
 
 libgstqa_@GST_API_VERSION@_la_SOURCES = \
     $(c_sources)
@@ -34,6 +35,19 @@ libgstqa_@GST_API_VERSION@_la_LIBADD = \
 libgstqa_@GST_API_VERSION@includedir = $(includedir)/gstreamer-@GST_API_VERSION@/gst/qa
 libgstqa_@GST_API_VERSION@include_HEADERS = $(public_headers)
 
+libgstqa_default_overrides_@GST_API_VERSION@_la_SOURCES = \
+    gst-qa-default-overrides.c
+
+libgstqa_default_overrides_@GST_API_VERSION@_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(GIO_CFLAGS)
+libgstqa_default_overrides_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) \
+       $(GST_LT_LDFLAGS) $(GIO_LDFLAGS)
+libgstqa_default_overrides_@GST_API_VERSION@_la_LIBADD = \
+       $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) \
+       $(GST_LIBS) $(GIO_LIBS)
+
+libgstqa_default_overrides_@GST_API_VERSION@includedir = $(includedir)/gstreamer-@GST_API_VERSION@/gst/qa
+libgstqa_default_overrides_@GST_API_VERSION@include_HEADERS =
+
 bin_PROGRAMS = gst-qa-@GST_API_VERSION@ gst-qa-transcoding-@GST_API_VERSION@
 AM_CFLAGS =  -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) $(GST_CFLAGS)
 LDADD = $(top_builddir)/gst/qa/libgstqa-@GST_API_VERSION@.la $(GST_PBUTILS_LIBS) $(GST_LIBS)
diff --git a/validate/gst/qa/gst-qa-default-overrides.c b/validate/gst/qa/gst-qa-default-overrides.c
new file mode 100644 (file)
index 0000000..eafb9e7
--- /dev/null
@@ -0,0 +1,42 @@
+/* GStreamer
+ * Copyright (C) 2013 Vincent Penquerc'h <vincent.penquerch@collabora.co.uk>
+ *
+ * gst-qa-default-overrides.c - Test overrides
+ *
+ * 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.1 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
+#include "gst-qa-override.h"
+#include "gst-qa-override-registry.h"
+#include "gst-qa-report.h"
+
+int
+gst_qa_create_overrides (void)
+{
+  GstQaOverride *o;
+
+  /* Some random test override. Will moan on:
+     gst-launch videotestsrc num-buffers=10 ! video/x-raw-yuv !  fakesink */
+  o = gst_qa_override_new ();
+  gst_qa_override_change_severity (o, GST_QA_ISSUE_ID_CAPS_IS_MISSING_FIELD,
+      GST_QA_REPORT_LEVEL_CRITICAL);
+  gst_qa_override_register_by_name ("capsfilter0", o);
+  return 1;
+}
index 8c13188482d6cbf570b78dcb2258362959c83a73..3d029b09bfa2af1afe71a26cca7b9f116f892ad7 100644 (file)
@@ -21,6 +21,9 @@
 
 #include <string.h>
 
+#define __USE_GNU
+#include <dlfcn.h>
+
 #include "gst-qa-override-registry.h"
 
 typedef struct
@@ -41,6 +44,8 @@ static GstQaOverrideRegistry *_registry_default;
 #define GST_QA_OVERRIDE_REGISTRY_LOCK(r) g_mutex_lock (&r->mutex)
 #define GST_QA_OVERRIDE_REGISTRY_UNLOCK(r) g_mutex_unlock (&r->mutex)
 
+#define GST_QA_OVERRIDE_INIT_SYMBOL "gst_qa_create_overrides"
+
 static GstQaOverrideRegistry *
 gst_qa_override_registry_new (void)
 {
@@ -181,3 +186,46 @@ gst_qa_override_registry_attach_overrides (GstQaMonitor * monitor)
   gst_qa_override_registry_attach_klass_overrides_unlocked (reg, monitor);
   GST_QA_OVERRIDE_REGISTRY_UNLOCK (reg);
 }
+
+int
+gst_qa_override_registry_preload (void)
+{
+  gchar **solist, *const *so;
+  const char *sos, *soerr;
+  void *sol;
+  int ret, (*entry) (void), nloaded = 0;
+
+  sos = g_getenv ("GST_QA_OVERRIDE");
+  if (!sos) {
+    GST_INFO ("No GST_QA_OVERRIDE found, no overrides to load");
+    return 0;
+  }
+  solist = g_strsplit (sos, ",", 0);
+  for (so = solist; *so; ++so) {
+    GST_INFO ("Loading overrides from %s", *so);
+    sol = dlopen (*so, RTLD_LAZY);
+    if (!sol) {
+      soerr = dlerror ();
+      GST_ERROR ("Failed to load %s %s", *so, soerr ? soerr : "no idea why");
+      continue;
+    }
+    entry = dlsym (sol, GST_QA_OVERRIDE_INIT_SYMBOL);
+    if (entry) {
+      ret = (*entry) ();
+      if (ret > 0) {
+        GST_INFO ("Loaded %d overrides from %s", ret, *so);
+        nloaded += ret;
+      } else if (ret < 0) {
+        GST_WARNING ("Error loading overrides from %s", *so);
+      } else {
+        GST_INFO ("Loaded no overrides from %s", *so);
+      }
+    } else {
+      GST_WARNING (GST_QA_OVERRIDE_INIT_SYMBOL " not found in %s", *so);
+    }
+    dlclose (sol);
+  }
+  g_strfreev (solist);
+  GST_INFO ("%d overrides loaded", nloaded);
+  return nloaded;
+}
index 6401ff3ef10a54d5ccf5b2c7dd78e11dd75ab43a..f4911fd816c98c204c003bd5d8de84c88d27726d 100644 (file)
@@ -46,6 +46,8 @@ void gst_qa_override_register_by_klass (const gchar * klass, GstQaOverride * ove
 
 void gst_qa_override_registry_attach_overrides (GstQaMonitor * monitor);
 
+int gst_qa_override_registry_preload (void);
+
 G_END_DECLS
 
 #endif /* __GST_QA_OVERRIDE_REGISTRY_H__ */
index 377164a144a596e04e08e55d121e471c24411440..ed995e02b71c18432ac805162c1e4499e687864e 100644 (file)
@@ -23,6 +23,7 @@
 #include "gst-qa-report.h"
 #include "gst-qa-monitor-factory.h"
 #include "gst-qa-element-monitor.h"
+#include "gst-qa-override-registry.h"
 #include "gst-qa-scenario.h"
 
 /**
@@ -80,6 +81,9 @@ gst_qa_runner_class_init (GstQaRunnerClass * klass)
   /* init the report system (can be called multiple times) */
   gst_qa_report_init ();
 
+  /* Ensure we load overrides before any use of a monitor */
+  gst_qa_override_registry_preload ();
+
   _signals[REPORT_ADDED_SIGNAL] =
       g_signal_new ("report-added", G_TYPE_FROM_CLASS (klass),
       G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1,