libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

jxl_tests.cmake (2999B)


      1 # Use of this source code is governed by a BSD-style
      2 # license that can be found in the LICENSE file.
      3 
      4 include(jxl_lists.cmake)
      5 
      6 if(BUILD_TESTING OR JPEGXL_ENABLE_TOOLS)
      7 # Library with test-only code shared between all tests / fuzzers.
      8 add_library(jxl_testlib-internal STATIC ${JPEGXL_INTERNAL_TESTLIB_FILES})
      9 target_compile_options(jxl_testlib-internal PRIVATE
     10   ${JPEGXL_INTERNAL_FLAGS}
     11   ${JPEGXL_COVERAGE_FLAGS}
     12 )
     13 target_compile_definitions(jxl_testlib-internal PUBLIC
     14   -DTEST_DATA_PATH="${JPEGXL_TEST_DATA_PATH}")
     15 target_include_directories(jxl_testlib-internal PUBLIC
     16   "${PROJECT_SOURCE_DIR}"
     17 )
     18 target_link_libraries(jxl_testlib-internal
     19   hwy
     20   jxl-internal
     21   jxl_threads
     22 )
     23 endif()
     24 
     25 if(NOT BUILD_TESTING)
     26   return()
     27 endif()
     28 
     29 list(APPEND JPEGXL_INTERNAL_TESTS
     30   # TODO(deymo): Move this to tools/
     31   ../tools/djxl_fuzzer_test.cc
     32   ../tools/gauss_blur_test.cc
     33 )
     34 
     35 find_package(GTest)
     36 
     37 set(JXL_WASM_TEST_LINK_FLAGS "")
     38 if (EMSCRIPTEN)
     39   # The emscripten linking step takes too much memory and crashes during the
     40   # wasm-opt step when using -O2 optimization level
     41   set(JXL_WASM_TEST_LINK_FLAGS "\
     42     -O1 \
     43     -s USE_LIBPNG=1 \
     44     -s ALLOW_MEMORY_GROWTH=1 \
     45     -s SINGLE_FILE=1 \
     46     -s EXIT_RUNTIME=1 \
     47     -s NODERAWFS=1 \
     48   ")
     49   if (JPEGXL_ENABLE_WASM_TRHEADS)
     50     set(JXL_WASM_TEST_LINK_FLAGS "${JXL_WASM_TEST_LINK_FLAGS} \
     51       -s PROXY_TO_PTHREAD \
     52       -s USE_PTHREADS=1 \
     53     ")
     54   endif()
     55 endif()  # EMSCRIPTEN
     56 
     57 # Individual test binaries:
     58 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests)
     59 foreach (TESTFILE IN LISTS JPEGXL_INTERNAL_TESTS)
     60   # The TESTNAME is the name without the extension or directory.
     61   get_filename_component(TESTNAME ${TESTFILE} NAME_WE)
     62   if(TESTFILE STREQUAL ../tools/djxl_fuzzer_test.cc)
     63     add_executable(${TESTNAME} ${TESTFILE} ../tools/djxl_fuzzer.cc)
     64   else()
     65     add_executable(${TESTNAME} ${TESTFILE})
     66   endif()
     67   if(EMSCRIPTEN)
     68     set_target_properties(${TESTNAME} PROPERTIES LINK_FLAGS "${JXL_WASM_TEST_LINK_FLAGS}")
     69   else()
     70     set_target_properties(${TESTNAME} PROPERTIES LINK_FLAGS "${JPEGXL_COVERAGE_LINK_FLAGS}")
     71   endif()
     72   target_compile_options(${TESTNAME} PRIVATE
     73     ${JPEGXL_INTERNAL_FLAGS}
     74     # Add coverage flags to the test binary so code in the private headers of
     75     # the library is also instrumented when running tests that execute it.
     76     ${JPEGXL_COVERAGE_FLAGS}
     77   )
     78   target_link_libraries(${TESTNAME}
     79     gmock
     80     GTest::GTest
     81     GTest::Main
     82     jxl_testlib-internal
     83     jxl_extras-internal
     84   )
     85   if(TESTFILE STREQUAL ../tools/gauss_blur_test.cc)
     86     target_link_libraries(${TESTNAME} jxl_gauss_blur)
     87   endif()
     88 
     89   # Output test targets in the test directory.
     90   set_target_properties(${TESTNAME} PROPERTIES PREFIX "tests/")
     91   if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
     92     set_target_properties(${TESTNAME} PROPERTIES COMPILE_FLAGS "-Wno-error")
     93   endif ()
     94   # 240 seconds because some build types (e.g. coverage) can be quite slow.
     95   gtest_discover_tests(${TESTNAME} DISCOVERY_TIMEOUT 240)
     96 endforeach ()