4 # Custom format class for static analyzer tests
5 class AnalyzerTest(lit
.formats
.ShTest
):
6 def __init__(self
, execute_external
, use_z3_solver
=False):
7 super(AnalyzerTest
, self
).__init
__(execute_external
)
8 self
.use_z3_solver
= use_z3_solver
10 def execute(self
, test
, litConfig
):
13 # Parse any test requirements ('REQUIRES: ')
15 lit
.TestRunner
.parseIntegratedTestScript(test
)
17 if "z3" not in test
.requires
:
19 self
.executeWithAnalyzeSubstitution(
20 saved_test
, litConfig
, "-analyzer-constraints=range"
24 if results
[-1].code
== lit
.Test
.FAIL
:
27 # If z3 backend available, add an additional run line for it
28 if self
.use_z3_solver
== "1":
29 assert test
.config
.clang_staticanalyzer_z3
== "1"
31 self
.executeWithAnalyzeSubstitution(
32 saved_test
, litConfig
, "-analyzer-constraints=z3 -DANALYZER_CM_Z3"
36 # Combine all result outputs into the last element
39 results
[-1].output
= x
.output
+ results
[-1].output
43 return lit
.Test
.Result(
44 lit
.Test
.UNSUPPORTED
, "Test requires the following unavailable features: z3"
47 def executeWithAnalyzeSubstitution(self
, test
, litConfig
, substitution
):
48 saved_substitutions
= list(test
.config
.substitutions
)
49 test
.config
.substitutions
.append(("%analyze", substitution
))
50 result
= lit
.TestRunner
.executeShTest(test
, litConfig
, self
.execute_external
)
51 test
.config
.substitutions
= saved_substitutions