4 # Custom format class for static analyzer tests
5 class AnalyzerTest(lit
.formats
.ShTest
):
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
11 def execute(self
, test
, litConfig
):
14 # Parse any test requirements ('REQUIRES: ')
16 lit
.TestRunner
.parseIntegratedTestScript(test
)
18 if 'z3' not in test
.requires
:
19 results
.append(self
.executeWithAnalyzeSubstitution(
20 saved_test
, litConfig
, '-analyzer-constraints=range'))
22 if results
[-1].code
== lit
.Test
.FAIL
:
25 # If z3 backend available, add an additional run line for it
26 if self
.use_z3_solver
== '1':
27 assert(test
.config
.clang_staticanalyzer_z3
== '1')
28 results
.append(self
.executeWithAnalyzeSubstitution(
29 saved_test
, litConfig
, '-analyzer-constraints=z3 -DANALYZER_CM_Z3'))
31 # Combine all result outputs into the last element
34 results
[-1].output
= x
.output
+ results
[-1].output
38 return lit
.Test
.Result(lit
.Test
.UNSUPPORTED
,
39 "Test requires the following unavailable features: z3")
41 def executeWithAnalyzeSubstitution(self
, test
, litConfig
, substitution
):
42 saved_substitutions
= list(test
.config
.substitutions
)
43 test
.config
.substitutions
.append(('%analyze', substitution
))
44 result
= lit
.TestRunner
.executeShTest(test
, litConfig
,
45 self
.execute_external
)
46 test
.config
.substitutions
= saved_substitutions