1 # ################################################################
3 # Copyright (c) Meta Platforms, Inc. and affiliates.
8 # Redistribution and use in source and binary forms, with or without modification,
9 # are permitted provided that the following conditions are met:
11 # * Redistributions of source code must retain the above copyright notice, this
12 # list of conditions and the following disclaimer.
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.
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.
29 # You can contact the author at :
30 # - zstd homepage : https://facebook.github.io/zstd/
31 # ################################################################
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.
38 function(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})
45 set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
47 # Define programs directory, where sources and header files are located
48 set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
49 set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs)
50 set(TESTS_DIR ${ZSTD_SOURCE_DIR}/tests)
51 include_directories(${TESTS_DIR} ${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${LIBRARY_DIR}/compress ${LIBRARY_DIR}/dictBuilder)
53 add_executable(datagen ${PROGRAMS_DIR}/datagen.c ${TESTS_DIR}/datagencli.c)
54 target_link_libraries(datagen libzstd_static)
59 add_executable(fullbench ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${TESTS_DIR}/fullbench.c)
61 target_compile_options(fullbench PRIVATE "-Wno-deprecated-declarations")
63 target_link_libraries(fullbench libzstd_static)
64 add_test(NAME fullbench COMMAND fullbench ${ZSTD_FULLBENCH_FLAGS})
69 add_executable(fuzzer ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/fuzzer.c)
71 target_compile_options(fuzzer PRIVATE "-Wno-deprecated-declarations")
73 target_link_libraries(fuzzer libzstd_static)
74 AddTestFlagsOption(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)")
76 add_test(NAME fuzzer COMMAND 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)
84 add_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)
86 target_compile_options(zstreamtest PRIVATE "-Wno-deprecated-declarations")
88 target_link_libraries(zstreamtest libzstd_static)
89 AddTestFlagsOption(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)")
91 add_test(NAME zstreamtest COMMAND zstreamtest ${ZSTD_ZSTREAM_FLAGS})
96 AddTestFlagsOption(ZSTD_PLAYTESTS_FLAGS "$ENV{PLAYTESTS_FLAGS}"
97 "Semicolon-separated list of flags to pass to the playTests.sh test")
98 add_test(NAME playTests COMMAND sh -c "\"${TESTS_DIR}/playTests.sh\" ${ZSTD_PLAYTESTS_FLAGS}")
99 find_program(UNAME uname) # Run script only in unix shell environments
100 if (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>"
106 message(STATUS "Disabling playTests.sh test because requirements not met")
107 set_tests_properties(playTests PROPERTIES DISABLED YES)
110 # Label the "Medium" set of tests (see TESTING.md)
111 set_property(TEST fuzzer zstreamtest playTests APPEND PROPERTY LABELS Medium)
113 add_executable(paramgrill ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/paramgrill.c)
115 target_link_libraries(paramgrill libzstd_static m) #m is math library
117 target_link_libraries(paramgrill libzstd_static)