Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 1 | import lit.formats |
| 2 | import lit.TestRunner |
| 3 | |
| 4 | # Custom format class for static analyzer tests |
| 5 | class AnalyzerTest(lit.formats.ShTest): |
| 6 | |
| 7 | def execute(self, test, litConfig): |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 8 | results = [] |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 9 | |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 10 | # Parse any test requirements ('REQUIRES: ') |
Dominic Chen | c0402c6 | 2017-07-12 21:43:42 +0000 | [diff] [blame^] | 11 | saved_test = test |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 12 | lit.TestRunner.parseIntegratedTestScript(test) |
| 13 | |
| 14 | if 'z3' not in test.requires: |
| 15 | results.append(self.executeWithAnalyzeSubstitution( |
Dominic Chen | c0402c6 | 2017-07-12 21:43:42 +0000 | [diff] [blame^] | 16 | saved_test, litConfig, '-analyzer-constraints=range')) |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 17 | |
Dominic Chen | c0402c6 | 2017-07-12 21:43:42 +0000 | [diff] [blame^] | 18 | if results[-1].code == lit.Test.FAIL: |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 19 | return results[-1] |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 20 | |
| 21 | # If z3 backend available, add an additional run line for it |
Dominic Chen | c0402c6 | 2017-07-12 21:43:42 +0000 | [diff] [blame^] | 22 | if test.config.clang_staticanalyzer_z3 == '1': |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 23 | results.append(self.executeWithAnalyzeSubstitution( |
| 24 | saved_test, litConfig, '-analyzer-constraints=z3 -DANALYZER_CM_Z3')) |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 25 | |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 26 | # Combine all result outputs into the last element |
| 27 | for x in results: |
| 28 | if x != results[-1]: |
| 29 | results[-1].output = x.output + results[-1].output |
| 30 | |
| 31 | if results: |
| 32 | return results[-1] |
| 33 | return lit.Test.Result(lit.Test.UNSUPPORTED, |
| 34 | "Test requires the following unavailable features: z3") |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 35 | |
| 36 | def executeWithAnalyzeSubstitution(self, test, litConfig, substitution): |
| 37 | saved_substitutions = list(test.config.substitutions) |
| 38 | test.config.substitutions.append(('%analyze', substitution)) |
| 39 | result = lit.TestRunner.executeShTest(test, litConfig, |
Dominic Chen | f94c108 | 2017-06-15 17:05:07 +0000 | [diff] [blame] | 40 | self.execute_external) |
Reid Kleckner | 2ae37c1 | 2017-04-05 18:56:48 +0000 | [diff] [blame] | 41 | test.config.substitutions = saved_substitutions |
| 42 | |
| 43 | return result |