blob: 468bb24640d88dec2cd40380dd01410ba2b77f2e [file] [log] [blame]
Dominic Chen35610d22017-07-12 19:37:57 +00001import copy
Reid Kleckner2ae37c12017-04-05 18:56:48 +00002import lit.formats
3import lit.TestRunner
4
5# Custom format class for static analyzer tests
6class AnalyzerTest(lit.formats.ShTest):
7
8 def execute(self, test, litConfig):
Dominic Chenf94c1082017-06-15 17:05:07 +00009 results = []
Reid Kleckner2ae37c12017-04-05 18:56:48 +000010
Dominic Chenf94c1082017-06-15 17:05:07 +000011 # Parse any test requirements ('REQUIRES: ')
Dominic Chen35610d22017-07-12 19:37:57 +000012 saved_test = copy.deepcopy(test)
Dominic Chenf94c1082017-06-15 17:05:07 +000013 lit.TestRunner.parseIntegratedTestScript(test)
14
Dominic Chen35610d22017-07-12 19:37:57 +000015 # If the test does not require z3, drop it from the available features
16 # to satisfy tests that explicitly require !z3
Dominic Chenf94c1082017-06-15 17:05:07 +000017 if 'z3' not in test.requires:
Dominic Chen35610d22017-07-12 19:37:57 +000018 test.config.available_features.discard('z3')
Dominic Chenf94c1082017-06-15 17:05:07 +000019 results.append(self.executeWithAnalyzeSubstitution(
Dominic Chen35610d22017-07-12 19:37:57 +000020 test, litConfig, '-analyzer-constraints=range'))
Dominic Chenf94c1082017-06-15 17:05:07 +000021
Dominic Chen35610d22017-07-12 19:37:57 +000022 if results[-1].code != lit.Test.PASS:
Dominic Chenf94c1082017-06-15 17:05:07 +000023 return results[-1]
Reid Kleckner2ae37c12017-04-05 18:56:48 +000024
25 # If z3 backend available, add an additional run line for it
Dominic Chen35610d22017-07-12 19:37:57 +000026 if test.config.clang_staticanalyzer_z3 == '1' and '!z3' not in test.requires:
Dominic Chenf94c1082017-06-15 17:05:07 +000027 results.append(self.executeWithAnalyzeSubstitution(
28 saved_test, litConfig, '-analyzer-constraints=z3 -DANALYZER_CM_Z3'))
Reid Kleckner2ae37c12017-04-05 18:56:48 +000029
Dominic Chenf94c1082017-06-15 17:05:07 +000030 # Combine all result outputs into the last element
31 for x in results:
32 if x != results[-1]:
33 results[-1].output = x.output + results[-1].output
34
35 if results:
36 return results[-1]
37 return lit.Test.Result(lit.Test.UNSUPPORTED,
38 "Test requires the following unavailable features: z3")
Reid Kleckner2ae37c12017-04-05 18:56:48 +000039
40 def executeWithAnalyzeSubstitution(self, test, litConfig, substitution):
41 saved_substitutions = list(test.config.substitutions)
42 test.config.substitutions.append(('%analyze', substitution))
43 result = lit.TestRunner.executeShTest(test, litConfig,
Dominic Chenf94c1082017-06-15 17:05:07 +000044 self.execute_external)
Reid Kleckner2ae37c12017-04-05 18:56:48 +000045 test.config.substitutions = saved_substitutions
46
47 return result