From 3b9ae399b57cfb6e332fac6a90997a3abd33c819 Mon Sep 17 00:00:00 2001
From: Jose Quaresma <quaresma.jose@gmail.com>
Date: Sun, 2 May 2021 01:58:01 +0100
Subject: [PATCH] tests: add helper script to run the installed_tests

- this is a bash script that will run the installed_tests
with some of the environment variables used in the meson
testing framework.

Upstream-Status: Submitted [https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/789]

Signed-off-by: Jose Quaresma <quaresma.jose@gmail.com>
---
 tests/check/meson.build      | 17 +++++++++++++++++
 tests/check/template.sh.in   |  9 +++++++++
 tests/check/template.test.in |  2 +-
 3 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100755 tests/check/template.sh.in

diff --git a/tests/check/meson.build b/tests/check/meson.build
index a3ffcb6..b907dcf 100644
--- a/tests/check/meson.build
+++ b/tests/check/meson.build
@@ -188,6 +188,23 @@ foreach t : core_tests
         install_dir: installed_tests_metadir,
         configuration: test_conf
       )
+
+      # All the tests will be deployed on the target machine and
+      # we use the home folder ~ for the registry which will then expand at runtime.
+      # Using the /tmp/gstreamer-1.0/@0@.registry can be problematic as it mostly
+      # is mounted using tmpfs and if the machine crash from some reason we can lost the registry
+      # that is useful for debug propose of the tests itself.
+      env += {'GST_REGISTRY': '~/.cache/gstreamer-1.0/@0@.registry'.format(test_name)}
+
+      # Set the full path for the test it self.
+      env += {'TEST': '@0@/@1@'.format(join_paths(prefix, installed_tests_execdir), test_name)}
+
+      configure_file(
+        input : 'template.sh.in',
+        output: test_name + '.sh',
+        install_dir: installed_tests_execdir,
+        configuration : env,
+      )
     endif
 
     test(test_name, exe, env: env, timeout : 3 * 60)
diff --git a/tests/check/template.sh.in b/tests/check/template.sh.in
new file mode 100755
index 0000000..f1318fa
--- /dev/null
+++ b/tests/check/template.sh.in
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+set -ax
+
+CK_DEFAULT_TIMEOUT="@CK_DEFAULT_TIMEOUT@"
+GST_PLUGIN_LOADING_WHITELIST="@GST_PLUGIN_LOADING_WHITELIST@"
+GST_REGISTRY=@GST_REGISTRY@
+GST_STATE_IGNORE_ELEMENTS="@GST_STATE_IGNORE_ELEMENTS@"
+exec @TEST@ "$@"
diff --git a/tests/check/template.test.in b/tests/check/template.test.in
index f701627..b74ef6a 100644
--- a/tests/check/template.test.in
+++ b/tests/check/template.test.in
@@ -1,3 +1,3 @@
 [Test]
 Type=session
-Exec=@installed_tests_dir@/@program@
+Exec=@installed_tests_dir@/@program@.sh
