blob: bf5e57249c06de95433924d85da572801645e848 [file] [log] [blame]
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001From cf8077a7e3ab0ae236ebde79b7fc0b02eac658de Mon Sep 17 00:00:00 2001
Andrew Geissler82c905d2020-04-13 13:39:40 -05002From: Carlos Rafael Giani <crg7475@mailbox.org>
3Date: Fri, 25 Oct 2019 00:06:26 +0200
Andrew Geisslerd1e89492021-02-12 15:35:20 -06004Subject: [PATCH 3/3] meson: Add option for installed tests
Andrew Geissler82c905d2020-04-13 13:39:40 -05005
6This adds an option for producing installed versions of the unit tests.
7These versions don't need meson to run (only a small shell script). This
8makes it easier to run cross compiled tests on a target machine.
9
10Upstream-Status: Pending
11
12Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
13---
14 build-aux/gen-installed-test-desc.py | 18 ++++++
15 build-aux/gen-installed-test-shscript.py | 25 ++++++++
16 meson_options.txt | 2 +
17 tests/check/meson.build | 46 +++++++++++++-
18 tests/files/testfile | 80 ++++++++++++++++++++++++
19 5 files changed, 170 insertions(+), 1 deletion(-)
20 create mode 100644 build-aux/gen-installed-test-desc.py
21 create mode 100644 build-aux/gen-installed-test-shscript.py
22 create mode 100644 tests/files/testfile
23
24diff --git a/build-aux/gen-installed-test-desc.py b/build-aux/gen-installed-test-desc.py
25new file mode 100644
Andrew Geisslerd1e89492021-02-12 15:35:20 -060026index 000000000..69e8a0faf
Andrew Geissler82c905d2020-04-13 13:39:40 -050027--- /dev/null
28+++ b/build-aux/gen-installed-test-desc.py
29@@ -0,0 +1,18 @@
30+import sys
31+import os
32+import argparse
33+
34+def write_template(filename, data):
35+ with open(filename, 'w') as f:
36+ f.write(data)
37+
38+def build_template(testdir, testname):
39+ return "[Test]\nType=session\nExec={}\n".format(os.path.join(testdir, testname))
40+
41+argparser = argparse.ArgumentParser(description='Generate installed-test data.')
42+argparser.add_argument('--test-execdir', metavar='dir', required=True, help='Installed test directory')
43+argparser.add_argument('--testname', metavar='name', required=True, help='Installed test name')
44+argparser.add_argument('--output', metavar='file', required=True, help='Output file')
45+args = argparser.parse_args()
46+
47+write_template(args.output, build_template(args.test_execdir, args.testname))
48diff --git a/build-aux/gen-installed-test-shscript.py b/build-aux/gen-installed-test-shscript.py
49new file mode 100644
Andrew Geisslerd1e89492021-02-12 15:35:20 -060050index 000000000..5da86fb37
Andrew Geissler82c905d2020-04-13 13:39:40 -050051--- /dev/null
52+++ b/build-aux/gen-installed-test-shscript.py
53@@ -0,0 +1,25 @@
54+import sys
55+import os
56+import argparse
57+
58+def write_template(filename, data):
59+ with open(filename, 'w') as f:
60+ f.write(data)
61+
62+def build_template(testdir, testname):
63+ return ''.join([
64+ "#!/usr/bin/env sh\n",
65+ "export GST_STATE_IGNORE_ELEMENTS=''\n",
66+ "export CK_DEFAULT_TIMEOUT=20\n",
67+ "export GST_PLUGIN_LOADING_WHITELIST='gstreamer'\n",
68+ "{}\n".format(os.path.join(testdir, testname)),
69+ ])
70+
71+argparser = argparse.ArgumentParser(description='Generate installed-test data.')
72+argparser.add_argument('--test-execdir', metavar='dir', required=True, help='Installed test directory')
73+argparser.add_argument('--testname', metavar='name', required=True, help='Installed test name')
74+argparser.add_argument('--output', metavar='file', required=True, help='Output file')
75+args = argparser.parse_args()
76+
77+write_template(args.output, build_template(args.test_execdir, args.testname))
78+os.chmod(args.output, 0o755)
79diff --git a/meson_options.txt b/meson_options.txt
Andrew Geisslerd1e89492021-02-12 15:35:20 -060080index 72c3997e2..346c423d4 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050081--- a/meson_options.txt
82+++ b/meson_options.txt
Andrew Geissler6ce62a22020-11-30 19:58:47 -060083@@ -15,6 +15,8 @@ option('poisoning', type : 'boolean', value : false, description : 'Enable poiso
Andrew Geissler82c905d2020-04-13 13:39:40 -050084 option('memory-alignment', type: 'combo',
85 choices : ['1', '2', '4', '8', '16', '32', '64', '128', '256', '512', '1024', '2048', '4096', '8192', 'malloc', 'pagesize'],
86 value: 'malloc')
87+option('installed-tests', type : 'boolean', value : false, description : 'enable installed tests')
88+option('test-files-path', type : 'string', description : 'Path where to find test files')
89
90 # Feature options
91 option('check', type : 'feature', value : 'auto', description : 'Build unit test libraries')
92diff --git a/tests/check/meson.build b/tests/check/meson.build
Andrew Geisslerd1e89492021-02-12 15:35:20 -060093index a617cf159..e629131c5 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050094--- a/tests/check/meson.build
95+++ b/tests/check/meson.build
Andrew Geissler6ce62a22020-11-30 19:58:47 -060096@@ -120,11 +120,17 @@ if add_languages('cpp', native: false, required: false)
Andrew Geissler82c905d2020-04-13 13:39:40 -050097 ]
98 endif
99
100+test_files_path = get_option('test-files-path')
101+if test_files_path == ''
102+ test_files_path = meson.current_source_dir() + '/../files'
103+endif
104+message('Using path "@0@" as the path to read test files from'.format(test_files_path))
105+
106 test_defines = [
107 '-UG_DISABLE_ASSERT',
108 '-UG_DISABLE_CAST_CHECKS',
109 '-DGST_CHECK_TEST_ENVIRONMENT_BEACON="GST_STATE_IGNORE_ELEMENTS"',
110- '-DTESTFILE="' + meson.current_source_dir() + '/meson.build"',
111+ '-DTESTFILE="@0@"'.format(test_files_path + '/testfile'),
Andrew Geissler82c905d2020-04-13 13:39:40 -0500112 '-DGST_DISABLE_DEPRECATED',
113 ]
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600114
115@@ -138,6 +144,14 @@ endif
Andrew Geissler82c905d2020-04-13 13:39:40 -0500116 glib_deps = [gio_dep, gobject_dep, gmodule_dep, glib_dep]
117 gst_deps = [gst_dep, gst_base_dep, gst_check_dep, gst_net_dep, gst_controller_dep]
118
119+installed_tests_datadir = join_paths(prefix, get_option('datadir'), 'installed-tests', 'gstreamer-1.0')
120+installed_tests_execdir = join_paths(prefix, libexecdir, 'installed-tests', 'gstreamer-1.0')
121+installed_tests_enabled = get_option('installed-tests')
122+
123+python = import('python').find_installation()
124+gen_installed_test_desc = files('../../build-aux/gen-installed-test-desc.py')
125+gen_installed_test_shscript = files('../../build-aux/gen-installed-test-shscript.py')
126+
127 foreach t : core_tests
128 fname = t[0]
129 test_name = fname.split('.')[0].underscorify()
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600130@@ -151,8 +165,38 @@ foreach t : core_tests
Andrew Geissler82c905d2020-04-13 13:39:40 -0500131 include_directories : [configinc],
132 link_with : link_with_libs,
133 dependencies : test_deps + glib_deps + gst_deps,
134+ install_dir: installed_tests_execdir,
135+ install: installed_tests_enabled
136 )
137
138+ if installed_tests_enabled
139+ installed_test_shscript = test_name + '.sh'
140+ shscript = custom_target (test_name + '_shscript',
141+ output: installed_test_shscript,
142+ command: [
143+ python,
144+ gen_installed_test_shscript,
145+ '--test-execdir=@0@'.format(installed_tests_execdir),
146+ '--testname=@0@'.format(test_name),
147+ '--output=@0@'.format(join_paths('@OUTDIR@', installed_test_shscript)),
148+ ],
149+ install: true,
150+ install_dir: installed_tests_execdir)
151+
152+ installed_test_desc = test_name + '.test'
153+ data = custom_target(test_name + '_desc',
154+ output: installed_test_desc,
155+ command: [
156+ python,
157+ gen_installed_test_desc,
158+ '--test-execdir=@0@'.format(installed_tests_execdir),
159+ '--testname=@0@'.format(installed_test_shscript),
160+ '--output=@0@'.format(join_paths('@OUTDIR@', installed_test_desc)),
161+ ],
162+ install: true,
163+ install_dir: installed_tests_datadir)
164+ endif
165+
166 env = environment()
167 env.set('GST_PLUGIN_PATH_1_0', meson.build_root())
168 env.set('GST_PLUGIN_SYSTEM_PATH_1_0', '')
169diff --git a/tests/files/testfile b/tests/files/testfile
170new file mode 100644
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600171index 000000000..89954e0e2
Andrew Geissler82c905d2020-04-13 13:39:40 -0500172--- /dev/null
173+++ b/tests/files/testfile
174@@ -0,0 +1,80 @@
175+................................................................................
176+................................................................................
177+................................................................................
178+................................................................................
179+................................................................................
180+................................................................................
181+................................................................................
182+................................................................................
183+................................................................................
184+................................................................................
185+................................................................................
186+................................................................................
187+................................................................................
188+................................................................................
189+................................................................................
190+................................................................................
191+................................................................................
192+................................................................................
193+................................................................................
194+................................................................................
195+................................................................................
196+................................................................................
197+................................................................................
198+................................................................................
199+................................................................................
200+................................................................................
201+................................................................................
202+................................................................................
203+................................................................................
204+................................................................................
205+................................................................................
206+................................................................................
207+................................................................................
208+................................................................................
209+................................................................................
210+................................................................................
211+................................................................................
212+................................................................................
213+................................................................................
214+................................................................................
215+................................................................................
216+................................................................................
217+................................................................................
218+................................................................................
219+................................................................................
220+................................................................................
221+................................................................................
222+................................................................................
223+................................................................................
224+................................................................................
225+................................................................................
226+................................................................................
227+................................................................................
228+................................................................................
229+................................................................................
230+................................................................................
231+................................................................................
232+................................................................................
233+................................................................................
234+................................................................................
235+................................................................................
236+................................................................................
237+................................................................................
238+................................................................................
239+................................................................................
240+................................................................................
241+................................................................................
242+................................................................................
243+................................................................................
244+................................................................................
245+................................................................................
246+................................................................................
247+................................................................................
248+................................................................................
249+................................................................................
250+................................................................................
251+................................................................................
252+................................................................................
253+................................................................................
254+................................................................................
255--
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002562.29.2
Andrew Geissler82c905d2020-04-13 13:39:40 -0500257