1From 27e977d03b0f7c1d0bf19621ef0cec0585410e7b Mon Sep 17 00:00:00 2001
2From: Jose Quaresma <quaresma.jose@gmail.com>
3Date: Sun, 11 Apr 2021 19:48:13 +0100
4Subject: [PATCH] tests: add support for install the tests
5
6This will provide to run the tests using the gnome-desktop-testing [1]
7
8[1] https://wiki.gnome.org/Initiatives/GnomeGoals/InstalledTests
9
10Upstream-Status: Submitted [https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/789]
11
12Signed-off-by: Jose Quaresma <quaresma.jose@gmail.com>
13
14---
15 meson.build                  |  4 ++++
16 meson_options.txt            |  1 +
17 tests/check/meson.build      | 22 +++++++++++++++++++++-
18 tests/check/template.test.in |  3 +++
19 4 files changed, 29 insertions(+), 1 deletion(-)
20 create mode 100644 tests/check/template.test.in
21
22diff --git a/meson.build b/meson.build
23index 60c7bec..f7650b1 100644
24--- a/meson.build
25+++ b/meson.build
26@@ -606,6 +606,10 @@ if bashcomp_dep.found()
27   endif
28 endif
29
30+installed_tests_enabled = get_option('installed_tests')
31+installed_tests_metadir = join_paths(datadir, 'installed-tests', meson.project_name())
32+installed_tests_execdir = join_paths(libexecdir, 'installed-tests', meson.project_name())
33+
34 plugins_install_dir = join_paths(get_option('libdir'), 'gstreamer-1.0')
35
36 pkgconfig = import('pkgconfig')
37diff --git a/meson_options.txt b/meson_options.txt
38index 7363bdb..a34ba37 100644
39--- a/meson_options.txt
40+++ b/meson_options.txt
41@@ -15,6 +15,7 @@ option('poisoning', type : 'boolean', value : false, description : 'Enable poiso
42 option('memory-alignment', type: 'combo',
43        choices : ['1', '2', '4', '8', '16', '32', '64', '128', '256', '512', '1024', '2048', '4096', '8192', 'malloc', 'pagesize'],
44        value: 'malloc')
45+option('installed_tests', type : 'boolean', value : false, description : 'Enable installed tests')
46
47 # Feature options
48 option('check', type : 'feature', value : 'auto', description : 'Build unit test libraries')
49diff --git a/tests/check/meson.build b/tests/check/meson.build
50index 16caac7..f2d400f 100644
51--- a/tests/check/meson.build
52+++ b/tests/check/meson.build
53@@ -124,10 +124,16 @@ test_defines = [
54   '-UG_DISABLE_ASSERT',
55   '-UG_DISABLE_CAST_CHECKS',
56   '-DGST_CHECK_TEST_ENVIRONMENT_BEACON="GST_STATE_IGNORE_ELEMENTS"',
57-  '-DTESTFILE="' + meson.current_source_dir() + '/meson.build"',
58   '-DGST_DISABLE_DEPRECATED',
59 ]
60
61+testfile = meson.current_source_dir() + '/meson.build'
62+if installed_tests_enabled
63+  install_data(testfile, install_dir : installed_tests_metadir, rename : 'testfile')
64+  testfile = installed_tests_metadir + '/testfile'
65+endif
66+test_defines += '-DTESTFILE="@0@"'.format(testfile)
67+
68 # sanity checking
69 if get_option('check').disabled()
70   if get_option('tests').enabled()
71@@ -150,6 +156,8 @@ foreach t : core_tests
72       include_directories : [configinc],
73       link_with : link_with_libs,
74       dependencies : gst_deps + test_deps,
75+      install_dir: installed_tests_execdir,
76+      install: installed_tests_enabled,
77     )
78
79     env = environment()
80@@ -161,6 +169,18 @@ foreach t : core_tests
81     env.set('GST_PLUGIN_SCANNER_1_0', gst_scanner_dir + '/gst-plugin-scanner')
82     env.set('GST_PLUGIN_LOADING_WHITELIST', 'gstreamer')
83
84+    if installed_tests_enabled
85+      test_conf = configuration_data()
86+      test_conf.set('installed_tests_dir', join_paths(prefix, installed_tests_execdir))
87+      test_conf.set('program', test_name)
88+      configure_file(
89+        input: 'template.test.in',
90+        output: test_name + '.test',
91+        install_dir: installed_tests_metadir,
92+        configuration: test_conf
93+      )
94+    endif
95+
96     test(test_name, exe, env: env, timeout : 3 * 60)
97   endif
98 endforeach
99diff --git a/tests/check/template.test.in b/tests/check/template.test.in
100new file mode 100644
101index 0000000..f701627
102--- /dev/null
103+++ b/tests/check/template.test.in
104@@ -0,0 +1,3 @@
105+[Test]
106+Type=session
107+Exec=@installed_tests_dir@/@program@
108