1# #############################################################################
2# Copyright (c) 2018-present     Dima Krasner <dima@dimakrasner.com>
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'
24ZSTDRTTEST = ['--test-large-data']
25
26# =============================================================================
27# Executables
28# =============================================================================
29
30test_includes = [ include_directories(join_paths(zstd_rootdir, 'programs')) ]
31
32datagen_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'),
33  join_paths(zstd_rootdir, 'tests/datagencli.c')]
34datagen = executable('datagen',
35  datagen_sources,
36  c_args: [ '-DNDEBUG' ],
37  include_directories: test_includes,
38  dependencies: libzstd_dep,
39  install: false)
40
41fullbench_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'),
42  join_paths(zstd_rootdir, 'programs/util.c'),
43  join_paths(zstd_rootdir, 'programs/timefn.c'),
44  join_paths(zstd_rootdir, 'programs/benchfn.c'),
45  join_paths(zstd_rootdir, 'programs/benchzstd.c'),
46  join_paths(zstd_rootdir, 'tests/fullbench.c')]
47fullbench = executable('fullbench',
48  fullbench_sources,
49  include_directories: test_includes,
50  dependencies: libzstd_dep,
51  install: false)
52
53fuzzer_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'),
54  join_paths(zstd_rootdir, 'programs/util.c'),
55  join_paths(zstd_rootdir, 'programs/timefn.c'),
56  join_paths(zstd_rootdir, 'tests/fuzzer.c')]
57fuzzer = executable('fuzzer',
58  fuzzer_sources,
59  include_directories: test_includes,
60  dependencies: libzstd_dep,
61  install: false)
62
63zbufftest_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'),
64  join_paths(zstd_rootdir, 'programs/util.c'),
65  join_paths(zstd_rootdir, 'programs/timefn.c'),
66  join_paths(zstd_rootdir, 'tests/zbufftest.c')]
67zbufftest = executable('zbufftest',
68  zbufftest_sources,
69  c_args: ['-Wno-deprecated-declarations'],
70  include_directories: test_includes,
71  dependencies: libzstd_dep,
72  install: false)
73
74zstreamtest_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'),
75  join_paths(zstd_rootdir, 'programs/util.c'),
76  join_paths(zstd_rootdir, 'programs/timefn.c'),
77  join_paths(zstd_rootdir, 'tests/seqgen.c'),
78  join_paths(zstd_rootdir, 'tests/zstreamtest.c')]
79zstreamtest = executable('zstreamtest',
80  zstreamtest_sources,
81  include_directories: test_includes,
82  dependencies: libzstd_dep,
83  install: false)
84
85paramgrill_sources = [join_paths(zstd_rootdir, 'programs/benchfn.c'),
86  join_paths(zstd_rootdir, 'programs/timefn.c'),
87  join_paths(zstd_rootdir, 'programs/benchzstd.c'),
88  join_paths(zstd_rootdir, 'programs/datagen.c'),
89  join_paths(zstd_rootdir, 'programs/util.c'),
90  join_paths(zstd_rootdir, 'tests/paramgrill.c')]
91paramgrill = executable('paramgrill',
92  paramgrill_sources,
93  include_directories: test_includes,
94  dependencies: [ libzstd_dep, libm_dep ],
95  install: false)
96
97roundTripCrash_sources = [join_paths(zstd_rootdir, 'tests/roundTripCrash.c')]
98roundTripCrash = executable('roundTripCrash',
99  roundTripCrash_sources,
100  dependencies: [ libzstd_dep ],
101  install: false)
102
103longmatch_sources = [join_paths(zstd_rootdir, 'tests/longmatch.c')]
104longmatch = executable('longmatch',
105  longmatch_sources,
106  dependencies: [ libzstd_dep ],
107  install: false)
108
109invalidDictionaries_sources = [join_paths(zstd_rootdir, 'tests/invalidDictionaries.c')]
110invalidDictionaries = executable('invalidDictionaries',
111  invalidDictionaries_sources,
112  dependencies: [ libzstd_dep ],
113  install: false)
114
115if 0 < legacy_level and legacy_level <= 4
116  legacy_sources = [join_paths(zstd_rootdir, 'tests/legacy.c')]
117  legacy = executable('legacy',
118    legacy_sources,
119    # Use -Dlegacy_level build option to control it
120    #c_args: '-DZSTD_LEGACY_SUPPORT=4',
121    dependencies: [ libzstd_dep ],
122    install: false)
123endif
124
125decodecorpus_sources = [join_paths(zstd_rootdir, 'programs/util.c'),
126  join_paths(zstd_rootdir, 'programs/timefn.c'),
127  join_paths(zstd_rootdir, 'tests/decodecorpus.c')]
128decodecorpus = executable('decodecorpus',
129  decodecorpus_sources,
130  include_directories: test_includes,
131  dependencies: [ libzstd_dep, libm_dep ],
132  install: false)
133
134symbols_sources = [join_paths(zstd_rootdir, 'tests/symbols.c')]
135symbols = executable('symbols',
136  symbols_sources,
137  include_directories: test_includes,
138  c_args: host_machine_os == os_windows ? '-DZSTD_DLL_IMPORT=1' : [],
139  dependencies: [ libzstd_dep ],
140  install: false)
141
142poolTests_sources = [join_paths(zstd_rootdir, 'programs/util.c'),
143  join_paths(zstd_rootdir, 'programs/timefn.c'),
144  join_paths(zstd_rootdir, 'tests/poolTests.c'),
145  join_paths(zstd_rootdir, 'lib/common/pool.c'),
146  join_paths(zstd_rootdir, 'lib/common/threading.c'),
147  join_paths(zstd_rootdir, 'lib/common/zstd_common.c'),
148  join_paths(zstd_rootdir, 'lib/common/error_private.c')]
149poolTests = executable('poolTests',
150  poolTests_sources,
151  include_directories: test_includes,
152  dependencies: [ libzstd_dep, thread_dep ],
153  install: false)
154
155checkTag_sources = [join_paths(zstd_rootdir, 'tests/checkTag.c')]
156checkTag = executable('checkTag',
157  checkTag_sources,
158  dependencies: [ libzstd_dep ],
159  install: false)
160
161# =============================================================================
162# Tests (Use "meson test --list" to list all tests)
163# =============================================================================
164
165if tests_supported_oses.contains(host_machine_os)
166  valgrind_prog = find_program('valgrind', ['/usr/bin/valgrind'], required: true)
167  valgrindTest_py = files('valgrindTest.py')
168  test('valgrindTest',
169    valgrindTest_py,
170    args: [valgrind_prog.path(), zstd, datagen, fuzzer, fullbench],
171    depends: [zstd, datagen, fuzzer, fullbench],
172    timeout: 600) # Timeout should work on HDD drive
173endif
174
175if host_machine_os != os_windows
176  playTests_sh = find_program(join_paths(zstd_rootdir, 'tests/playTests.sh'), required: true)
177  test('test-zstd',
178    playTests_sh,
179    args: ZSTDRTTEST,
180    env: ['ZSTD=' + zstd.full_path()],
181    depends: [datagen],
182    workdir: meson.current_build_dir(),
183    timeout: 2800) # Timeout should work on HDD drive
184endif
185
186test('test-fullbench-1',
187  fullbench,
188  args: ['-i1'],
189  depends: [datagen],
190  timeout: 60)
191test('test-fullbench-2',
192  fullbench,
193  args: ['-i1', '-P0'],
194  depends: [datagen],
195  timeout: 60)
196
197if use_zlib
198  test('test-fuzzer',
199    fuzzer,
200    args: ['-v', FUZZERTEST] + FUZZER_FLAGS,
201    timeout: 480)
202endif
203
204test('test-zbuff',
205  zbufftest,
206  args: [ZSTREAM_TESTTIME],
207  timeout: 120)
208test('test-zstream-1',
209  zstreamtest,
210  args: ['-v', ZSTREAM_TESTTIME] + FUZZER_FLAGS,
211  timeout: 240)
212test('test-zstream-2',
213  zstreamtest,
214  args: ['-mt', '-t1', ZSTREAM_TESTTIME] + FUZZER_FLAGS,
215  timeout: 120)
216test('test-zstream-3',
217  zstreamtest,
218  args: ['--newapi', '-t1', ZSTREAM_TESTTIME] + FUZZER_FLAGS,
219  timeout: 120)
220test('test-longmatch', longmatch, timeout: 36)
221test('test-invalidDictionaries', invalidDictionaries) # should be fast
222test('test-symbols', symbols) # should be fast
223if 0 < legacy_level and legacy_level <= 4
224  test('test-legacy', legacy) # should be fast
225endif
226test('test-decodecorpus',
227  decodecorpus,
228  args: ['-t', DECODECORPUS_TESTTIME],
229  timeout: 60)
230test('test-poolTests', poolTests) # should be fast
231