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