forked from p4gauntlet/toz3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
291 lines (249 loc) · 9.25 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# Makefile for the toZ3
# sources for toZ3
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/version.h.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/version.h" @ONLY
)
OPTION (ENABLE_GAUNTLET_PRUNER "Build the Gauntlet Pruner." OFF)
set(
TOZ3V2_COMMON_SRCS
common/create_z3.cpp
common/state.cpp
common/type_simple.cpp
common/type_table.cpp
common/type_complex.cpp
common/visitor_interpret.cpp
common/visitor_specialize.cpp
common/parser.cpp
common/expressions.cpp
common/operands.cpp
common/util.cpp
)
set(
TOZ3V2_COMMON_HDRS
common/create_z3.h
common/scope.h
common/state.h
common/type_base.h
common/type_simple.h
common/type_complex.h
common/visitor_interpret.h
common/visitor_specialize.h
common/util.h
)
set(
TOZ3V2_INTERPRET_SRCS
interpret/main.cpp
interpret/options.cpp
)
set(
TOZ3V2_INTERPRET_HDRS
interpret/options.h
)
set(
TOZ3V2_COMPARE_SRCS
compare/compare.cpp
compare/options.cpp
compare/main.cpp
)
set(
TOZ3V2_COMPARE_HDRS
compare/compare.h
compare/options.h
)
set(
TOZ3V2_VALIDATE_SRCS
compare/compare.cpp
validate/options.cpp
validate/main.cpp
)
set(
TOZ3V2_VALIDATE_HDRS
validate/options.h
)
file(
GLOB_RECURSE TOZ3_LINT_LIST FOLLOW_SYMLINKS
common/*.cpp
common/*.h
compare/*.cpp
compare/*.h
interpret/*.cpp
interpret/*.h
pruner/*.cpp
pruner/*.h
validate/*.cpp
validate/*.h
)
# Filter some folders from the CI checks.
list(FILTER TOZ3_LINT_LIST EXCLUDE REGEX "pruner/src/contrib")
add_clang_format_files(${P4C_SOURCE_DIR} "${TOZ3_LINT_LIST}")
add_cpplint_files(${P4C_SOURCE_DIR} "${TOZ3_LINT_LIST}")
# Enable clang-tidy to force consistent code style across the project.
# See also: https://gitlab.kitware.com/cmake/cmake/-/issues/18926
option(CMAKE_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
if(CMAKE_RUN_CLANG_TIDY)
message(STATUS "Enabling clang-tidy checks.")
message(STATUS "Exporting compile commands for clang-tidy.")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
message(FATAL_ERROR "CMAKE_RUN_CLANG_TIDY requires an out-of-source build!")
endif()
set(CLANG_TIDY_COMMAND "${PROJECT_SOURCE_DIR}/scripts/tools/clang-tidy")
execute_process(
COMMAND ${CLANG_TIDY_COMMAND} --version
OUTPUT_VARIABLE clang_tidy_ver
)
message(STATUS "clang-tidy: ${clang_tidy_ver}")
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
# Create a preprocessor definition that depends on .clang-tidy content so
# the compile command will change when .clang-tidy changes. This ensures
# that a subsequent build re-runs clang-tidy on all sources even if they
# do not otherwise need to be recompiled. Nothing actually uses this
# definition. We add it to targets on which we run clang-tidy just to
# get the build dependency on the .clang-tidy file.
file(SHA1 ${CMAKE_CURRENT_LIST_DIR}/.clang-tidy clang_tidy_sha1)
set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
unset(clang_tidy_sha1)
endif()
add_library(p4toz3lib ${TOZ3V2_COMMON_SRCS})
# add the Z3 includes
target_include_directories(p4toz3lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/contrib/z3)
target_link_libraries(
p4toz3lib ${P4C_LIBRARIES} ${P4C_LIB_DEPS}
${CMAKE_CURRENT_SOURCE_DIR}/contrib/z3/libz3.a
)
add_dependencies(p4toz3lib genIR frontend)
add_executable(p4toz3 ${TOZ3V2_INTERPRET_SRCS})
target_link_libraries(p4toz3 p4toz3lib)
install(TARGETS p4toz3 RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
add_executable(p4compare ${TOZ3V2_COMPARE_SRCS})
target_link_libraries(p4compare p4toz3lib)
install(TARGETS p4compare RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
add_executable(p4validate ${TOZ3V2_VALIDATE_SRCS})
target_link_libraries(p4validate p4toz3lib)
install(TARGETS p4validate RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
add_custom_target(
linkp4toz3
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/p4toz3 ${P4C_BINARY_DIR}/p4toz3
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/p4compare ${P4C_BINARY_DIR}/p4compare
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/p4validate ${P4C_BINARY_DIR}/p4validate
COMMAND ${CMAKE_COMMAND} -E create_symlink ${P4C_BINARY_DIR}/p4include ${CMAKE_CURRENT_BINARY_DIR}/p4include
COMMAND ${CMAKE_COMMAND} -E create_symlink ${P4C_BINARY_DIR}/p4_14include ${CMAKE_CURRENT_BINARY_DIR}/p4_14include
)
add_dependencies(p4c_driver linkp4toz3)
# Test configuration
set(P4C_TEST_DIR "${CMAKE_SOURCE_DIR}/testdata/p4_16_samples")
set(TOZ3_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests")
set(VALIDATION_BIN "${CMAKE_BINARY_DIR}/p4validate")
set(COMPARE_BIN "${CMAKE_BINARY_DIR}/p4compare")
set(COMPILER_BIN "${CMAKE_BINARY_DIR}/p4test")
set(VALIDATION_DRIVER "${CMAKE_CURRENT_SOURCE_DIR}/tools/run_validation_test.py")
################# P4C TESTS #################
file(GLOB P4C_VALIDATION_TESTS "${P4C_TEST_DIR}/*.p4")
# These tests need to be added manually
set(
MANUAL_VALIDATION_TESTS
${P4C_TEST_DIR}/fabric_20190420/fabric.p4
)
set(P4C_VALIDATION_TESTS "${P4C_VALIDATION_TESTS};${MANUAL_VALIDATION_TESTS}")
set(P4C_VALIDATION_XFAIL_TESTS)
# These tests need to be remove because they have spurious behavior (timeouts).
set(
SKIPPED_TESTS
# Spurious timeouts.
${P4C_TEST_DIR}/lpm_ubpf.p4
# Unreliable test.
${P4C_TEST_DIR}/pna-issue3041.p4
# Crashes.
${P4C_TEST_DIR}/bit0-bmv2.p4
${P4C_TEST_DIR}/bool_to_bit_cast.p4
${P4C_TEST_DIR}/enumCast.p4
${P4C_TEST_DIR}/issue1208-1.p4
${P4C_TEST_DIR}/issue1334.p4
${P4C_TEST_DIR}/issue1717.p4
${P4C_TEST_DIR}/issue3001-1.p4
${P4C_TEST_DIR}/issue3001.p4
${P4C_TEST_DIR}/issue3051.p4
${P4C_TEST_DIR}/minsize.p4
${P4C_TEST_DIR}/parser-unroll-test1.p4
${P4C_TEST_DIR}/parser-unroll-test2.p4
${P4C_TEST_DIR}/parser-unroll-test3.p4
${P4C_TEST_DIR}/parser-unroll-test4.p4
${P4C_TEST_DIR}/issue2800a.p4
${P4C_TEST_DIR}/issue2800b.p4
${P4C_TEST_DIR}/issue2800c.p4
${P4C_TEST_DIR}/issue2800d.p4
${P4C_TEST_DIR}/issue3091-1.p4
${P4C_TEST_DIR}/issue3091.p4
${P4C_TEST_DIR}/issue1914.p4
${P4C_TEST_DIR}/issue1914-1.p4
${P4C_TEST_DIR}/issue1914-2.p4
${P4C_TEST_DIR}/pna-direction-main-parser-err.p4
${P4C_TEST_DIR}/pna-direction.p4
${P4C_TEST_DIR}/pna-example-mirror-packet-error3.p4
${P4C_TEST_DIR}/issue3283.p4
${P4C_TEST_DIR}/issue3374.p4
${P4C_TEST_DIR}/pna-elim-hdr-copy-dpdk.p4
${P4C_TEST_DIR}/pna-example-varIndex.p4
${P4C_TEST_DIR}/pna-too-big-label-name-dpdk.p4
${P4C_TEST_DIR}/invalid-header.p4
${P4C_TEST_DIR}/issue3616.p4
${P4C_TEST_DIR}/methodArgs.p4
${P4C_TEST_DIR}/issue3779.p4
${P4C_TEST_DIR}/default-initializer.p4
${P4C_TEST_DIR}/invalid-union.p4
${P4C_TEST_DIR}/stack-init.p4
${P4C_TEST_DIR}/issue4057.p4
${P4C_TEST_DIR}/pna-dpdk-header-stack-assignment.p4
)
if(SKIPPED_TESTS)
list(REMOVE_ITEM P4C_VALIDATION_TESTS ${SKIPPED_TESTS})
endif()
set(VALIDATION_FLAGS "--validation-bin ${VALIDATION_BIN} --compiler-bin ${COMPILER_BIN} --build-dir ${CMAKE_BINARY_DIR}")
if(VALIDATION_IGNORE_CRASHES)
set(VALIDATION_FLAGS "${VALIDATION_FLAGS} --ignore-crashes")
endif()
p4c_add_tests("toz3-validate-p4c" ${VALIDATION_DRIVER} "${P4C_VALIDATION_TESTS}" "${P4C_VALIDATION_XFAIL_TESTS}" "${VALIDATION_FLAGS}")
################# CUSTOM TESTS #################
file(GLOB VALIDATION_FRIENDS_TESTS "${TOZ3_TEST_DIR}/false_friends/*.p4")
set(VALIDATION_FRIENDS_XFAIL_TESTS)
# These tests need to be remove because they have spurious behavior (timeouts).
set(SKIPPED_TESTS)
if(SKIPPED_TESTS)
list(REMOVE_ITEM VALIDATION_FRIENDS_TESTS ${SKIPPED_TESTS})
endif()
set(VALIDATION_FRIENDS_FLAGS "--validation-bin ${VALIDATION_BIN} --compiler-bin ${COMPILER_BIN} --build-dir ${CMAKE_BINARY_DIR}")
if(VALIDATION_IGNORE_CRASHES)
set(VALIDATION_FRIENDS_FLAGS "${VALIDATION_FRIENDS_FLAGS} --ignore-crashes")
endif()
p4c_add_tests("toz3-validate-friends" ${VALIDATION_DRIVER} "${VALIDATION_FRIENDS_TESTS}" "${P4C_VALIDATION_XFAIL_TESTS}" "${VALIDATION_FLAGS}")
################# VIOLATION TESTS #################
file(GLOB VIOLATION_TESTS LIST_DIRECTORIES true "${TOZ3_TEST_DIR}/violated/*")
set(
VIOLATION_XFAIL_TESTS
extensions/toz3/tests/violated/2314_regression
extensions/toz3/tests/violated/parser_loop
# Fails because the parser is disabled.
extensions/toz3/tests/violated/2591_regression
)
set(VIOLATION_FLAGS "--validation-bin ${COMPARE_BIN} --compiler-bin ${COMPILER_BIN} --build-dir ${CMAKE_BINARY_DIR} --check-violation")
if(VALIDATION_IGNORE_CRASHES)
set(VIOLATION_FLAGS "${VIOLATION_FLAGS} --ignore-crashes")
endif()
p4c_add_tests("toz3-validate-violation" ${VALIDATION_DRIVER} "${VIOLATION_TESTS}" "${VIOLATION_XFAIL_TESTS}" "${VIOLATION_FLAGS}")
################# UNDEFINED TESTS #################
file(GLOB UNDEFINED_TESTS LIST_DIRECTORIES true "${TOZ3_TEST_DIR}/undef_violated/*")
set(
UNDEFINED_XFAIL_TESTS
extensions/toz3/tests/undef_violated/NestedStructs_1
extensions/toz3/tests/undef_violated/NestedStructs_2
)
set(UNDEFINED_FLAGS "--validation-bin ${COMPARE_BIN} --compiler-bin ${COMPILER_BIN} --build-dir ${CMAKE_BINARY_DIR} --check-undefined")
if(VALIDATION_IGNORE_CRASHES)
set(UNDEFINED_FLAGS "${UNDEFINED_FLAGS} --ignore-crashes")
endif()
p4c_add_tests("toz3-validate-undefined" ${VALIDATION_DRIVER} "${UNDEFINED_TESTS}" "${UNDEFINED_XFAIL_TESTS}" "${UNDEFINED_FLAGS}")
# This also builds the pruner module
if(ENABLE_GAUNTLET_PRUNER)
add_subdirectory(pruner)
endif()