blob: a2655330aac4ae4f8883c29e721a4e9f62b6e4ef [file] [log] [blame]
Alexandre Ramesb78f1392016-07-01 14:22:22 +01001# Copyright 2015, VIXL authors
armvixldb644342015-07-21 11:37:10 +01002# 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 Barbier88e1d032019-06-13 15:20:20 +010027import collections
armvixldb644342015-07-21 11:37:10 +010028import multiprocessing
29import re
armvixldb644342015-07-21 11:37:10 +010030import subprocess
armvixldb644342015-07-21 11:37:10 +010031import time
32
Anton Kirilov88a33762016-08-26 15:46:33 +010033from known_test_failures import FilterKnownTestFailures
armvixldb644342015-07-21 11:37:10 +010034import printer
Anthony Barbier88e1d032019-06-13 15:20:20 +010035import thread_pool
armvixldb644342015-07-21 11:37:10 +010036import util
37
Anthony Barbier88e1d032019-06-13 15:20:20 +010038REGEXP_MISSING_FEATURES = "Missing features: { ([^,}]+(, [^,}]+)*) }"
armvixldb644342015-07-21 11:37:10 +010039
armvixldb644342015-07-21 11:37:10 +010040# Scan matching tests and return a test manifest.
41def 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:
armvixldb644342015-07-21 11:37:10 +010047 tests = filter(re.compile(f).search, tests)
48
49 return tests
50
armvixldb644342015-07-21 11:37:10 +010051def RunTest(test):
Anthony Barbierb5f72392019-02-15 15:33:48 +000052 p = subprocess.Popen(test.command,
armvixldb644342015-07-21 11:37:10 +010053 stdout=subprocess.PIPE,
54 stderr=subprocess.STDOUT)
55 p_out, p_err = p.communicate()
56 rc = p.poll()
57
58 if rc == 0:
Anthony Barbier88e1d032019-06-13 15:20:20 +010059 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
armvixldb644342015-07-21 11:37:10 +010073 else:
Anthony Barbierb5f72392019-02-15 15:33:48 +000074 with Test.n_tests_failed.get_lock(): Test.n_tests_failed.value += 1
armvixldb644342015-07-21 11:37:10 +010075
76 printer.__print_lock__.acquire()
77
Anthony Barbierb5f72392019-02-15 15:33:48 +000078 printer.UpdateProgress(test.shared.start_time,
79 Test.n_tests_passed.value,
80 Test.n_tests_failed.value,
81 test.shared.n_tests,
Anthony Barbier88e1d032019-06-13 15:20:20 +010082 Test.n_tests_skipped.value,
83 test.shared.n_known_failures,
Anthony Barbierb5f72392019-02-15 15:33:48 +000084 test.name,
armvixldb644342015-07-21 11:37:10 +010085 prevent_next_overwrite = (rc != 0),
86 has_lock = True,
Anthony Barbierb5f72392019-02-15 15:33:48 +000087 prefix = test.shared.progress_prefix)
armvixldb644342015-07-21 11:37:10 +010088
89 if rc != 0:
Anthony Barbierb5f72392019-02-15 15:33:48 +000090 printer.Print('FAILED: ' + test.name, has_lock = True)
91 printer.Print(printer.COLOUR_RED + ' '.join(test.command) + printer.NO_COLOUR,
armvixldb644342015-07-21 11:37:10 +010092 has_lock = True)
93 printer.Print(p_out, has_lock = True)
94
95 printer.__print_lock__.release()
96
Anthony Barbierb5f72392019-02-15 15:33:48 +000097class 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 Barbier88e1d032019-06-13 15:20:20 +0100104 n_tests_skipped = multiprocessing.Value('i', 0)
105 manager = multiprocessing.Manager()
armvixldb644342015-07-21 11:37:10 +0100106
Anthony Barbierb5f72392019-02-15 15:33:48 +0000107 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
armvixldb644342015-07-21 11:37:10 +0100113
Anthony Barbierb5f72392019-02-15 15:33:48 +0000114class 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 Barbier88e1d032019-06-13 15:20:20 +0100119 self.tests_skipped = Test.manager.dict()
120 self.n_known_failures = 0
121 self.known_failures = collections.Counter()
armvixldb644342015-07-21 11:37:10 +0100122
Anthony Barbierb5f72392019-02-15 15:33:48 +0000123 def Add(self, test_runner_command, filters, runtime_options):
124 tests = GetTests(test_runner_command, filters)
Anthony Barbier88e1d032019-06-13 15:20:20 +0100125 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
armvixldb644342015-07-21 11:37:10 +0100131
Anthony Barbierb5f72392019-02-15 15:33:48 +0000132 if len(tests) == 0:
133 printer.Print('No tests to run.')
134 return
armvixldb644342015-07-21 11:37:10 +0100135
Anthony Barbierb5f72392019-02-15 15:33:48 +0000136 for test in tests:
137 self.queue.append(Test(test_runner_command, test,
138 runtime_options, self.under_valgrind, self))
armvixldb644342015-07-21 11:37:10 +0100139
Anthony Barbierb5f72392019-02-15 15:33:48 +0000140 # Run the specified tests.
Anthony Barbier88e1d032019-06-13 15:20:20 +0100141 def Run(self, jobs, verbose):
142 def InitGlobals():
Anthony Barbierb5f72392019-02-15 15:33:48 +0000143 # 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 Barbier88e1d032019-06-13 15:20:20 +0100148 return False
Anthony Barbierb5f72392019-02-15 15:33:48 +0000149 Test.n_tests_passed.value = 0
150 Test.n_tests_failed.value = 0
Anthony Barbier88e1d032019-06-13 15:20:20 +0100151 Test.n_tests_skipped.value = 0
152 self.tests_skipped.clear()
153 return True
armvixldb644342015-07-21 11:37:10 +0100154
Anthony Barbier88e1d032019-06-13 15:20:20 +0100155 thread_pool.Multithread(RunTest, self.queue, jobs, InitGlobals)
armvixldb644342015-07-21 11:37:10 +0100156
Anthony Barbier88e1d032019-06-13 15:20:20 +0100157 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 Barbierb5f72392019-02-15 15:33:48 +0000188
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