1# ################################################################ 2# zstd - Makefile 3# Copyright (c) Meta Platforms, Inc. and affiliates. 4# All rights reserved. 5# 6# BSD license 7# 8# Redistribution and use in source and binary forms, with or without modification, 9# are permitted provided that the following conditions are met: 10# 11# * Redistributions of source code must retain the above copyright notice, this 12# list of conditions and the following disclaimer. 13# 14# * Redistributions in binary form must reproduce the above copyright notice, this 15# list of conditions and the following disclaimer in the documentation and/or 16# other materials provided with the distribution. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28# 29# You can contact the author at : 30# - zstd homepage : https://facebook.github.io/zstd/ 31# ################################################################ 32 33project(tests) 34 35# name: Cache variable name. The value is expected to be a semicolon-separated 36# list of command line flags 37# default_value: Value to initialize the option with. Can be space separated. 38function(AddTestFlagsOption name default_value doc) 39 string(STRIP "${default_value}" default_value) 40 string(REGEX REPLACE " +" ";" default_value "${default_value}") 41 set(${name} ${default_value} CACHE STRING "${doc}") 42 mark_as_advanced(${name}) 43endfunction() 44 45set(CMAKE_INCLUDE_CURRENT_DIR TRUE) 46 47# Define programs directory, where sources and header files are located 48set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib) 49set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs) 50set(TESTS_DIR ${ZSTD_SOURCE_DIR}/tests) 51include_directories(${TESTS_DIR} ${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${LIBRARY_DIR}/compress ${LIBRARY_DIR}/dictBuilder) 52 53add_executable(datagen ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/lorem.c ${TESTS_DIR}/loremOut.c ${TESTS_DIR}/datagencli.c) 54target_link_libraries(datagen libzstd_static) 55 56# 57# fullbench 58# 59add_executable(fullbench ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/lorem.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${TESTS_DIR}/fullbench.c) 60if (NOT MSVC) 61 target_compile_options(fullbench PRIVATE "-Wno-deprecated-declarations") 62endif() 63target_link_libraries(fullbench libzstd_static) 64add_test(NAME fullbench COMMAND "$<TARGET_FILE:fullbench>" ${ZSTD_FULLBENCH_FLAGS}) 65 66# 67# fuzzer 68# 69add_executable(fuzzer ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/fuzzer.c) 70if (NOT MSVC) 71 target_compile_options(fuzzer PRIVATE "-Wno-deprecated-declarations") 72endif() 73target_link_libraries(fuzzer libzstd_static) 74AddTestFlagsOption(ZSTD_FUZZER_FLAGS "$ENV{FUZZERTEST} $ENV{FUZZER_FLAGS}" 75 "Semicolon-separated list of flags to pass to the fuzzer test (see `fuzzer -h` for usage)") 76add_test(NAME fuzzer COMMAND "$<TARGET_FILE:fuzzer>" ${ZSTD_FUZZER_FLAGS}) 77# Disable the timeout since the run time is too long for the default timeout of 78# 1500 seconds and varies considerably between low-end and high-end CPUs. 79# set_tests_properties(fuzzer PROPERTIES TIMEOUT 0) 80 81# 82# zstreamtest 83# 84add_executable(zstreamtest ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/seqgen.c ${TESTS_DIR}/zstreamtest.c ${TESTS_DIR}/external_matchfinder.c) 85if (NOT MSVC) 86 target_compile_options(zstreamtest PRIVATE "-Wno-deprecated-declarations") 87endif() 88target_link_libraries(zstreamtest libzstd_static) 89AddTestFlagsOption(ZSTD_ZSTREAM_FLAGS "$ENV{ZSTREAM_TESTTIME} $ENV{FUZZER_FLAGS}" 90 "Semicolon-separated list of flags to pass to the zstreamtest test (see `zstreamtest -h` for usage)") 91add_test(NAME zstreamtest COMMAND "$<TARGET_FILE:zstreamtest>" ${ZSTD_ZSTREAM_FLAGS}) 92 93# 94# playTests.sh 95# 96AddTestFlagsOption(ZSTD_PLAYTESTS_FLAGS "$ENV{PLAYTESTS_FLAGS}" 97 "Semicolon-separated list of flags to pass to the playTests.sh test") 98add_test(NAME playTests COMMAND sh -c "\"${TESTS_DIR}/playTests.sh\" ${ZSTD_PLAYTESTS_FLAGS}") 99find_program(UNAME uname) # Run script only in unix shell environments 100if (ZSTD_BUILD_PROGRAMS AND UNAME) 101 set_property(TEST playTests APPEND PROPERTY ENVIRONMENT 102 "ZSTD_BIN=$<TARGET_FILE:zstd>" 103 "DATAGEN_BIN=$<TARGET_FILE:datagen>" 104 ) 105else() 106 message(STATUS "Disabling playTests.sh test because requirements not met") 107 set_tests_properties(playTests PROPERTIES DISABLED YES) 108endif() 109 110# Label the "Medium" set of tests (see TESTING.md) 111set_property(TEST fuzzer zstreamtest playTests APPEND PROPERTY LABELS Medium) 112 113add_executable(paramgrill ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/lorem.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/paramgrill.c) 114if (UNIX) 115 target_link_libraries(paramgrill libzstd_static m) #m is math library 116else() 117 target_link_libraries(paramgrill libzstd_static) 118endif () 119