• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Tint Authors.
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
15function(add_tint_ast_fuzzer NAME)
16  add_executable(${NAME} ${NAME}.cc ${AST_FUZZER_SOURCES})
17  target_link_libraries(${NAME} libtint-fuzz libtint_ast_fuzzer)
18  tint_default_compile_options(${NAME})
19  target_compile_definitions(${NAME} PRIVATE CUSTOM_MUTATOR)
20  target_include_directories(${NAME} PRIVATE ${CMAKE_BINARY_DIR})
21endfunction()
22
23set(PROTOBUF_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/protobufs/tint_ast_fuzzer.proto)
24
25file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/protobufs)
26
27add_custom_command(
28        OUTPUT
29        ${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.cc
30        ${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.h
31        COMMAND
32        "protobuf::protoc" -I=${CMAKE_CURRENT_SOURCE_DIR}/protobufs
33        --cpp_out=${CMAKE_CURRENT_BINARY_DIR}/protobufs ${PROTOBUF_SOURCES}
34        DEPENDS ${PROTOBUF_SOURCES}
35        COMMENT "Generate protobuf sources from proto definition file.")
36
37set(LIBTINT_AST_FUZZER_SOURCES
38        ../mersenne_twister_engine.h
39        ../random_generator.h
40        ../random_generator_engine.h
41        mutation.h
42        mutation_finder.h
43        mutation_finders/replace_identifiers.h
44        mutations/replace_identifier.h
45        mutator.h
46        node_id_map.h
47        probability_context.h
48        protobufs/tint_ast_fuzzer.h
49        util.h
50        ${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.h)
51
52set(LIBTINT_AST_FUZZER_SOURCES ${LIBTINT_AST_FUZZER_SOURCES}
53        ../mersenne_twister_engine.cc
54        ../random_generator.cc
55        ../random_generator_engine.cc
56        mutation.cc
57        mutation_finder.cc
58        mutation_finders/replace_identifiers.cc
59        mutations/replace_identifier.cc
60        mutator.cc
61        node_id_map.cc
62        probability_context.cc
63        ${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.cc)
64
65set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/protobufs/tint_ast_fuzzer.pb.cc PROPERTIES COMPILE_FLAGS -w)
66
67# Add static library target.
68add_library(libtint_ast_fuzzer STATIC ${LIBTINT_AST_FUZZER_SOURCES})
69target_link_libraries(libtint_ast_fuzzer protobuf::libprotobuf libtint)
70tint_default_compile_options(libtint_ast_fuzzer)
71target_include_directories(libtint_ast_fuzzer PRIVATE ${CMAKE_BINARY_DIR})
72
73set(AST_FUZZER_SOURCES
74        cli.cc
75        cli.h
76        fuzzer.cc
77        override_cli_params.h
78        ../tint_common_fuzzer.cc
79        ../tint_common_fuzzer.h)
80
81set_source_files_properties(fuzzer.cc PROPERTIES COMPILE_FLAGS -Wno-missing-prototypes)
82
83# Add libfuzzer targets.
84# Targets back-ends according to command line arguments.
85add_tint_ast_fuzzer(tint_ast_fuzzer)
86# Targets back-ends individually.
87add_tint_ast_fuzzer(tint_ast_hlsl_writer_fuzzer)
88add_tint_ast_fuzzer(tint_ast_msl_writer_fuzzer)
89add_tint_ast_fuzzer(tint_ast_spv_writer_fuzzer)
90add_tint_ast_fuzzer(tint_ast_wgsl_writer_fuzzer)
91
92# Add tests.
93if (${TINT_BUILD_TESTS})
94    set(TEST_SOURCES
95            mutations/replace_identifier_test.cc)
96
97    add_executable(tint_ast_fuzzer_unittests ${TEST_SOURCES})
98
99    target_include_directories(
100            tint_ast_fuzzer_unittests PRIVATE ${gmock_SOURCE_DIR}/include)
101    target_link_libraries(tint_ast_fuzzer_unittests gmock_main libtint_ast_fuzzer)
102    tint_default_compile_options(tint_ast_fuzzer_unittests)
103    target_compile_options(tint_ast_fuzzer_unittests PRIVATE
104            -Wno-global-constructors
105            -Wno-weak-vtables
106            -Wno-covered-switch-default)
107
108    target_include_directories(tint_ast_fuzzer_unittests PRIVATE ${CMAKE_BINARY_DIR})
109
110    add_test(NAME tint_ast_fuzzer_unittests COMMAND tint_ast_fuzzer_unittests)
111endif ()
112