]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | # |
2 | # This file is open source software, licensed to you under the terms | |
3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file | |
4 | # distributed with this work for additional information regarding copyright | |
5 | # ownership. You may not use this file except in compliance with the License. | |
6 | # | |
7 | # You may obtain a copy of the License at | |
8 | # | |
9 | # http://www.apache.org/licenses/LICENSE-2.0 | |
10 | # | |
11 | # Unless required by applicable law or agreed to in writing, | |
12 | # software distributed under the License is distributed on an | |
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | # KIND, either express or implied. See the License for the | |
15 | # specific language governing permissions and limitations | |
16 | # under the License. | |
17 | # | |
18 | ||
19 | # | |
20 | # Copyright (C) 2018 Scylladb, Ltd. | |
21 | # | |
22 | ||
23 | # Logical target for all unit tests. | |
24 | add_custom_target (unit_tests) | |
25 | ||
9f95a23c TL |
26 | set (Seastar_UNIT_TEST_SMP |
27 | 2 | |
28 | CACHE | |
29 | STRING | |
30 | "Run unit tests with this many cores.") | |
11fdf7f2 | 31 | |
9f95a23c TL |
32 | # |
33 | # Define a new unit test with the given name. | |
34 | # | |
35 | # seastar_add_test (name | |
36 | # [KIND {SEASTAR,BOOST,CUSTOM}] | |
37 | # [SOURCES source1 source2 ... sourcen] | |
38 | # [WORKING_DIRECTORY dir] | |
39 | # [LIBRARIES library1 library2 ... libraryn] | |
40 | # [RUN_ARGS arg1 arg2 ... argn]) | |
41 | # | |
42 | # There are three kinds of test we support (the KIND parameter): | |
43 | # | |
44 | # - SEASTAR: Unit tests which use macros like `SEASTAR_TEST_CASE` | |
45 | # - BOOST: Unit tests which use macros like `BOOST_AUTO_TEST_CASE` | |
46 | # - CUSTOM: Custom tests which need to be specified | |
47 | # | |
48 | # SEASTAR and BOOST tests will have their output saved for interpretation by the Jenkins continuous integration service | |
49 | # if this is configured for the build. | |
50 | # | |
51 | # KIND can be omitted, in which case it is assumed to be SEASTAR. | |
52 | # | |
53 | # If SOURCES is provided, then the test files are first compiled into an executable which has the same name as the test | |
54 | # but with a suffix ("_test"). | |
55 | # | |
56 | # WORKING_DIRECTORY can be optionally provided to choose where the test is executed. | |
57 | # | |
58 | # If LIBRARIES is provided along with SOURCES, then the executable is additionally linked with these libraries. | |
59 | # | |
60 | # RUN_ARGS are optional additional arguments to pass to the executable. For SEASTAR tests, these come after `--`. For | |
61 | # CUSTOM tests with no SOURCES, this parameter can be used to specify the executable name as well as its arguments since | |
62 | # no executable is compiled. | |
63 | # | |
64 | function (seastar_add_test name) | |
65 | set (test_kinds | |
66 | SEASTAR | |
67 | BOOST | |
68 | CUSTOM) | |
11fdf7f2 | 69 | |
9f95a23c TL |
70 | cmake_parse_arguments (parsed_args |
71 | "" | |
72 | "WORKING_DIRECTORY;KIND" | |
73 | "RUN_ARGS;SOURCES;LIBRARIES" | |
74 | ${ARGN}) | |
75 | ||
76 | if (NOT parsed_args_KIND) | |
77 | set (parsed_args_KIND SEASTAR) | |
78 | elseif (NOT (parsed_args_KIND IN_LIST test_kinds)) | |
79 | message (FATAL_ERROR "Invalid test kind. KIND must be one of ${test_kinds}") | |
80 | endif () | |
11fdf7f2 TL |
81 | |
82 | if (parsed_args_SOURCES) | |
9f95a23c TL |
83 | # These may be unused. |
84 | seastar_jenkins_arguments (${name} jenkins_args) | |
11fdf7f2 | 85 | |
9f95a23c TL |
86 | # |
87 | # Each kind of test must populate the `args` and `libraries` lists. | |
88 | # | |
89 | ||
90 | set (libraries "${parsed_args_LIBRARIES}") | |
91 | ||
92 | if (parsed_args_KIND STREQUAL "SEASTAR") | |
93 | set (args "") | |
94 | ||
95 | list (APPEND libraries | |
96 | seastar_testing | |
97 | seastar_private) | |
11fdf7f2 TL |
98 | |
99 | if (NOT (Seastar_JENKINS STREQUAL "")) | |
9f95a23c | 100 | list (APPEND args ${jenkins_args}) |
11fdf7f2 TL |
101 | endif () |
102 | ||
9f95a23c TL |
103 | list (APPEND args -- -c ${Seastar_UNIT_TEST_SMP}) |
104 | list (APPEND args ${parsed_args_RUN_ARGS}) | |
105 | elseif (parsed_args_KIND STREQUAL "BOOST") | |
106 | set (args "") | |
107 | ||
108 | list (APPEND libraries | |
109 | Boost::unit_test_framework | |
110 | seastar_private) | |
111 | ||
112 | if (NOT (Seastar_JENKINS STREQUAL "")) | |
113 | list (APPEND args ${jenkins_args}) | |
11fdf7f2 TL |
114 | endif () |
115 | ||
9f95a23c TL |
116 | list (APPEND args ${parsed_args_RUN_ARGS}) |
117 | else () # CUSTOM | |
118 | set (args ${parsed_args_RUN_ARGS}) | |
11fdf7f2 TL |
119 | endif () |
120 | ||
121 | set (executable_target test_unit_${name}) | |
122 | add_executable (${executable_target} ${parsed_args_SOURCES}) | |
123 | ||
124 | target_link_libraries (${executable_target} | |
125 | PRIVATE ${libraries}) | |
126 | ||
127 | target_compile_definitions (${executable_target} | |
128 | PRIVATE SEASTAR_TESTING_MAIN) | |
129 | ||
130 | target_include_directories (${executable_target} | |
131 | PRIVATE | |
132 | ${CMAKE_CURRENT_SOURCE_DIR} | |
133 | ${Seastar_SOURCE_DIR}/src) | |
134 | ||
135 | set_target_properties (${executable_target} | |
136 | PROPERTIES | |
9f95a23c | 137 | OUTPUT_NAME ${name}_test) |
11fdf7f2 TL |
138 | |
139 | add_dependencies (unit_tests ${executable_target}) | |
9f95a23c TL |
140 | set (forwarded_args COMMAND ${executable_target} ${args}) |
141 | else () | |
142 | if (NOT (parsed_args_KIND STREQUAL "CUSTOM")) | |
143 | message (FATAL_ERROR "SOURCES are required for ${parsed_args_KIND} tests") | |
144 | endif () | |
145 | ||
146 | set (forwarded_args COMMAND ${parsed_args_RUN_ARGS}) | |
11fdf7f2 TL |
147 | endif () |
148 | ||
9f95a23c TL |
149 | # |
150 | # We expect `forwarded_args` to be populated correctly at this point. | |
151 | # | |
152 | ||
11fdf7f2 TL |
153 | set (target test_unit_${name}_run) |
154 | ||
155 | if (parsed_args_WORKING_DIRECTORY) | |
9f95a23c | 156 | list (APPEND forwarded_args WORKING_DIRECTORY ${parsed_args_WORKING_DIRECTORY}) |
11fdf7f2 TL |
157 | endif () |
158 | ||
159 | add_custom_target (${target} | |
9f95a23c | 160 | ${forwarded_args} |
11fdf7f2 TL |
161 | USES_TERMINAL) |
162 | ||
163 | add_test ( | |
164 | NAME Seastar.unit.${name} | |
165 | COMMAND ${CMAKE_COMMAND} --build ${Seastar_BINARY_DIR} --target ${target}) | |
166 | ||
167 | set_tests_properties (Seastar.unit.${name} | |
168 | PROPERTIES | |
9f95a23c TL |
169 | TIMEOUT ${Seastar_TEST_TIMEOUT} |
170 | ENVIRONMENT "${Seastar_TEST_ENVIRONMENT}") | |
171 | endfunction () | |
172 | ||
173 | # | |
174 | # Define a new custom unit test whose entry point is a Seastar application. | |
175 | # | |
176 | # seastar_add_app_test (name | |
177 | # [SOURCES source1 source2 ... sourcen] | |
178 | # [LIBRARIES library1 library2 ... libraryn] | |
179 | # [RUN_ARGS arg1 arg2 ... argn]) | |
180 | # | |
181 | # These kinds of tests are structured like Seastar applications. | |
182 | # | |
183 | # These tests always link against `seastar_private` and are always invoked with | |
184 | # `-c ${Seastar_UNIT_TEST_SMP}`. | |
185 | # | |
186 | function (seastar_add_app_test name) | |
187 | cmake_parse_arguments (parsed_args | |
188 | "" | |
189 | "" | |
190 | "RUN_ARGS;SOURCES;LIBRARIES" | |
191 | ${ARGN}) | |
192 | ||
193 | seastar_add_test (${name} | |
194 | KIND CUSTOM | |
195 | SOURCES ${parsed_args_SOURCES} | |
196 | LIBRARIES | |
197 | seastar_private | |
198 | ${parsed_args_LIBRARIES} | |
199 | RUN_ARGS | |
200 | -c ${Seastar_UNIT_TEST_SMP} | |
201 | ${parsed_args_RUN_ARGS}) | |
202 | endfunction () | |
11fdf7f2 TL |
203 | |
204 | function (prepend_each var prefix) | |
205 | set (result "") | |
206 | ||
207 | foreach (x ${ARGN}) | |
208 | list (APPEND result ${prefix}/${x}) | |
209 | endforeach () | |
210 | ||
211 | set (${var} ${result} PARENT_SCOPE) | |
212 | endfunction () | |
213 | ||
214 | add_custom_target (test_unit | |
215 | COMMAND ctest --verbose -R Seastar.unit | |
216 | USES_TERMINAL) | |
217 | ||
218 | seastar_add_test (abort_source | |
219 | SOURCES abort_source_test.cc) | |
220 | ||
221 | seastar_add_test (alloc | |
222 | SOURCES alloc_test.cc) | |
223 | ||
224 | if (NOT Seastar_EXECUTE_ONLY_FAST_TESTS) | |
225 | set (allocator_test_args "") | |
226 | else () | |
227 | if (CMAKE_BUILD_TYPE STREQUAL "Debug") | |
228 | set (allocator_test_args --iterations 5) | |
229 | else () | |
230 | set (allocator_test_args --time 0.1) | |
231 | endif () | |
232 | endif () | |
233 | ||
234 | seastar_add_test (allocator | |
235 | SOURCES allocator_test.cc | |
236 | RUN_ARGS ${allocator_test_args}) | |
237 | ||
9f95a23c TL |
238 | seastar_add_app_test (alien |
239 | SOURCES alien_test.cc) | |
11fdf7f2 TL |
240 | |
241 | seastar_add_test (checked_ptr | |
242 | SOURCES checked_ptr_test.cc) | |
243 | ||
244 | seastar_add_test (chunked_fifo | |
245 | SOURCES chunked_fifo_test.cc) | |
246 | ||
247 | seastar_add_test (circular_buffer | |
248 | SOURCES circular_buffer_test.cc) | |
249 | ||
250 | seastar_add_test (circular_buffer_fixed_capacity | |
251 | SOURCES circular_buffer_fixed_capacity_test.cc) | |
252 | ||
253 | seastar_add_test (connect | |
254 | SOURCES connect_test.cc) | |
255 | ||
9f95a23c TL |
256 | if (Seastar_EXPERIMENTAL_COROUTINES_TS) |
257 | seastar_add_test (coroutines | |
258 | SOURCES coroutines_test.cc) | |
259 | endif () | |
260 | ||
11fdf7f2 TL |
261 | seastar_add_test (defer |
262 | SOURCES defer_test.cc) | |
263 | ||
9f95a23c TL |
264 | seastar_add_test (deleter |
265 | SOURCES deleter_test.cc) | |
266 | ||
267 | seastar_add_app_test (directory | |
268 | SOURCES directory_test.cc) | |
11fdf7f2 | 269 | |
9f95a23c TL |
270 | seastar_add_app_test (distributed |
271 | SOURCES distributed_test.cc) | |
11fdf7f2 TL |
272 | |
273 | seastar_add_test (dns | |
274 | SOURCES dns_test.cc) | |
275 | ||
276 | seastar_add_test (execution_stage | |
277 | SOURCES execution_stage_test.cc) | |
278 | ||
279 | seastar_add_test (expiring_fifo | |
280 | SOURCES expiring_fifo_test.cc) | |
281 | ||
282 | seastar_add_test (fair_queue | |
283 | SOURCES fair_queue_test.cc) | |
284 | ||
285 | seastar_add_test (file_io | |
286 | SOURCES file_io_test.cc) | |
287 | ||
288 | seastar_add_test (foreign_ptr | |
289 | SOURCES foreign_ptr_test.cc) | |
290 | ||
291 | seastar_add_test (fstream | |
292 | SOURCES | |
293 | fstream_test.cc | |
294 | mock_file.hh) | |
295 | ||
296 | seastar_add_test (futures | |
297 | SOURCES futures_test.cc) | |
298 | ||
9f95a23c TL |
299 | seastar_add_test (sharded |
300 | SOURCES sharded_test.cc) | |
301 | ||
11fdf7f2 TL |
302 | seastar_add_test (httpd |
303 | SOURCES | |
304 | httpd_test.cc | |
305 | loopback_socket.hh) | |
306 | ||
9f95a23c TL |
307 | seastar_add_test (ipv6 |
308 | SOURCES ipv6_test.cc) | |
309 | ||
310 | seastar_add_test (network_interface | |
311 | SOURCES network_interface_test.cc) | |
312 | ||
11fdf7f2 TL |
313 | seastar_add_test (json_formatter |
314 | SOURCES json_formatter_test.cc) | |
315 | ||
316 | seastar_add_test (lowres_clock | |
317 | SOURCES lowres_clock_test.cc) | |
318 | ||
9f95a23c TL |
319 | seastar_add_test (metrics |
320 | SOURCES metrics_test.cc) | |
321 | ||
11fdf7f2 | 322 | seastar_add_test (net_config |
9f95a23c | 323 | KIND BOOST |
11fdf7f2 TL |
324 | SOURCES net_config_test.cc) |
325 | ||
326 | seastar_add_test (noncopyable_function | |
9f95a23c | 327 | KIND BOOST |
11fdf7f2 TL |
328 | SOURCES noncopyable_function_test.cc) |
329 | ||
330 | seastar_add_test (output_stream | |
331 | SOURCES output_stream_test.cc) | |
332 | ||
333 | seastar_add_test (packet | |
9f95a23c | 334 | KIND BOOST |
11fdf7f2 TL |
335 | SOURCES packet_test.cc) |
336 | ||
337 | seastar_add_test (program_options | |
9f95a23c | 338 | KIND BOOST |
11fdf7f2 TL |
339 | SOURCES program_options_test.cc) |
340 | ||
341 | seastar_add_test (queue | |
342 | SOURCES queue_test.cc) | |
343 | ||
344 | seastar_add_test (rpc | |
345 | SOURCES | |
346 | loopback_socket.hh | |
347 | rpc_test.cc) | |
348 | ||
349 | seastar_add_test (semaphore | |
350 | SOURCES semaphore_test.cc) | |
351 | ||
352 | seastar_add_test (shared_ptr | |
9f95a23c | 353 | KIND BOOST |
11fdf7f2 TL |
354 | SOURCES shared_ptr_test.cc) |
355 | ||
356 | seastar_add_test (signal | |
357 | SOURCES signal_test.cc) | |
358 | ||
359 | seastar_add_test (simple_stream | |
9f95a23c | 360 | KIND BOOST |
11fdf7f2 TL |
361 | SOURCES simple_stream_test.cc) |
362 | ||
363 | # TODO: Disabled for now. See GH-520. | |
364 | # seastar_add_test (slab | |
365 | # SOURCES slab_test.cc | |
366 | # NO_SEASTAR_TESTING_LIBRARY) | |
367 | ||
9f95a23c TL |
368 | seastar_add_app_test (smp |
369 | SOURCES smp_test.cc) | |
370 | ||
371 | seastar_add_app_test (socket | |
372 | SOURCES socket_test.cc) | |
11fdf7f2 TL |
373 | |
374 | seastar_add_test (sstring | |
9f95a23c | 375 | KIND BOOST |
11fdf7f2 TL |
376 | SOURCES sstring_test.cc) |
377 | ||
378 | seastar_add_test (stall_detector | |
379 | SOURCES stall_detector_test.cc) | |
380 | ||
381 | seastar_add_test (thread | |
382 | SOURCES thread_test.cc) | |
383 | ||
9f95a23c TL |
384 | seastar_add_test (scheduling_group |
385 | SOURCES scheduling_group_test.cc) | |
386 | ||
387 | seastar_add_app_test (thread_context_switch | |
388 | SOURCES thread_context_switch_test.cc) | |
11fdf7f2 | 389 | |
9f95a23c TL |
390 | seastar_add_app_test (timer |
391 | SOURCES timer_test.cc) | |
392 | ||
393 | seastar_add_test (uname | |
394 | KIND BOOST | |
395 | SOURCES uname_test.cc) | |
11fdf7f2 TL |
396 | |
397 | set (tls_certificate_files | |
398 | catest.key | |
399 | catest.pem | |
400 | tls-ca-bundle.pem | |
401 | test.crl | |
402 | test.crt | |
403 | test.csr | |
404 | test.key) | |
405 | ||
406 | prepend_each ( | |
407 | in_tls_certificate_files | |
408 | ${CMAKE_CURRENT_SOURCE_DIR}/ | |
409 | ${tls_certificate_files}) | |
410 | ||
411 | prepend_each ( | |
412 | out_tls_certificate_files | |
413 | ${CMAKE_CURRENT_BINARY_DIR}/ | |
414 | ${tls_certificate_files}) | |
415 | ||
416 | add_custom_command ( | |
417 | DEPENDS ${in_tls_certificate_files} | |
418 | OUTPUT ${out_tls_certificate_files} | |
419 | COMMAND ${CMAKE_COMMAND} -E copy ${in_tls_certificate_files} ${CMAKE_CURRENT_BINARY_DIR}) | |
420 | ||
421 | # TODO: Disabled for now. See GH-514. | |
422 | # seastar_add_test (tls | |
423 | # DEPENDS ${out_tls_certificate_files} | |
424 | # SOURCES tls_test.cc | |
425 | # WORKING_DIRECTORY ${Seastar_BINARY_DIR}) | |
426 | ||
427 | seastar_add_test (tuple_utils | |
9f95a23c | 428 | KIND BOOST |
11fdf7f2 TL |
429 | SOURCES tuple_utils_test.cc) |
430 | ||
9f95a23c TL |
431 | seastar_add_test (unix_domain |
432 | SOURCES unix_domain_test.cc) | |
433 | ||
11fdf7f2 | 434 | seastar_add_test (unwind |
9f95a23c | 435 | KIND BOOST |
11fdf7f2 TL |
436 | SOURCES unwind_test.cc) |
437 | ||
438 | seastar_add_test (weak_ptr | |
9f95a23c | 439 | KIND BOOST |
11fdf7f2 | 440 | SOURCES weak_ptr_test.cc) |