2017-04-06 02:56:48 +08:00
|
|
|
import lit.formats
|
|
|
|
import lit.TestRunner
|
|
|
|
|
|
|
|
# Custom format class for static analyzer tests
|
|
|
|
class AnalyzerTest(lit.formats.ShTest):
|
|
|
|
|
|
|
|
def execute(self, test, litConfig):
|
2017-06-16 01:05:07 +08:00
|
|
|
results = []
|
2017-04-06 02:56:48 +08:00
|
|
|
|
2017-06-16 01:05:07 +08:00
|
|
|
# Parse any test requirements ('REQUIRES: ')
|
2017-07-13 05:43:42 +08:00
|
|
|
saved_test = test
|
2017-06-16 01:05:07 +08:00
|
|
|
lit.TestRunner.parseIntegratedTestScript(test)
|
|
|
|
|
|
|
|
if 'z3' not in test.requires:
|
|
|
|
results.append(self.executeWithAnalyzeSubstitution(
|
2017-07-13 05:43:42 +08:00
|
|
|
saved_test, litConfig, '-analyzer-constraints=range'))
|
2017-06-16 01:05:07 +08:00
|
|
|
|
2017-07-13 05:43:42 +08:00
|
|
|
if results[-1].code == lit.Test.FAIL:
|
2017-06-16 01:05:07 +08:00
|
|
|
return results[-1]
|
2017-04-06 02:56:48 +08:00
|
|
|
|
|
|
|
# If z3 backend available, add an additional run line for it
|
2017-07-13 05:43:42 +08:00
|
|
|
if test.config.clang_staticanalyzer_z3 == '1':
|
2017-06-16 01:05:07 +08:00
|
|
|
results.append(self.executeWithAnalyzeSubstitution(
|
|
|
|
saved_test, litConfig, '-analyzer-constraints=z3 -DANALYZER_CM_Z3'))
|
2017-04-06 02:56:48 +08:00
|
|
|
|
2017-06-16 01:05:07 +08:00
|
|
|
# Combine all result outputs into the last element
|
|
|
|
for x in results:
|
|
|
|
if x != results[-1]:
|
|
|
|
results[-1].output = x.output + results[-1].output
|
|
|
|
|
|
|
|
if results:
|
|
|
|
return results[-1]
|
|
|
|
return lit.Test.Result(lit.Test.UNSUPPORTED,
|
|
|
|
"Test requires the following unavailable features: z3")
|
2017-04-06 02:56:48 +08:00
|
|
|
|
|
|
|
def executeWithAnalyzeSubstitution(self, test, litConfig, substitution):
|
|
|
|
saved_substitutions = list(test.config.substitutions)
|
|
|
|
test.config.substitutions.append(('%analyze', substitution))
|
|
|
|
result = lit.TestRunner.executeShTest(test, litConfig,
|
2017-06-16 01:05:07 +08:00
|
|
|
self.execute_external)
|
2017-04-06 02:56:48 +08:00
|
|
|
test.config.substitutions = saved_substitutions
|
|
|
|
|
|
|
|
return result
|