Home | History | Annotate | Download | only in test
      1 # Copyright (c) 2015-2016 The Khronos Group Inc.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #     http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 
     15 # Add a SPIR-V Tools unit test. Signature:
     16 #   add_spvtools_unittest(
     17 #     TARGET target_name
     18 #     SRCS   src_file.h src_file.cpp
     19 #     LIBS   lib1 lib2
     20 #   )
     21 
     22 if (NOT "${SPIRV_SKIP_TESTS}")
     23   if (TARGET gmock_main)
     24     message(STATUS "Found Google Mock, building tests.")
     25   else()
     26     message(STATUS "Did not find googletest, tests will not be built. "
     27       "To enable tests place googletest in '<spirv-dir>/external/googletest'.")
     28   endif()
     29 endif()
     30 
     31 function(add_spvtools_unittest)
     32   if (NOT "${SPIRV_SKIP_TESTS}" AND TARGET gmock_main)
     33     set(one_value_args TARGET PCH_FILE)
     34     set(multi_value_args SRCS LIBS ENVIRONMENT)
     35     cmake_parse_arguments(
     36       ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN})
     37     set(target test_${ARG_TARGET})
     38     set(SRC_COPY ${ARG_SRCS})
     39     if (DEFINED ARG_PCH_FILE)
     40       spvtools_pch(SRC_COPY ${ARG_PCH_FILE})
     41     endif()
     42     add_executable(${target} ${SRC_COPY})
     43     spvtools_default_compile_options(${target})
     44     if(${COMPILER_IS_LIKE_GNU})
     45       target_compile_options(${target} PRIVATE -Wno-undef)
     46       # Effcee and RE2 headers exhibit shadowing.
     47       target_compile_options(${target} PRIVATE -Wno-shadow)
     48     endif()
     49     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
     50       # Disable C4503 "decorated name length exceeded" warning,
     51       # triggered by some heavily templated types.
     52       # We don't care much about that in test code.
     53       # Important to do since we have warnings-as-errors.
     54       target_compile_options(${target} PRIVATE /wd4503)
     55       # Googletest accidentally turns off support for ::testing::Combine
     56       # in VS 2017.  See https://github.com/google/googletest/issues/1352
     57       # Forcibly turn it on again.
     58       target_compile_options(${target} PRIVATE /DGTEST_HAS_COMBINE=1)
     59     endif()
     60     target_include_directories(${target} PRIVATE
     61       ${SPIRV_HEADER_INCLUDE_DIR}
     62       ${spirv-tools_SOURCE_DIR}
     63       ${spirv-tools_SOURCE_DIR}/include
     64       ${spirv-tools_SOURCE_DIR}/test
     65       ${spirv-tools_BINARY_DIR}
     66       ${gtest_SOURCE_DIR}/include
     67       ${gmock_SOURCE_DIR}/include
     68     )
     69     if (TARGET effcee)
     70       # If using Effcee for testing, then add its include directory.
     71       target_include_directories(${target} PRIVATE ${effcee_SOURCE_DIR})
     72     endif()
     73     target_link_libraries(${target} PRIVATE ${ARG_LIBS})
     74     if (TARGET effcee)
     75       target_link_libraries(${target} PRIVATE effcee)
     76     endif()
     77     target_link_libraries(${target} PRIVATE gmock_main)
     78     add_test(NAME spirv-tools-${target} COMMAND ${target})
     79     if (DEFINED ARG_ENVIRONMENT)
     80       set_tests_properties(spirv-tools-${target} PROPERTIES ENVIRONMENT ${ARG_ENVIRONMENT})
     81     endif()
     82     set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests")
     83   endif()
     84 endfunction()
     85 
     86 set(TEST_SOURCES
     87   test_fixture.h
     88   unit_spirv.h
     89 
     90   assembly_context_test.cpp
     91   assembly_format_test.cpp
     92   binary_destroy_test.cpp
     93   binary_endianness_test.cpp
     94   binary_header_get_test.cpp
     95   binary_parse_test.cpp
     96   binary_strnlen_s_test.cpp
     97   binary_to_text_test.cpp
     98   binary_to_text.literal_test.cpp
     99   comment_test.cpp
    100   diagnostic_test.cpp
    101   enum_string_mapping_test.cpp
    102   enum_set_test.cpp
    103   ext_inst.debuginfo_test.cpp
    104   ext_inst.glsl_test.cpp
    105   ext_inst.opencl_test.cpp
    106   fix_word_test.cpp
    107   generator_magic_number_test.cpp
    108   hex_float_test.cpp
    109   immediate_int_test.cpp
    110   libspirv_macros_test.cpp
    111   log_test.cpp
    112   named_id_test.cpp
    113   name_mapper_test.cpp
    114   opcode_make_test.cpp
    115   opcode_require_capabilities_test.cpp
    116   opcode_split_test.cpp
    117   opcode_table_get_test.cpp
    118   operand_capabilities_test.cpp
    119   operand_test.cpp
    120   operand_pattern_test.cpp
    121   parse_number_test.cpp
    122   preserve_numeric_ids_test.cpp
    123   software_version_test.cpp
    124   string_utils_test.cpp
    125   target_env_test.cpp
    126   text_advance_test.cpp
    127   text_destroy_test.cpp
    128   text_literal_test.cpp
    129   text_start_new_inst_test.cpp
    130   text_to_binary.annotation_test.cpp
    131   text_to_binary.barrier_test.cpp
    132   text_to_binary.constant_test.cpp
    133   text_to_binary.control_flow_test.cpp
    134   text_to_binary_test.cpp
    135   text_to_binary.debug_test.cpp
    136   text_to_binary.device_side_enqueue_test.cpp
    137   text_to_binary.extension_test.cpp
    138   text_to_binary.function_test.cpp
    139   text_to_binary.group_test.cpp
    140   text_to_binary.image_test.cpp
    141   text_to_binary.literal_test.cpp
    142   text_to_binary.memory_test.cpp
    143   text_to_binary.misc_test.cpp
    144   text_to_binary.mode_setting_test.cpp
    145   text_to_binary.pipe_storage_test.cpp
    146   text_to_binary.type_declaration_test.cpp
    147   text_to_binary.subgroup_dispatch_test.cpp
    148   text_to_binary.reserved_sampling_test.cpp
    149   text_word_get_test.cpp
    150 
    151   unit_spirv.cpp
    152 )
    153 
    154 spvtools_pch(TEST_SOURCES pch_test)
    155 
    156 add_spvtools_unittest(
    157   TARGET spirv_unit_tests
    158   SRCS ${TEST_SOURCES}
    159   LIBS ${SPIRV_TOOLS})
    160 
    161 add_spvtools_unittest(
    162   TARGET c_interface
    163   SRCS c_interface_test.cpp
    164   LIBS ${SPIRV_TOOLS})
    165 
    166 add_spvtools_unittest(
    167   TARGET c_interface_shared
    168   SRCS c_interface_test.cpp
    169   LIBS ${SPIRV_TOOLS}-shared
    170   ENVIRONMENT PATH=$<TARGET_FILE_DIR:${SPIRV_TOOLS}-shared>)
    171 
    172 add_spvtools_unittest(
    173   TARGET cpp_interface
    174   SRCS cpp_interface_test.cpp
    175   LIBS SPIRV-Tools-opt)
    176 
    177 if (${SPIRV_TIMER_ENABLED})
    178 add_spvtools_unittest(
    179   TARGET timer
    180   SRCS timer_test.cpp
    181   LIBS ${SPIRV_TOOLS})
    182 endif()
    183 
    184 
    185 add_spvtools_unittest(
    186   TARGET bit_stream
    187   SRCS bit_stream.cpp
    188       ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.cpp
    189       ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.h
    190   LIBS ${SPIRV_TOOLS})
    191 
    192 add_spvtools_unittest(
    193   TARGET huffman_codec
    194   SRCS huffman_codec.cpp
    195       ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.cpp
    196       ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.h
    197       ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/huffman_codec.h
    198   LIBS ${SPIRV_TOOLS})
    199 
    200 add_spvtools_unittest(
    201   TARGET move_to_front
    202   SRCS move_to_front_test.cpp
    203     ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/move_to_front.h
    204     ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/move_to_front.cpp
    205   LIBS ${SPIRV_TOOLS})
    206 
    207 add_subdirectory(comp)
    208 add_subdirectory(link)
    209 add_subdirectory(opt)
    210 add_subdirectory(reduce)
    211 add_subdirectory(stats)
    212 add_subdirectory(tools)
    213 add_subdirectory(util)
    214 add_subdirectory(val)
    215