Alexandre Rames | b78f139 | 2016-07-01 14:22:22 +0100 | [diff] [blame] | 1 | # Copyright 2015, VIXL authors |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 2 | # All rights reserved. |
| 3 | # |
| 4 | # Redistribution and use in source and binary forms, with or without |
| 5 | # modification, are permitted provided that the following conditions are met: |
| 6 | # |
| 7 | # * Redistributions of source code must retain the above copyright notice, |
| 8 | # this list of conditions and the following disclaimer. |
| 9 | # * Redistributions in binary form must reproduce the above copyright notice, |
| 10 | # this list of conditions and the following disclaimer in the documentation |
| 11 | # and/or other materials provided with the distribution. |
| 12 | # * Neither the name of ARM Limited nor the names of its contributors may be |
| 13 | # used to endorse or promote products derived from this software without |
| 14 | # specific prior written permission. |
| 15 | # |
| 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND |
| 17 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 20 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 27 | import collections |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 28 | import multiprocessing |
| 29 | import re |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 30 | import subprocess |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 31 | import time |
| 32 | |
Anton Kirilov | 88a3376 | 2016-08-26 15:46:33 +0100 | [diff] [blame] | 33 | from known_test_failures import FilterKnownTestFailures |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 34 | import printer |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 35 | import thread_pool |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 36 | import util |
| 37 | |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 38 | REGEXP_MISSING_FEATURES = "Missing features: { ([^,}]+(, [^,}]+)*) }" |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 39 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 40 | # Scan matching tests and return a test manifest. |
| 41 | def GetTests(runner, filters = []): |
| 42 | rc, output = util.getstatusoutput(runner + ' --list') |
| 43 | if rc != 0: util.abort('Failed to list all tests') |
| 44 | |
| 45 | tests = output.split() |
| 46 | for f in filters: |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 47 | tests = filter(re.compile(f).search, tests) |
| 48 | |
| 49 | return tests |
| 50 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 51 | def RunTest(test): |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 52 | p = subprocess.Popen(test.command, |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 53 | stdout=subprocess.PIPE, |
| 54 | stderr=subprocess.STDOUT) |
| 55 | p_out, p_err = p.communicate() |
| 56 | rc = p.poll() |
| 57 | |
| 58 | if rc == 0: |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 59 | skipped = False |
| 60 | lines = p_out.split('\n') |
| 61 | skipped_id = "SKIPPED: " |
| 62 | for i in range(len(lines)): |
| 63 | if lines[i].startswith(skipped_id): |
| 64 | skipped = True |
| 65 | reason = lines[i][len(skipped_id):] |
| 66 | with Test.n_tests_skipped.get_lock(): |
| 67 | Test.n_tests_skipped.value += 1 |
| 68 | test.shared.tests_skipped.setdefault(reason, 0) |
| 69 | test.shared.tests_skipped[reason] += 1 |
| 70 | break |
| 71 | if not skipped: |
| 72 | with Test.n_tests_passed.get_lock(): Test.n_tests_passed.value += 1 |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 73 | else: |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 74 | with Test.n_tests_failed.get_lock(): Test.n_tests_failed.value += 1 |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 75 | |
| 76 | printer.__print_lock__.acquire() |
| 77 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 78 | printer.UpdateProgress(test.shared.start_time, |
| 79 | Test.n_tests_passed.value, |
| 80 | Test.n_tests_failed.value, |
| 81 | test.shared.n_tests, |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 82 | Test.n_tests_skipped.value, |
| 83 | test.shared.n_known_failures, |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 84 | test.name, |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 85 | prevent_next_overwrite = (rc != 0), |
| 86 | has_lock = True, |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 87 | prefix = test.shared.progress_prefix) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 88 | |
| 89 | if rc != 0: |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 90 | printer.Print('FAILED: ' + test.name, has_lock = True) |
| 91 | printer.Print(printer.COLOUR_RED + ' '.join(test.command) + printer.NO_COLOUR, |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 92 | has_lock = True) |
| 93 | printer.Print(p_out, has_lock = True) |
| 94 | |
| 95 | printer.__print_lock__.release() |
| 96 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 97 | class Test(object): |
| 98 | # Shared state for multiprocessing. Ideally the context should be passed with |
| 99 | # arguments, but constraints from the multiprocessing module prevent us from |
| 100 | # doing so: the shared variables (multiprocessing.Value) must be either global |
| 101 | # or static, or no work is started. |
| 102 | n_tests_passed = multiprocessing.Value('i', 0) |
| 103 | n_tests_failed = multiprocessing.Value('i', 0) |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 104 | n_tests_skipped = multiprocessing.Value('i', 0) |
| 105 | manager = multiprocessing.Manager() |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 106 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 107 | def __init__(self, test_runner, test, runtime_options, use_valgrind, shared): |
| 108 | self.command = [test_runner, test] + runtime_options |
| 109 | self.name = test |
| 110 | self.shared = shared |
| 111 | if use_valgrind: |
| 112 | self.command = ['valgrind'] + self.command |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 113 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 114 | class TestQueue(object): |
| 115 | def __init__(self, under_valgrind = False, prefix = ''): |
| 116 | self.progress_prefix = prefix |
| 117 | self.under_valgrind = under_valgrind |
| 118 | self.queue = [] |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 119 | self.tests_skipped = Test.manager.dict() |
| 120 | self.n_known_failures = 0 |
| 121 | self.known_failures = collections.Counter() |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 122 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 123 | def Add(self, test_runner_command, filters, runtime_options): |
| 124 | tests = GetTests(test_runner_command, filters) |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 125 | n_tests_total = len(tests) |
| 126 | tests, skipped = FilterKnownTestFailures(tests, under_valgrind = self.under_valgrind) |
| 127 | for n_tests, reason in skipped: |
| 128 | if n_tests > 0: |
| 129 | self.n_known_failures += n_tests |
| 130 | self.known_failures[reason] += n_tests |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 131 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 132 | if len(tests) == 0: |
| 133 | printer.Print('No tests to run.') |
| 134 | return |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 135 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 136 | for test in tests: |
| 137 | self.queue.append(Test(test_runner_command, test, |
| 138 | runtime_options, self.under_valgrind, self)) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 139 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 140 | # Run the specified tests. |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 141 | def Run(self, jobs, verbose): |
| 142 | def InitGlobals(): |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 143 | # Initialisation. |
| 144 | self.start_time = time.time() |
| 145 | self.n_tests = len(self.queue) |
| 146 | if self.n_tests == 0: |
| 147 | printer.Print('No tests to run.') |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 148 | return False |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 149 | Test.n_tests_passed.value = 0 |
| 150 | Test.n_tests_failed.value = 0 |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 151 | Test.n_tests_skipped.value = 0 |
| 152 | self.tests_skipped.clear() |
| 153 | return True |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 154 | |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 155 | thread_pool.Multithread(RunTest, self.queue, jobs, InitGlobals) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 156 | |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame^] | 157 | printer.UpdateProgress(self.start_time, |
| 158 | Test.n_tests_passed.value, |
| 159 | Test.n_tests_failed.value, |
| 160 | self.n_tests, |
| 161 | Test.n_tests_skipped.value, |
| 162 | self.n_known_failures, |
| 163 | '== Done ==', |
| 164 | prevent_next_overwrite = True, |
| 165 | prefix = self.progress_prefix) |
| 166 | n_tests_features = 0 |
| 167 | features = set() |
| 168 | for reason, n_tests in self.tests_skipped.items(): |
| 169 | m = re.match(REGEXP_MISSING_FEATURES, reason) |
| 170 | if m: |
| 171 | if verbose: |
| 172 | printer.Print("%d tests skipped because the following features are not " |
| 173 | "available '%s'" % (n_tests, m.group(1))) |
| 174 | else: |
| 175 | n_tests_features += n_tests |
| 176 | features.update(m.group(1).split(', ')) |
| 177 | else: |
| 178 | printer.Print("%d tests skipped because '%s'" % (n_tests, reason)) |
| 179 | |
| 180 | n_tests_other = 0 |
| 181 | if n_tests_features > 0 : |
| 182 | printer.Print("%d tests skipped because the CPU does not support " |
| 183 | "the following features: '%s'" % |
| 184 | (n_tests_features, ", ".join(features))) |
| 185 | |
| 186 | for reason, n_tests in self.known_failures.items(): |
| 187 | printer.Print("%d tests skipped because '%s'" % (n_tests, reason)) |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 188 | |
| 189 | # Empty the queue now that the tests have been run. |
| 190 | self.queue = [] |
| 191 | # `0` indicates success |
| 192 | return Test.n_tests_failed.value |
| 193 | |