Dominic Chen | 35610d2 | 2017-07-12 19:37:57 +0000 | [diff] [blame] | 1 | import copy |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 2 | import lit.formats |
| 3 | import lit.TestRunner |
| 4 | |
| 5 | # Custom format class for static analyzer tests |
| 6 | class AnalyzerTest(lit.formats.ShTest): |
| 7 | |
| 8 | def execute(self, test, litConfig): |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 9 | results = [] |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 10 | |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 11 | # Parse any test requirements ('REQUIRES: ') |
Dominic Chen | 35610d2 | 2017-07-12 19:37:57 +0000 | [diff] [blame] | 12 | saved_test = copy.deepcopy(test) |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 13 | lit.TestRunner.parseIntegratedTestScript(test) |
| 14 | |
Dominic Chen | 35610d2 | 2017-07-12 19:37:57 +0000 | [diff] [blame] | 15 | # If the test does not require z3, drop it from the available features |
| 16 | # to satisfy tests that explicitly require !z3 |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 17 | if 'z3' not in test.requires: |
Dominic Chen | 35610d2 | 2017-07-12 19:37:57 +0000 | [diff] [blame] | 18 | test.config.available_features.discard('z3') |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 19 | results.append(self.executeWithAnalyzeSubstitution( |
Dominic Chen | 35610d2 | 2017-07-12 19:37:57 +0000 | [diff] [blame] | 20 | test, litConfig, '-analyzer-constraints=range')) |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 21 | |
Dominic Chen | 35610d2 | 2017-07-12 19:37:57 +0000 | [diff] [blame] | 22 | if results[-1].code != lit.Test.PASS: |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 23 | return results[-1] |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 24 | |
| 25 | # If z3 backend available, add an additional run line for it |
Dominic Chen | 35610d2 | 2017-07-12 19:37:57 +0000 | [diff] [blame] | 26 | if test.config.clang_staticanalyzer_z3 == '1' and '!z3' not in test.requires: |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 27 | results.append(self.executeWithAnalyzeSubstitution( |
| 28 | saved_test, litConfig, '-analyzer-constraints=z3 -DANALYZER_CM_Z3')) |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 29 | |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 30 | # 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 Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 39 | |
| 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 Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 44 | self.execute_external) |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 45 | test.config.substitutions = saved_substitutions |
| 46 | |
| 47 | return result |