Skip to content

Commit 2997a30

Browse files
author
George Karpenkov
committed
[analyzer] [NFC] Introduce separate targets for testing the analyzer: check-clang-analyzer and check-clang-analyzer-z3
Current testing setup for analyzer tests with Z3 is rather inconvenient: There's no way to run the analyzer tests separately (I use LIT_FILTER=Analysis ninja check-clang, but a direct target is nicer). When Clang is built with Z3 support, there's no way to *not* run tests with Z3 solver, and this is often desired, as tests with Z3 solver take a very long time. This patch introduces two extra targets: - check-clang-analyzer - check-clang-analyzer-z3 which solve those problems. Differential Revision: https://reviews.llvm.org/D50594 llvm-svn: 339629
1 parent 97ea485 commit 2997a30

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

clang/test/Analysis/analyzer_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# Custom format class for static analyzer tests
55
class AnalyzerTest(lit.formats.ShTest):
66

7+
def __init__(self, execute_external, use_z3_solver=False):
8+
super(AnalyzerTest, self).__init__(execute_external)
9+
self.use_z3_solver = use_z3_solver
10+
711
def execute(self, test, litConfig):
812
results = []
913

@@ -19,7 +23,8 @@ def execute(self, test, litConfig):
1923
return results[-1]
2024

2125
# If z3 backend available, add an additional run line for it
22-
if test.config.clang_staticanalyzer_z3 == '1':
26+
if self.use_z3_solver == '1':
27+
assert(test.config.clang_staticanalyzer_z3 == '1')
2328
results.append(self.executeWithAnalyzeSubstitution(
2429
saved_test, litConfig, '-analyzer-constraints=z3 -DANALYZER_CM_Z3'))
2530

clang/test/Analysis/lit.local.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import site
77
site.addsitedir(os.path.dirname(__file__))
88
import analyzer_test
99
config.test_format = analyzer_test.AnalyzerTest(
10-
config.test_format.execute_external)
10+
config.test_format.execute_external, config.use_z3_solver)
1111

1212
if not config.root.clang_staticanalyzer:
1313
config.unsupported = True

clang/test/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,15 @@ endif ()
8888

8989
set(CLANG_TEST_PARAMS
9090
clang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
91+
USE_Z3_SOLVER=0
9192
)
9293

94+
set(ANALYZER_TEST_PARAMS
95+
USE_Z3_SOLVER=0)
96+
97+
set(ANALYZER_TEST_PARAMS_Z3
98+
USE_Z3_SOLVER=1)
99+
93100
if( NOT CLANG_BUILT_STANDALONE )
94101
list(APPEND CLANG_TEST_DEPS
95102
llvm-config
@@ -126,6 +133,24 @@ add_lit_testsuite(check-clang "Running the Clang regression tests"
126133
)
127134
set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")
128135

136+
if (CLANG_ENABLE_STATIC_ANALYZER)
137+
add_lit_testsuite(check-clang-analyzer "Running the Clang analyzer tests"
138+
${CMAKE_CURRENT_BINARY_DIR}/Analysis
139+
PARAMS ${ANALYZER_TEST_PARAMS}
140+
DEPENDS ${CLANG_TEST_DEPS})
141+
set_target_properties(check-clang-analyzer PROPERTIES FOLDER "Clang tests")
142+
143+
144+
if (CLANG_ANALYZER_WITH_Z3)
145+
add_lit_testsuite(check-clang-analyzer-z3 "Running the Clang analyzer tests, using Z3 as a solver"
146+
${CMAKE_CURRENT_BINARY_DIR}/Analysis
147+
PARAMS ${ANALYZER_TEST_PARAMS_Z3}
148+
DEPENDS ${CLANG_TEST_DEPS})
149+
set_target_properties(check-clang-analyzer-z3 PROPERTIES FOLDER "Clang tests")
150+
endif()
151+
152+
endif()
153+
129154
add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR}
130155
PARAMS ${CLANG_TEST_PARAMS}
131156
DEPENDS ${CLANG_TEST_DEPS}

clang/test/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ config.enable_shared = @ENABLE_SHARED@
2626
config.enable_backtrace = @ENABLE_BACKTRACES@
2727
config.host_arch = "@HOST_ARCH@"
2828
config.python_executable = "@PYTHON_EXECUTABLE@"
29+
config.use_z3_solver = "@USE_Z3_SOLVER@"
2930

3031
# Support substitution of the tools and libs dirs with user parameters. This is
3132
# used when we can't determine the tool dir at configuration time.
@@ -34,6 +35,7 @@ try:
3435
config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
3536
config.llvm_shlib_dir = config.llvm_shlib_dir % lit_config.params
3637
config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params
38+
config.use_z3_solver = lit_config.params['USE_Z3_SOLVER']
3739
except KeyError:
3840
e = sys.exc_info()[1]
3941
key, = e.args

0 commit comments

Comments
 (0)