armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | |
Alexandre Rames | b78f139 | 2016-07-01 14:22:22 +0100 | [diff] [blame] | 3 | # Copyright 2015, VIXL authors |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright notice, |
| 10 | # this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above copyright notice, |
| 12 | # this list of conditions and the following disclaimer in the documentation |
| 13 | # and/or other materials provided with the distribution. |
| 14 | # * Neither the name of ARM Limited nor the names of its contributors may be |
| 15 | # used to endorse or promote products derived from this software without |
| 16 | # specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND |
| 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 22 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 29 | import argparse |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 30 | import fcntl |
| 31 | import git |
| 32 | import itertools |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 33 | import multiprocessing |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 34 | import os |
| 35 | from os.path import join |
| 36 | import platform |
| 37 | import re |
| 38 | import subprocess |
| 39 | import sys |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 40 | import time |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 41 | |
| 42 | import config |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 43 | import clang_format |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 44 | import lint |
| 45 | import printer |
| 46 | import test |
| 47 | import threaded_tests |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 48 | import util |
| 49 | |
| 50 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 51 | dir_root = config.dir_root |
| 52 | |
| 53 | def Optionify(name): |
| 54 | return '--' + name |
| 55 | |
| 56 | |
| 57 | # The options that can be tested are abstracted to provide an easy way to add |
| 58 | # new ones. |
| 59 | # Environment options influence the environment. They can be used for example to |
| 60 | # set the compiler used. |
| 61 | # Build options are options passed to scons, with a syntax like `scons opt=val` |
| 62 | # Runtime options are options passed to the test program. |
| 63 | # See the definition of `test_options` below. |
| 64 | |
| 65 | # 'all' is a special value for the options. If specified, all other values of |
| 66 | # the option are tested. |
| 67 | class TestOption(object): |
| 68 | type_environment = 'type_environment' |
| 69 | type_build = 'type_build' |
| 70 | type_run = 'type_run' |
| 71 | |
| 72 | def __init__(self, option_type, name, help, |
| 73 | val_test_choices, val_test_default = None, |
| 74 | # If unset, the user can pass any value. |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 75 | strict_choices = True, test_independently = False): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 76 | self.name = name |
| 77 | self.option_type = option_type |
| 78 | self.help = help |
| 79 | self.val_test_choices = val_test_choices |
| 80 | self.strict_choices = strict_choices |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 81 | self.test_independently = test_independently |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 82 | if val_test_default is not None: |
| 83 | self.val_test_default = val_test_default |
| 84 | else: |
| 85 | self.val_test_default = val_test_choices[0] |
| 86 | |
| 87 | def ArgList(self, to_test): |
| 88 | res = [] |
| 89 | if to_test == 'all': |
| 90 | for value in self.val_test_choices: |
| 91 | if value != 'all': |
| 92 | res.append(self.GetOptionString(value)) |
| 93 | else: |
| 94 | for value in to_test: |
| 95 | res.append(self.GetOptionString(value)) |
| 96 | return res |
| 97 | |
| 98 | class EnvironmentOption(TestOption): |
| 99 | option_type = TestOption.type_environment |
| 100 | def __init__(self, name, environment_variable_name, help, |
| 101 | val_test_choices, val_test_default = None, |
| 102 | strict_choices = True): |
| 103 | super(EnvironmentOption, self).__init__(EnvironmentOption.option_type, |
| 104 | name, |
| 105 | help, |
| 106 | val_test_choices, |
| 107 | val_test_default, |
| 108 | strict_choices = strict_choices) |
| 109 | self.environment_variable_name = environment_variable_name |
| 110 | |
| 111 | def GetOptionString(self, value): |
| 112 | return self.environment_variable_name + '=' + value |
| 113 | |
| 114 | |
| 115 | class BuildOption(TestOption): |
| 116 | option_type = TestOption.type_build |
| 117 | def __init__(self, name, help, |
| 118 | val_test_choices, val_test_default = None, |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 119 | strict_choices = True, test_independently = False): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 120 | super(BuildOption, self).__init__(BuildOption.option_type, |
| 121 | name, |
| 122 | help, |
| 123 | val_test_choices, |
| 124 | val_test_default, |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 125 | strict_choices = strict_choices, |
| 126 | test_independently = test_independently) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 127 | def GetOptionString(self, value): |
| 128 | return self.name + '=' + value |
| 129 | |
| 130 | |
| 131 | class RuntimeOption(TestOption): |
| 132 | option_type = TestOption.type_run |
| 133 | def __init__(self, name, help, |
| 134 | val_test_choices, val_test_default = None): |
| 135 | super(RuntimeOption, self).__init__(RuntimeOption.option_type, |
| 136 | name, |
| 137 | help, |
| 138 | val_test_choices, |
| 139 | val_test_default) |
| 140 | def GetOptionString(self, value): |
| 141 | if value == 'on': |
| 142 | return Optionify(self.name) |
| 143 | else: |
| 144 | return None |
| 145 | |
| 146 | |
| 147 | |
| 148 | environment_option_compiler = \ |
| 149 | EnvironmentOption('compiler', 'CXX', 'Test for the specified compilers.', |
| 150 | val_test_choices=['all'] + config.tested_compilers, |
| 151 | strict_choices = False) |
| 152 | test_environment_options = [ |
| 153 | environment_option_compiler |
| 154 | ] |
| 155 | |
| 156 | build_option_mode = \ |
| 157 | BuildOption('mode', 'Test with the specified build modes.', |
| 158 | val_test_choices=['all'] + config.build_options_modes) |
| 159 | build_option_standard = \ |
| 160 | BuildOption('std', 'Test with the specified C++ standard.', |
| 161 | val_test_choices=['all'] + config.tested_cpp_standards, |
| 162 | strict_choices = False) |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 163 | build_option_target = \ |
| 164 | BuildOption('target', 'Test with the specified isa enabled.', |
| 165 | val_test_choices=['all'] + config.build_options_target, |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 166 | strict_choices = False, test_independently = True) |
| 167 | build_option_negative_testing = \ |
| 168 | BuildOption('negative_testing', 'Test with negative testing enabled.', |
| 169 | val_test_choices=['all'] + config.build_options_negative_testing, |
| 170 | strict_choices = False, test_independently = True) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 171 | test_build_options = [ |
| 172 | build_option_mode, |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 173 | build_option_standard, |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 174 | build_option_target, |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 175 | build_option_negative_testing |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 176 | ] |
| 177 | |
Jacob Bramley | c919d87 | 2018-07-03 17:58:44 +0100 | [diff] [blame] | 178 | test_runtime_options = [] |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 179 | |
| 180 | test_options = \ |
Jacob Bramley | c919d87 | 2018-07-03 17:58:44 +0100 | [diff] [blame] | 181 | test_environment_options + test_build_options + test_runtime_options |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 182 | |
| 183 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 184 | def BuildOptions(): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 185 | args = argparse.ArgumentParser( |
| 186 | description = |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 187 | '''This tool runs all tests matching the specified filters for multiple |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 188 | environment, build options, and runtime options configurations.''', |
| 189 | # Print default values. |
| 190 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 191 | |
| 192 | args.add_argument('filters', metavar='filter', nargs='*', |
| 193 | help='Run tests matching all of the (regexp) filters.') |
| 194 | |
| 195 | # We automatically build the script options from the options to be tested. |
| 196 | test_arguments = args.add_argument_group( |
| 197 | 'Test options', |
| 198 | 'These options indicate what should be tested') |
| 199 | for option in test_options: |
| 200 | choices = option.val_test_choices if option.strict_choices else None |
| 201 | help = option.help |
| 202 | if not option.strict_choices: |
| 203 | help += ' Supported values: {' + ','.join(option.val_test_choices) + '}' |
| 204 | test_arguments.add_argument(Optionify(option.name), |
| 205 | nargs='+', |
| 206 | choices=choices, |
| 207 | default=option.val_test_default, |
| 208 | help=help, |
| 209 | action='store') |
| 210 | |
| 211 | general_arguments = args.add_argument_group('General options') |
| 212 | general_arguments.add_argument('--fast', action='store_true', |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 213 | help='''Skip the lint and clang-format tests, |
| 214 | and run only with one compiler, in one mode, |
| 215 | with one C++ standard, and with an appropriate |
Alexandre Rames | dd7de86 | 2016-07-06 13:56:11 +0100 | [diff] [blame] | 216 | default for runtime options.''') |
Jacob Bramley | 59d74ae | 2017-01-18 15:27:45 +0000 | [diff] [blame] | 217 | general_arguments.add_argument('--dry-run', action='store_true', |
| 218 | help='''Don't actually build or run anything, |
| 219 | but print the configurations that would be |
| 220 | tested.''') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 221 | general_arguments.add_argument( |
| 222 | '--jobs', '-j', metavar='N', type=int, nargs='?', |
| 223 | default=multiprocessing.cpu_count(), |
| 224 | const=multiprocessing.cpu_count(), |
| 225 | help='''Runs the tests using N jobs. If the option is set but no value is |
| 226 | provided, the script will use as many jobs as it thinks useful.''') |
Pierre Langlois | 44096c4 | 2018-05-23 23:15:25 +0100 | [diff] [blame] | 227 | general_arguments.add_argument('--clang-format', |
| 228 | default=clang_format.DEFAULT_CLANG_FORMAT, |
| 229 | help='Path to clang-format.') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 230 | general_arguments.add_argument('--nobench', action='store_true', |
| 231 | help='Do not run benchmarks.') |
| 232 | general_arguments.add_argument('--nolint', action='store_true', |
| 233 | help='Do not run the linter.') |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 234 | general_arguments.add_argument('--noclang-format', action='store_true', |
| 235 | help='Do not run clang-format.') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 236 | general_arguments.add_argument('--notest', action='store_true', |
| 237 | help='Do not run tests.') |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 238 | general_arguments.add_argument('--fail-early', action='store_true', |
| 239 | help='Exit as soon as a test fails.') |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 240 | sim_default = 'none' if platform.machine() == 'aarch64' else 'aarch64' |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 241 | general_arguments.add_argument( |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 242 | '--simulator', action='store', choices=['aarch64', 'none'], |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 243 | default=sim_default, |
| 244 | help='Explicitly enable or disable the simulator.') |
armvixl | 684cd2a | 2015-10-23 13:38:33 +0100 | [diff] [blame] | 245 | general_arguments.add_argument( |
| 246 | '--under_valgrind', action='store_true', |
| 247 | help='''Run the test-runner commands under Valgrind. |
| 248 | Note that a few tests are known to fail because of |
| 249 | issues in Valgrind''') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 250 | return args.parse_args() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 251 | |
| 252 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 253 | def RunCommand(command, environment_options = None): |
| 254 | # Create a copy of the environment. We do not want to pollute the environment |
| 255 | # of future commands run. |
| 256 | environment = os.environ |
| 257 | # Configure the environment. |
| 258 | # TODO: We currently pass the options as strings, so we need to parse them. We |
| 259 | # should instead pass them as a data structure and build the string option |
| 260 | # later. `environment_options` looks like `['CXX=compiler', 'OPT=val']`. |
| 261 | if environment_options: |
| 262 | for option in environment_options: |
| 263 | opt, val = option.split('=') |
| 264 | environment[opt] = val |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 265 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 266 | printable_command = '' |
| 267 | if environment_options: |
| 268 | printable_command += ' '.join(environment_options) + ' ' |
| 269 | printable_command += ' '.join(command) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 270 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 271 | printable_command_orange = \ |
| 272 | printer.COLOUR_ORANGE + printable_command + printer.NO_COLOUR |
| 273 | printer.PrintOverwritableLine(printable_command_orange) |
| 274 | sys.stdout.flush() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 275 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 276 | # Start a process for the command. |
| 277 | # Interleave `stderr` and `stdout`. |
| 278 | p = subprocess.Popen(command, |
| 279 | stdout=subprocess.PIPE, |
| 280 | stderr=subprocess.STDOUT, |
| 281 | env=environment) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 282 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 283 | # We want to be able to display a continuously updated 'work indicator' while |
| 284 | # the process is running. Since the process can hang if the `stdout` pipe is |
| 285 | # full, we need to pull from it regularly. We cannot do so via the |
| 286 | # `readline()` function because it is blocking, and would thus cause the |
| 287 | # indicator to not be updated properly. So use file control mechanisms |
| 288 | # instead. |
| 289 | indicator = ' (still working: %d seconds elapsed)' |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 290 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 291 | # Mark the process output as non-blocking. |
| 292 | flags = fcntl.fcntl(p.stdout, fcntl.F_GETFL) |
| 293 | fcntl.fcntl(p.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK) |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 294 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 295 | t_start = time.time() |
| 296 | t_last_indication = t_start |
| 297 | process_output = '' |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 298 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 299 | # Keep looping as long as the process is running. |
| 300 | while p.poll() is None: |
| 301 | # Avoid polling too often. |
| 302 | time.sleep(0.1) |
| 303 | # Update the progress indicator. |
| 304 | t_current = time.time() |
| 305 | if (t_current - t_start >= 2) and (t_current - t_last_indication >= 1): |
| 306 | printer.PrintOverwritableLine( |
| 307 | printable_command_orange + indicator % int(t_current - t_start)) |
| 308 | sys.stdout.flush() |
| 309 | t_last_indication = t_current |
| 310 | # Pull from the process output. |
| 311 | while True: |
| 312 | try: |
| 313 | line = os.read(p.stdout.fileno(), 1024) |
| 314 | except OSError: |
| 315 | line = '' |
| 316 | break |
| 317 | if line == '': break |
| 318 | process_output += line |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 319 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 320 | # The process has exited. Don't forget to retrieve the rest of its output. |
| 321 | out, err = p.communicate() |
| 322 | rc = p.poll() |
| 323 | process_output += out |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 324 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame^] | 325 | printable_command += ' (took %d seconds)' % int(t_current - t_start) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 326 | if rc == 0: |
| 327 | printer.Print(printer.COLOUR_GREEN + printable_command + printer.NO_COLOUR) |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 328 | else: |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 329 | printer.Print(printer.COLOUR_RED + printable_command + printer.NO_COLOUR) |
| 330 | printer.Print(process_output) |
| 331 | return rc |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 332 | |
| 333 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 334 | def RunLinter(): |
Alexandre Rames | b274662 | 2016-07-11 16:12:39 +0100 | [diff] [blame] | 335 | rc, default_tracked_files = lint.GetDefaultFilesToLint() |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 336 | if rc: |
| 337 | return rc |
Alexandre Rames | b274662 | 2016-07-11 16:12:39 +0100 | [diff] [blame] | 338 | return lint.RunLinter(map(lambda x: join(dir_root, x), default_tracked_files), |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 339 | jobs = args.jobs, progress_prefix = 'cpp lint: ') |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 340 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 341 | |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 342 | def RunClangFormat(): |
| 343 | return clang_format.ClangFormatFiles(clang_format.GetCppSourceFilesToFormat(), |
Pierre Langlois | 44096c4 | 2018-05-23 23:15:25 +0100 | [diff] [blame] | 344 | args.clang_format, jobs = args.jobs, |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 345 | progress_prefix = 'clang-format: ') |
| 346 | |
| 347 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 348 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 349 | def BuildAll(build_options, jobs): |
| 350 | scons_command = ["scons", "-C", dir_root, 'all', '-j', str(jobs)] |
| 351 | scons_command += list(build_options) |
| 352 | return RunCommand(scons_command, list(environment_options)) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 353 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 354 | |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 355 | # Work out if the given options or args allow to run on the specified arch. |
| 356 | # * arches is a list of ISA/architecture (a64, aarch32, etc) |
| 357 | # * options are test.py's command line options if any. |
| 358 | # * args are the arguments given to the build script. |
| 359 | def CanRunOn(arches, options, args): |
| 360 | # First we check in the build specific options. |
| 361 | for option in options: |
| 362 | if 'target' in option: |
| 363 | # The option format is 'target=x,y,z'. |
| 364 | for target in (option.split('='))[1].split(','): |
| 365 | if target in arches: |
| 366 | return True |
| 367 | |
| 368 | # There was a target build option but it didn't include the target arch. |
| 369 | return False |
| 370 | |
| 371 | # No specific build option, check the script arguments. |
| 372 | # The meaning of 'all' will depend on the platform, e.g. 32-bit compilers |
| 373 | # cannot handle Aarch64 while 64-bit compiler can handle Aarch32. To avoid |
| 374 | # any issues no benchmarks are run for target='all'. |
| 375 | if args.target == 'all': return False |
| 376 | |
| 377 | for target in args.target[0].split(','): |
| 378 | if target in arches: |
| 379 | return True |
| 380 | |
| 381 | return False |
| 382 | |
| 383 | |
| 384 | def CanRunAarch64(options, args): |
| 385 | return CanRunOn(['aarch64', 'a64'], options, args) |
| 386 | |
| 387 | |
| 388 | def CanRunAarch32(options, args): |
| 389 | return CanRunOn(['aarch32', 'a32', 't32'], options, args) |
| 390 | |
| 391 | |
| 392 | def RunBenchmarks(options, args): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 393 | rc = 0 |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 394 | if CanRunAarch32(options, args): |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 395 | benchmark_names = util.ListCCFilesWithoutExt(config.dir_aarch32_benchmarks) |
| 396 | for bench in benchmark_names: |
| 397 | rc |= RunCommand( |
| 398 | [os.path.realpath( |
Martyn Capewell | 9cd420f | 2017-05-12 20:30:23 +0100 | [diff] [blame] | 399 | join(config.dir_build_latest, 'benchmarks/aarch32', bench)), '10']) |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 400 | if CanRunAarch64(options, args): |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 401 | benchmark_names = util.ListCCFilesWithoutExt(config.dir_aarch64_benchmarks) |
| 402 | for bench in benchmark_names: |
| 403 | rc |= RunCommand( |
| 404 | [util.relrealpath( |
Martyn Capewell | 9cd420f | 2017-05-12 20:30:23 +0100 | [diff] [blame] | 405 | join(config.dir_build_latest, |
| 406 | 'benchmarks/aarch64', bench)), '10']) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 407 | return rc |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 408 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 409 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 410 | def PrintStatus(success): |
| 411 | printer.Print('\n$ ' + ' '.join(sys.argv)) |
| 412 | if success: |
| 413 | printer.Print('SUCCESS') |
| 414 | else: |
| 415 | printer.Print('FAILURE') |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 416 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 417 | |
| 418 | |
| 419 | if __name__ == '__main__': |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 420 | util.require_program('scons') |
| 421 | rc = 0 |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 422 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 423 | args = BuildOptions() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 424 | |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 425 | def MaybeExitEarly(rc): |
| 426 | if args.fail_early and rc != 0: |
| 427 | PrintStatus(rc == 0) |
| 428 | sys.exit(rc) |
| 429 | |
armvixl | 684cd2a | 2015-10-23 13:38:33 +0100 | [diff] [blame] | 430 | if args.under_valgrind: |
| 431 | util.require_program('valgrind') |
| 432 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 433 | if args.fast: |
| 434 | def SetFast(option, specified, default): |
| 435 | option.val_test_choices = \ |
Alexandre Rames | dd7de86 | 2016-07-06 13:56:11 +0100 | [diff] [blame] | 436 | [default if specified == 'all' else specified[0]] |
| 437 | # `g++` is very slow to compile a few aarch32 test files. |
| 438 | SetFast(environment_option_compiler, args.compiler, 'clang++') |
| 439 | SetFast(build_option_standard, args.std, 'c++98') |
| 440 | SetFast(build_option_mode, args.mode, 'debug') |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 441 | |
Jacob Bramley | 59d74ae | 2017-01-18 15:27:45 +0000 | [diff] [blame] | 442 | if not args.nolint and not (args.fast or args.dry_run): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 443 | rc |= RunLinter() |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 444 | MaybeExitEarly(rc) |
| 445 | |
Jacob Bramley | 59d74ae | 2017-01-18 15:27:45 +0000 | [diff] [blame] | 446 | if not args.noclang_format and not (args.fast or args.dry_run): |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 447 | rc |= RunClangFormat() |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 448 | MaybeExitEarly(rc) |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 449 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 450 | # List all combinations of options that will be tested. |
| 451 | def ListCombinations(args, options): |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 452 | opts_list = [ |
| 453 | opt.ArgList(args.__dict__[opt.name]) |
| 454 | for opt in options |
| 455 | if not opt.test_independently |
| 456 | ] |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 457 | return list(itertools.product(*opts_list)) |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 458 | # List combinations of options that should only be tested independently. |
Jacob Bramley | d503ed2 | 2017-01-18 16:14:37 +0000 | [diff] [blame] | 459 | def ListIndependentCombinations(args, options, base): |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 460 | n = [] |
| 461 | for opt in options: |
| 462 | if opt.test_independently: |
| 463 | for o in opt.ArgList(args.__dict__[opt.name]): |
Jacob Bramley | d503ed2 | 2017-01-18 16:14:37 +0000 | [diff] [blame] | 464 | n.append(base + (o,)) |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 465 | return n |
Georgia Kouveli | 38d5d1b | 2016-11-16 11:58:41 +0000 | [diff] [blame] | 466 | # TODO: We should refine the configurations we test by default, instead of |
| 467 | # always testing all possible combinations. |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 468 | test_env_combinations = ListCombinations(args, test_environment_options) |
| 469 | test_build_combinations = ListCombinations(args, test_build_options) |
Jacob Bramley | d503ed2 | 2017-01-18 16:14:37 +0000 | [diff] [blame] | 470 | if not args.fast: |
| 471 | test_build_combinations.extend( |
| 472 | ListIndependentCombinations(args, |
| 473 | test_build_options, |
| 474 | test_build_combinations[0])) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 475 | test_runtime_combinations = ListCombinations(args, test_runtime_options) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 476 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame^] | 477 | tests = threaded_tests.TestQueue(args.under_valgrind) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 478 | for environment_options in test_env_combinations: |
| 479 | for build_options in test_build_combinations: |
Jacob Bramley | 59d74ae | 2017-01-18 15:27:45 +0000 | [diff] [blame] | 480 | if (args.dry_run): |
| 481 | for runtime_options in test_runtime_combinations: |
| 482 | print(' '.join(filter(None, environment_options)) + ', ' + |
| 483 | ' '.join(filter(None, build_options)) + ', ' + |
| 484 | ' '.join(filter(None, runtime_options))) |
| 485 | continue |
| 486 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 487 | # Avoid going through the build stage if we are not using the build |
| 488 | # result. |
| 489 | if not (args.notest and args.nobench): |
| 490 | build_rc = BuildAll(build_options, args.jobs) |
| 491 | # Don't run the tests for this configuration if the build failed. |
| 492 | if build_rc != 0: |
| 493 | rc |= build_rc |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 494 | MaybeExitEarly(rc) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 495 | continue |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 496 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 497 | # Use the realpath of the test executable so that the commands printed |
| 498 | # can be copy-pasted and run. |
Alexandre Rames | 81c76e6 | 2016-07-19 09:53:09 +0100 | [diff] [blame] | 499 | test_executable = util.relrealpath( |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 500 | join(config.dir_build_latest, 'test', 'test-runner')) |
| 501 | |
| 502 | if not args.notest: |
| 503 | printer.Print(test_executable) |
| 504 | |
| 505 | for runtime_options in test_runtime_combinations: |
| 506 | if not args.notest: |
| 507 | runtime_options = [x for x in runtime_options if x is not None] |
| 508 | prefix = ' ' + ' '.join(runtime_options) + ' ' |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame^] | 509 | tests.Add(test_executable, |
| 510 | args.filters, |
| 511 | list(runtime_options)) |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 512 | MaybeExitEarly(rc) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 513 | |
| 514 | if not args.nobench: |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 515 | rc |= RunBenchmarks(build_options, args) |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 516 | MaybeExitEarly(rc) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 517 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame^] | 518 | rc |= tests.Run(args.jobs) |
Jacob Bramley | 59d74ae | 2017-01-18 15:27:45 +0000 | [diff] [blame] | 519 | if not args.dry_run: |
| 520 | PrintStatus(rc == 0) |
Alexandre Rames | 7c0ea8b | 2016-05-18 13:47:42 +0100 | [diff] [blame] | 521 | |
| 522 | sys.exit(rc) |