xref: /aosp_15_r20/external/zstd/build/meson/tests/meson.build (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1# #############################################################################
2# Copyright (c) 2018-present     Dima Krasner <[email protected]>
3#                                lzutao <taolzu(at)gmail.com>
4# All rights reserved.
5#
6# This source code is licensed under both the BSD-style license (found in the
7# LICENSE file in the root directory of this source tree) and the GPLv2 (found
8# in the COPYING file in the root directory of this source tree).
9# #############################################################################
10
11zstd_rootdir = '../../..'
12
13tests_supported_oses = [os_linux, 'gnu/kfreebsd', os_darwin, 'gnu', 'openbsd',
14  os_freebsd, 'netbsd', 'dragonfly', os_sun]
15
16# =============================================================================
17# Test flags
18# =============================================================================
19
20FUZZER_FLAGS = ['--no-big-tests']
21FUZZERTEST = '-T200s'
22ZSTREAM_TESTTIME = '-T90s'
23DECODECORPUS_TESTTIME = '-T30'
24
25# =============================================================================
26# Executables
27# =============================================================================
28
29test_includes = [ include_directories(join_paths(zstd_rootdir, 'programs')) ]
30
31testcommon_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'),
32  join_paths(zstd_rootdir, 'programs/lorem.c'),
33  join_paths(zstd_rootdir, 'programs/util.c'),
34  join_paths(zstd_rootdir, 'programs/timefn.c'),
35  join_paths(zstd_rootdir, 'programs/benchfn.c'),
36  join_paths(zstd_rootdir, 'programs/benchzstd.c')]
37
38testcommon = static_library('testcommon',
39  testcommon_sources,
40  # needed due to use of private symbol + -fvisibility=hidden
41  link_with: libzstd_static)
42
43testcommon_dep = declare_dependency(link_with: testcommon,
44  dependencies: libzstd_deps,
45  include_directories: libzstd_includes)
46
47datagen_sources = [join_paths(zstd_rootdir, 'tests/datagencli.c'),
48  join_paths(zstd_rootdir, 'tests/loremOut.c')]
49datagen = executable('datagen',
50  datagen_sources,
51  c_args: [ '-DNDEBUG' ],
52  include_directories: test_includes,
53  dependencies: testcommon_dep,
54  install: false)
55
56fullbench_sources = [join_paths(zstd_rootdir, 'tests/fullbench.c')]
57fullbench = executable('fullbench',
58  fullbench_sources,
59  include_directories: test_includes,
60  dependencies: testcommon_dep,
61  install: false)
62
63fuzzer_sources = [join_paths(zstd_rootdir, 'tests/fuzzer.c')]
64fuzzer = executable('fuzzer',
65  fuzzer_sources,
66  include_directories: test_includes,
67  dependencies: [ testcommon_dep, thread_dep ],
68  install: false)
69
70zstreamtest_sources = [
71  join_paths(zstd_rootdir, 'tests/seqgen.c'),
72  join_paths(zstd_rootdir, 'tests/zstreamtest.c'),
73  join_paths(zstd_rootdir, 'tests/external_matchfinder.c')]
74zstreamtest = executable('zstreamtest',
75  zstreamtest_sources,
76  include_directories: test_includes,
77  dependencies: testcommon_dep,
78  install: false)
79
80paramgrill_sources = [join_paths(zstd_rootdir, 'tests/paramgrill.c')]
81paramgrill = executable('paramgrill',
82  paramgrill_sources,
83  include_directories: test_includes,
84  dependencies: [ testcommon_dep, libm_dep ],
85  install: false)
86
87roundTripCrash_sources = [join_paths(zstd_rootdir, 'tests/roundTripCrash.c')]
88roundTripCrash = executable('roundTripCrash',
89  roundTripCrash_sources,
90  dependencies: [ testcommon_dep ],
91  install: false)
92
93longmatch_sources = [join_paths(zstd_rootdir, 'tests/longmatch.c')]
94longmatch = executable('longmatch',
95  longmatch_sources,
96  dependencies: [ libzstd_dep ],
97  install: false)
98
99invalidDictionaries_sources = [join_paths(zstd_rootdir, 'tests/invalidDictionaries.c')]
100invalidDictionaries = executable('invalidDictionaries',
101  invalidDictionaries_sources,
102  dependencies: [ libzstd_dep ],
103  install: false)
104
105if 0 < legacy_level and legacy_level <= 4
106  legacy_sources = [join_paths(zstd_rootdir, 'tests/legacy.c')]
107  legacy = executable('legacy',
108    legacy_sources,
109    # Use -Dlegacy_level build option to control it
110    #c_args: '-DZSTD_LEGACY_SUPPORT=4',
111    dependencies: [ libzstd_dep ],
112    install: false)
113endif
114
115decodecorpus_sources = [join_paths(zstd_rootdir, 'tests/decodecorpus.c')]
116decodecorpus = executable('decodecorpus',
117  decodecorpus_sources,
118  include_directories: test_includes,
119  dependencies: [ testcommon_dep, libm_dep ],
120  install: false)
121
122poolTests_sources = [join_paths(zstd_rootdir, 'tests/poolTests.c')]
123poolTests = executable('poolTests',
124  poolTests_sources,
125  include_directories: test_includes,
126  dependencies: [ testcommon_dep, thread_dep ],
127  install: false)
128
129checkTag_sources = [join_paths(zstd_rootdir, 'tests/checkTag.c')]
130checkTag = executable('checkTag',
131  checkTag_sources,
132  dependencies: [ libzstd_dep ],
133  install: false)
134
135# =============================================================================
136# Tests (Use "meson test --list" to list all tests)
137# =============================================================================
138
139if tests_supported_oses.contains(host_machine_os)
140  valgrind_prog = find_program('valgrind', ['/usr/bin/valgrind'], required: false)
141  valgrindTest_py = files('valgrindTest.py')
142  if valgrind_prog.found()
143    test('valgrindTest',
144      valgrindTest_py,
145      args: [valgrind_prog.path(), zstd, datagen, fuzzer, fullbench],
146      depends: [zstd, datagen, fuzzer, fullbench],
147      timeout: 600) # Timeout should work on HDD drive
148  endif
149endif
150
151if host_machine_os != os_windows
152  playTests_sh = find_program(join_paths(zstd_rootdir, 'tests/playTests.sh'), required: true)
153
154  # add slow tests only if the meson version is new enough to support
155  # test setups with default-excluded suites
156  if meson.version().version_compare('>=0.57.0')
157    matrix = {'fast': [], 'slow': ['--test-large-data']}
158  else
159    matrix = {'fast': []}
160  endif
161
162  foreach suite, opt: matrix
163    test('test-zstd-'+suite,
164      playTests_sh,
165      args: opt,
166      env: ['ZSTD_BIN=' + zstd.full_path(), 'DATAGEN_BIN=./datagen'],
167      depends: [datagen, zstd],
168      suite: suite,
169      workdir: meson.current_build_dir(),
170      timeout: 2800) # Timeout should work on HDD drive
171  endforeach
172endif
173
174test('test-fullbench-1',
175  fullbench,
176  args: ['-i1'],
177  depends: [datagen],
178  timeout: 60)
179test('test-fullbench-2',
180  fullbench,
181  args: ['-i1', '-P0'],
182  depends: [datagen],
183  timeout: 60)
184
185if use_zlib
186  test('test-fuzzer',
187    fuzzer,
188    args: ['-v', FUZZERTEST] + FUZZER_FLAGS,
189    timeout: 480)
190endif
191
192test('test-zstream-1',
193  zstreamtest,
194  args: ['-v', ZSTREAM_TESTTIME] + FUZZER_FLAGS,
195  timeout: 240)
196test('test-zstream-3',
197  zstreamtest,
198  args: ['--newapi', '-t1', ZSTREAM_TESTTIME] + FUZZER_FLAGS,
199  timeout: 120)
200test('test-longmatch', longmatch, timeout: 36)
201test('test-invalidDictionaries', invalidDictionaries) # should be fast
202if 0 < legacy_level and legacy_level <= 4
203  test('test-legacy', legacy) # should be fast
204endif
205test('test-decodecorpus',
206  decodecorpus,
207  args: ['-t', DECODECORPUS_TESTTIME],
208  timeout: 60)
209test('test-poolTests', poolTests) # should be fast
210
211if meson.version().version_compare('>=0.57.0')
212  add_test_setup('fast',
213    is_default: true,
214    exclude_suites: ['slow'])
215  add_test_setup('slow',
216    exclude_suites: ['fast'])
217endif
218