1#
2# Copyright (c) 2017, Alliance for Open Media. All rights reserved
3#
4# This source code is subject to the terms of the BSD 2 Clause License and the
5# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
6# not distributed with this source code in the LICENSE file, you can obtain it
7# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
8# License 1.0 was not distributed with this source code in the PATENTS file, you
9# can obtain it at www.aomedia.org/license/patent.
10#
11if(AOM_TEST_TEST_CMAKE_)
12  return()
13endif() # AOM_TEST_TEST_CMAKE_
14set(AOM_TEST_TEST_CMAKE_ 1)
15
16include(FindPythonInterp)
17include(ProcessorCount)
18
19include("${AOM_ROOT}/test/test_data_util.cmake")
20
21set(AOM_UNIT_TEST_DATA_LIST_FILE "${AOM_ROOT}/test/test-data.sha1")
22
23list(APPEND AOM_UNIT_TEST_WRAPPER_SOURCES "${AOM_GEN_SRC_DIR}/usage_exit.c"
24            "${AOM_ROOT}/test/test_libaom.cc")
25
26list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
27            "${AOM_ROOT}/test/acm_random.h"
28            "${AOM_ROOT}/test/aom_integer_test.cc"
29            "${AOM_ROOT}/test/av1_config_test.cc"
30            "${AOM_ROOT}/test/blockd_test.cc"
31            "${AOM_ROOT}/test/clear_system_state.h"
32            "${AOM_ROOT}/test/codec_factory.h"
33            "${AOM_ROOT}/test/decode_test_driver.cc"
34            "${AOM_ROOT}/test/decode_test_driver.h"
35            "${AOM_ROOT}/test/function_equivalence_test.h"
36            "${AOM_ROOT}/test/log2_test.cc"
37            "${AOM_ROOT}/test/md5_helper.h"
38            "${AOM_ROOT}/test/register_state_check.h"
39            "${AOM_ROOT}/test/test_vectors.cc"
40            "${AOM_ROOT}/test/test_vectors.h"
41            "${AOM_ROOT}/test/transform_test_base.h"
42            "${AOM_ROOT}/test/util.h"
43            "${AOM_ROOT}/test/video_source.h")
44
45if(CONFIG_INTERNAL_STATS)
46  list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
47              "${AOM_ROOT}/test/hbd_metrics_test.cc")
48endif()
49
50list(APPEND AOM_UNIT_TEST_DECODER_SOURCES "${AOM_ROOT}/test/decode_api_test.cc"
51            "${AOM_ROOT}/test/external_frame_buffer_test.cc"
52            "${AOM_ROOT}/test/invalid_file_test.cc"
53            "${AOM_ROOT}/test/test_vector_test.cc"
54            "${AOM_ROOT}/test/ivf_video_source.h")
55
56list(APPEND AOM_UNIT_TEST_ENCODER_SOURCES
57            "${AOM_ROOT}/test/active_map_test.cc"
58            "${AOM_ROOT}/test/altref_test.cc"
59            "${AOM_ROOT}/test/aq_segment_test.cc"
60            "${AOM_ROOT}/test/borders_test.cc"
61            "${AOM_ROOT}/test/cpu_speed_test.cc"
62            "${AOM_ROOT}/test/datarate_test.cc"
63            "${AOM_ROOT}/test/encode_api_test.cc"
64            "${AOM_ROOT}/test/encode_test_driver.cc"
65            "${AOM_ROOT}/test/encode_test_driver.h"
66            "${AOM_ROOT}/test/end_to_end_test.cc"
67            "${AOM_ROOT}/test/error_resilience_test.cc"
68            "${AOM_ROOT}/test/frame_size_tests.cc"
69            "${AOM_ROOT}/test/horz_superres_test.cc"
70            "${AOM_ROOT}/test/i420_video_source.h"
71            "${AOM_ROOT}/test/lossless_test.cc"
72            "${AOM_ROOT}/test/monochrome_test.cc"
73            "${AOM_ROOT}/test/qm_test.cc"
74            "${AOM_ROOT}/test/resize_test.cc"
75            "${AOM_ROOT}/test/scalability_test.cc"
76            "${AOM_ROOT}/test/y4m_test.cc"
77            "${AOM_ROOT}/test/y4m_video_source.h"
78            "${AOM_ROOT}/test/yuv_video_source.h")
79
80list(APPEND AOM_DECODE_PERF_TEST_SOURCES "${AOM_ROOT}/test/decode_perf_test.cc")
81list(APPEND AOM_ENCODE_PERF_TEST_SOURCES "${AOM_ROOT}/test/encode_perf_test.cc")
82list(APPEND AOM_UNIT_TEST_WEBM_SOURCES "${AOM_ROOT}/test/webm_video_source.h")
83list(APPEND AOM_TEST_INTRA_PRED_SPEED_SOURCES "${AOM_GEN_SRC_DIR}/usage_exit.c"
84            "${AOM_ROOT}/test/test_intra_pred_speed.cc")
85
86if(NOT BUILD_SHARED_LIBS)
87  list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
88              "${AOM_ROOT}/test/cdef_test.cc"
89              "${AOM_ROOT}/test/cfl_test.cc"
90              "${AOM_ROOT}/test/convolve_test.cc"
91              "${AOM_ROOT}/test/hiprec_convolve_test.cc"
92              "${AOM_ROOT}/test/hiprec_convolve_test_util.cc"
93              "${AOM_ROOT}/test/hiprec_convolve_test_util.h"
94              "${AOM_ROOT}/test/intrabc_test.cc"
95              "${AOM_ROOT}/test/intrapred_test.cc"
96              "${AOM_ROOT}/test/lpf_test.cc"
97              "${AOM_ROOT}/test/onyxc_int_test.cc"
98              "${AOM_ROOT}/test/scan_test.cc"
99              "${AOM_ROOT}/test/selfguided_filter_test.cc"
100              "${AOM_ROOT}/test/simd_cmp_impl.h"
101              "${AOM_ROOT}/test/simd_impl.h")
102
103  if(CONFIG_ACCOUNTING)
104    list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
105                "${AOM_ROOT}/test/accounting_test.cc")
106  endif()
107
108  if(CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
109    list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
110                "${AOM_ROOT}/test/av1_encoder_parms_get_to_decoder.cc"
111                "${AOM_ROOT}/test/av1_ext_tile_test.cc"
112                "${AOM_ROOT}/test/binary_codes_test.cc"
113                "${AOM_ROOT}/test/boolcoder_test.cc"
114                "${AOM_ROOT}/test/coding_path_sync.cc"
115                "${AOM_ROOT}/test/decode_multithreaded_test.cc"
116                "${AOM_ROOT}/test/divu_small_test.cc"
117                "${AOM_ROOT}/test/dr_prediction_test.cc"
118                "${AOM_ROOT}/test/ec_test.cc"
119                "${AOM_ROOT}/test/ethread_test.cc"
120                "${AOM_ROOT}/test/film_grain_table_test.cc"
121                "${AOM_ROOT}/test/segment_binarization_sync.cc"
122                "${AOM_ROOT}/test/superframe_test.cc"
123                "${AOM_ROOT}/test/tile_independence_test.cc")
124  endif()
125
126  list(APPEND AOM_UNIT_TEST_COMMON_INTRIN_NEON
127              "${AOM_ROOT}/test/simd_cmp_neon.cc")
128  if(HAVE_NEON)
129    list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
130                "${AOM_ROOT}/test/simd_neon_test.cc")
131  endif()
132
133  list(APPEND AOM_UNIT_TEST_COMMON_INTRIN_SSE2
134              "${AOM_ROOT}/test/simd_cmp_sse2.cc")
135  if(HAVE_SSE2)
136    list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
137                "${AOM_ROOT}/test/simd_sse2_test.cc")
138  endif()
139
140  list(APPEND AOM_UNIT_TEST_COMMON_INTRIN_SSSE3
141              "${AOM_ROOT}/test/simd_cmp_ssse3.cc")
142  if(HAVE_SSSE3)
143    list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
144                "${AOM_ROOT}/test/simd_ssse3_test.cc")
145  endif()
146
147  if(HAVE_SSE4)
148    list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
149                "${AOM_ROOT}/test/simd_sse4_test.cc")
150  endif()
151
152  if(HAVE_SSE4_1)
153    list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
154                "${AOM_ROOT}/test/filterintra_test.cc")
155  endif()
156
157  list(APPEND AOM_UNIT_TEST_COMMON_INTRIN_AVX2
158              "${AOM_ROOT}/test/simd_cmp_avx2.cc")
159  if(HAVE_AVX2)
160    list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
161                "${AOM_ROOT}/test/simd_avx2_test.cc")
162  endif()
163
164  list(APPEND AOM_UNIT_TEST_ENCODER_SOURCES
165              "${AOM_ROOT}/test/arf_freq_test.cc"
166              "${AOM_ROOT}/test/av1_convolve_2d_test.cc"
167              "${AOM_ROOT}/test/av1_convolve_2d_test_util.cc"
168              "${AOM_ROOT}/test/av1_convolve_2d_test_util.h"
169              "${AOM_ROOT}/test/av1_fwd_txfm1d_test.cc"
170              "${AOM_ROOT}/test/av1_fwd_txfm2d_test.cc"
171              "${AOM_ROOT}/test/av1_inv_txfm1d_test.cc"
172              "${AOM_ROOT}/test/av1_inv_txfm2d_test.cc"
173              "${AOM_ROOT}/test/av1_round_shift_array_test.cc"
174              "${AOM_ROOT}/test/av1_txfm_test.cc"
175              "${AOM_ROOT}/test/av1_txfm_test.h"
176              "${AOM_ROOT}/test/av1_wedge_utils_test.cc"
177              "${AOM_ROOT}/test/blend_a64_mask_1d_test.cc"
178              "${AOM_ROOT}/test/blend_a64_mask_test.cc"
179              "${AOM_ROOT}/test/comp_avg_pred_test.cc"
180              "${AOM_ROOT}/test/comp_avg_pred_test.h"
181              "${AOM_ROOT}/test/comp_mask_variance_test.cc"
182              "${AOM_ROOT}/test/encodetxb_test.cc"
183              "${AOM_ROOT}/test/error_block_test.cc"
184              "${AOM_ROOT}/test/fft_test.cc"
185              "${AOM_ROOT}/test/fwht4x4_test.cc"
186              "${AOM_ROOT}/test/masked_sad_test.cc"
187              "${AOM_ROOT}/test/masked_variance_test.cc"
188              "${AOM_ROOT}/test/motion_vector_test.cc"
189              "${AOM_ROOT}/test/noise_model_test.cc"
190              "${AOM_ROOT}/test/obmc_sad_test.cc"
191              "${AOM_ROOT}/test/obmc_variance_test.cc"
192              "${AOM_ROOT}/test/pickrst_test.cc"
193              "${AOM_ROOT}/test/sad_test.cc"
194              "${AOM_ROOT}/test/subtract_test.cc"
195              "${AOM_ROOT}/test/reconinter_test.cc"
196              "${AOM_ROOT}/test/sum_squares_test.cc"
197              "${AOM_ROOT}/test/variance_test.cc"
198              "${AOM_ROOT}/test/wiener_test.cc"
199              "${AOM_ROOT}/test/warp_filter_test.cc"
200              "${AOM_ROOT}/test/warp_filter_test_util.cc"
201              "${AOM_ROOT}/test/warp_filter_test_util.h")
202
203  list(APPEND AOM_UNIT_TEST_ENCODER_INTRIN_SSE4_1
204              "${AOM_ROOT}/test/av1_highbd_iht_test.cc"
205              "${AOM_ROOT}/test/av1_quantize_test.cc"
206              "${AOM_ROOT}/test/corner_match_test.cc"
207              "${AOM_ROOT}/test/quantize_func_test.cc"
208              "${AOM_ROOT}/test/simd_cmp_sse4.cc")
209
210  if(HAVE_SSE4_1)
211    list(APPEND AOM_UNIT_TEST_ENCODER_SOURCES
212                "${AOM_ROOT}/test/av1_convolve_scale_test.cc"
213                "${AOM_ROOT}/test/av1_horz_only_frame_superres_test.cc"
214                "${AOM_ROOT}/test/intra_edge_test.cc")
215
216  endif()
217
218  if(HAVE_SSE4_2)
219    list(APPEND AOM_UNIT_TEST_ENCODER_SOURCES "${AOM_ROOT}/test/hash_test.cc")
220  endif()
221
222endif()
223
224if(ENABLE_TESTS)
225  find_package(PythonInterp)
226  if(NOT PYTHONINTERP_FOUND)
227    message(FATAL_ERROR
228              "--- Unit tests require Python, rerun cmake with "
229              "-DENABLE_TESTS=0 to avoid this error, or install Python and "
230              "make sure it's in your PATH.")
231  endif()
232
233  if(MSVC) # Force static run time to avoid collisions with googletest.
234    include("${AOM_ROOT}/build/cmake/msvc_runtime.cmake")
235    if(BUILD_SHARED_LIBS)
236      set(AOM_DISABLE_GTEST_CMAKE 1)
237    endif()
238  endif()
239
240  if(BUILD_SHARED_LIBS AND APPLE) # Silence an RPATH warning.
241    set(CMAKE_MACOSX_RPATH 1)
242  endif()
243
244  include_directories(
245    "${AOM_ROOT}/third_party/googletest/src/googletest/include")
246
247  if(AOM_DISABLE_GTEST_CMAKE)
248    include_directories("${AOM_ROOT}/third_party/googletest/src/googletest")
249    add_library(
250      gtest
251      STATIC
252      "${AOM_ROOT}/third_party/googletest/src/googletest/src/gtest-all.cc")
253  else()
254    add_subdirectory("${AOM_ROOT}/third_party/googletest/src/googletest"
255                     EXCLUDE_FROM_ALL)
256  endif()
257endif()
258
259# Setup testdata download targets, test build targets, and test run targets. The
260# libaom and app util targets must exist before this function is called.
261function(setup_aom_test_targets)
262
263  # TODO(tomfinegan): Build speed optimization. $AOM_UNIT_TEST_COMMON_SOURCES
264  # and $AOM_UNIT_TEST_ENCODER_SOURCES are very large. The build of test targets
265  # could be sped up (on multicore build machines) by compiling sources in each
266  # list into separate object library targets, and then linking them into
267  # test_libaom.
268  add_library(test_aom_common OBJECT ${AOM_UNIT_TEST_COMMON_SOURCES})
269  add_dependencies(test_aom_common aom)
270
271  if(CONFIG_AV1_DECODER)
272    add_library(test_aom_decoder OBJECT ${AOM_UNIT_TEST_DECODER_SOURCES})
273    add_dependencies(test_aom_decoder aom)
274  endif()
275
276  if(CONFIG_AV1_ENCODER)
277    add_library(test_aom_encoder OBJECT ${AOM_UNIT_TEST_ENCODER_SOURCES})
278    add_dependencies(test_aom_encoder aom)
279  endif()
280
281  add_executable(test_libaom ${AOM_UNIT_TEST_WRAPPER_SOURCES}
282                 $<TARGET_OBJECTS:aom_common_app_util>
283                 $<TARGET_OBJECTS:test_aom_common>)
284  list(APPEND AOM_APP_TARGETS test_libaom)
285
286  if(CONFIG_AV1_DECODER)
287    target_sources(test_libaom PRIVATE $<TARGET_OBJECTS:aom_decoder_app_util>
288                   $<TARGET_OBJECTS:test_aom_decoder>)
289
290    if(ENABLE_DECODE_PERF_TESTS AND CONFIG_WEBM_IO)
291      target_sources(test_libaom PRIVATE ${AOM_DECODE_PERF_TEST_SOURCES})
292    endif()
293  endif()
294
295  if(CONFIG_AV1_ENCODER)
296    target_sources(test_libaom PRIVATE $<TARGET_OBJECTS:test_aom_encoder>
297                   $<TARGET_OBJECTS:aom_encoder_app_util>)
298
299    if(ENABLE_ENCODE_PERF_TESTS)
300      target_sources(test_libaom PRIVATE ${AOM_ENCODE_PERF_TEST_SOURCES})
301    endif()
302
303    if(NOT BUILD_SHARED_LIBS)
304      add_executable(test_intra_pred_speed ${AOM_TEST_INTRA_PRED_SPEED_SOURCES}
305                     $<TARGET_OBJECTS:aom_common_app_util>)
306      target_link_libraries(test_intra_pred_speed ${AOM_LIB_LINK_TYPE} aom
307                            gtest)
308      list(APPEND AOM_APP_TARGETS test_intra_pred_speed)
309    endif()
310  endif()
311
312  target_link_libraries(test_libaom ${AOM_LIB_LINK_TYPE} aom gtest)
313
314  if(CONFIG_LIBYUV)
315    target_sources(test_libaom PRIVATE $<TARGET_OBJECTS:yuv>)
316  endif()
317  if(CONFIG_WEBM_IO)
318    target_sources(test_libaom PRIVATE $<TARGET_OBJECTS:webm>)
319  endif()
320  if(HAVE_SSE2)
321    add_intrinsics_source_to_target("-msse2" "test_libaom"
322                                    "AOM_UNIT_TEST_COMMON_INTRIN_SSE2")
323  endif()
324  if(HAVE_SSSE3)
325    add_intrinsics_source_to_target("-mssse3" "test_libaom"
326                                    "AOM_UNIT_TEST_COMMON_INTRIN_SSSE3")
327  endif()
328  if(HAVE_SSE4_1)
329    add_intrinsics_source_to_target("-msse4.1" "test_libaom"
330                                    "AOM_UNIT_TEST_COMMON_INTRIN_SSE4_1")
331    if(CONFIG_AV1_ENCODER)
332      if(AOM_UNIT_TEST_ENCODER_INTRIN_SSE4_1)
333        add_intrinsics_source_to_target("-msse4.1" "test_libaom"
334                                        "AOM_UNIT_TEST_ENCODER_INTRIN_SSE4_1")
335      endif()
336    endif()
337  endif()
338  if(HAVE_AVX2)
339    add_intrinsics_source_to_target("-mavx2" "test_libaom"
340                                    "AOM_UNIT_TEST_COMMON_INTRIN_AVX2")
341  endif()
342  if(HAVE_NEON)
343    add_intrinsics_source_to_target("${AOM_NEON_INTRIN_FLAG}" "test_libaom"
344                                    "AOM_UNIT_TEST_COMMON_INTRIN_NEON")
345  endif()
346
347  if(ENABLE_TESTDATA)
348    make_test_data_lists("${AOM_UNIT_TEST_DATA_LIST_FILE}" test_files
349                         test_file_checksums)
350    list(LENGTH test_files num_test_files)
351    list(LENGTH test_file_checksums num_test_file_checksums)
352
353    math(EXPR max_file_index "${num_test_files} - 1")
354    foreach(test_index RANGE ${max_file_index})
355      list(GET test_files ${test_index} test_file)
356      list(GET test_file_checksums ${test_index} test_file_checksum)
357      add_custom_target(testdata_${test_index}
358                        COMMAND
359                          ${CMAKE_COMMAND} -DAOM_CONFIG_DIR="${AOM_CONFIG_DIR}"
360                          -DAOM_ROOT="${AOM_ROOT}"
361                          -DAOM_TEST_FILE="${test_file}"
362                          -DAOM_TEST_CHECKSUM=${test_file_checksum} -P
363                          "${AOM_ROOT}/test/test_data_download_worker.cmake")
364      list(APPEND testdata_targets testdata_${test_index})
365    endforeach()
366
367    # Create a custom build target for running each test data download target.
368    add_custom_target(testdata)
369    add_dependencies(testdata ${testdata_targets})
370
371    # Skip creation of test run targets when generating for Visual Studio and
372    # Xcode unless the user explicitly requests IDE test hosting. This is done
373    # to make build cycles in the IDE tolerable when the IDE command for build
374    # project is used to build AOM. Default behavior in IDEs is to build all
375    # targets, and the test run takes hours.
376    if(((NOT MSVC) AND (NOT XCODE)) OR ENABLE_IDE_TEST_HOSTING)
377
378      # Pick a reasonable number of targets (this controls parallelization).
379      processorcount(num_test_targets)
380      if(num_test_targets EQUAL 0) # Just default to 10 targets when there's no
381                                   # processor count available.
382        set(num_test_targets 10)
383      endif()
384
385      math(EXPR max_shard_index "${num_test_targets} - 1")
386      foreach(shard_index RANGE ${max_shard_index})
387        set(test_name "test_${shard_index}")
388        add_custom_target(${test_name}
389                          COMMAND ${CMAKE_COMMAND}
390                                  -DGTEST_SHARD_INDEX=${shard_index}
391                                  -DGTEST_TOTAL_SHARDS=${num_test_targets}
392                                  -DTEST_LIBAOM=$<TARGET_FILE:test_libaom> -P
393                                  "${AOM_ROOT}/test/test_runner.cmake"
394                          DEPENDS testdata test_libaom)
395        list(APPEND test_targets ${test_name})
396      endforeach()
397      add_custom_target(runtests)
398      add_dependencies(runtests ${test_targets})
399    endif()
400  endif()
401
402  # Collect all variables containing libaom test source files.
403  get_cmake_property(all_cmake_vars VARIABLES)
404  foreach(var ${all_cmake_vars})
405
406    # https://github.com/cheshirekow/cmake_format/issues/34
407# cmake-format: off
408    if (("${var}" MATCHES "_TEST_" AND NOT
409         "${var}" MATCHES
410         "_DATA_\|_CMAKE_\|INTRA_PRED\|_COMPILED\|_HOSTING\|_PERF_\|CODER_")
411        OR (CONFIG_AV1_ENCODER AND ENABLE_ENCODE_PERF_TESTS AND
412            "${var}" MATCHES "_ENCODE_PERF_TEST_")
413        OR (CONFIG_AV1_DECODER AND ENABLE_DECODE_PERF_TESTS AND
414            "${var}" MATCHES "_DECODE_PERF_TEST_")
415        OR (CONFIG_AV1_ENCODER AND "${var}" MATCHES "_TEST_ENCODER_")
416        OR (CONFIG_AV1_DECODER AND  "${var}" MATCHES "_TEST_DECODER_"))
417      list(APPEND aom_test_source_vars ${var})
418    endif()
419    # cmake-format: on
420  endforeach()
421
422  # Libaom_test_srcs.txt generation.
423  set(libaom_test_srcs_txt_file "${AOM_CONFIG_DIR}/libaom_test_srcs.txt")
424  file(WRITE "${libaom_test_srcs_txt_file}"
425             "# This file is generated. DO NOT EDIT.\n")
426
427  # Static source file list first.
428  foreach(aom_test_source_var ${aom_test_source_vars})
429    foreach(file ${${aom_test_source_var}})
430      if(NOT "${file}" MATCHES "${AOM_CONFIG_DIR}")
431        string(REPLACE "${AOM_ROOT}/" "" file "${file}")
432        file(APPEND "${libaom_test_srcs_txt_file}" "${file}\n")
433      endif()
434    endforeach()
435  endforeach()
436
437  set(AOM_APP_TARGETS ${AOM_APP_TARGETS} PARENT_SCOPE)
438endfunction()
439