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) |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame^] | 163 | build_option_target_arch = \ |
| 164 | BuildOption('target_arch', 'Test with the specified architectures enabled.', |
| 165 | val_test_choices=['all'] + config.build_options_target_arch, |
| 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, |
| 174 | build_option_target_arch, |
| 175 | build_option_negative_testing |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 176 | ] |
| 177 | |
| 178 | runtime_option_debugger = \ |
| 179 | RuntimeOption('debugger', |
| 180 | '''Test with the specified configurations for the debugger. |
| 181 | Note that this is only tested if we are using the simulator.''', |
| 182 | val_test_choices=['all', 'on', 'off']) |
| 183 | test_runtime_options = [ |
| 184 | runtime_option_debugger |
| 185 | ] |
| 186 | |
| 187 | test_options = \ |
| 188 | test_environment_options + test_build_options + test_runtime_options |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 189 | |
| 190 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 191 | def BuildOptions(): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 192 | args = argparse.ArgumentParser( |
| 193 | description = |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 194 | '''This tool runs all tests matching the specified filters for multiple |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 195 | environment, build options, and runtime options configurations.''', |
| 196 | # Print default values. |
| 197 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 198 | |
| 199 | args.add_argument('filters', metavar='filter', nargs='*', |
| 200 | help='Run tests matching all of the (regexp) filters.') |
| 201 | |
| 202 | # We automatically build the script options from the options to be tested. |
| 203 | test_arguments = args.add_argument_group( |
| 204 | 'Test options', |
| 205 | 'These options indicate what should be tested') |
| 206 | for option in test_options: |
| 207 | choices = option.val_test_choices if option.strict_choices else None |
| 208 | help = option.help |
| 209 | if not option.strict_choices: |
| 210 | help += ' Supported values: {' + ','.join(option.val_test_choices) + '}' |
| 211 | test_arguments.add_argument(Optionify(option.name), |
| 212 | nargs='+', |
| 213 | choices=choices, |
| 214 | default=option.val_test_default, |
| 215 | help=help, |
| 216 | action='store') |
| 217 | |
| 218 | general_arguments = args.add_argument_group('General options') |
| 219 | general_arguments.add_argument('--fast', action='store_true', |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 220 | help='''Skip the lint and clang-format tests, |
| 221 | and run only with one compiler, in one mode, |
| 222 | with one C++ standard, and with an appropriate |
Alexandre Rames | dd7de86 | 2016-07-06 13:56:11 +0100 | [diff] [blame] | 223 | default for runtime options.''') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 224 | general_arguments.add_argument( |
| 225 | '--jobs', '-j', metavar='N', type=int, nargs='?', |
| 226 | default=multiprocessing.cpu_count(), |
| 227 | const=multiprocessing.cpu_count(), |
| 228 | help='''Runs the tests using N jobs. If the option is set but no value is |
| 229 | provided, the script will use as many jobs as it thinks useful.''') |
| 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 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 325 | if rc == 0: |
| 326 | printer.Print(printer.COLOUR_GREEN + printable_command + printer.NO_COLOUR) |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 327 | else: |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 328 | printer.Print(printer.COLOUR_RED + printable_command + printer.NO_COLOUR) |
| 329 | printer.Print(process_output) |
| 330 | return rc |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 331 | |
| 332 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 333 | def RunLinter(): |
Alexandre Rames | b274662 | 2016-07-11 16:12:39 +0100 | [diff] [blame] | 334 | rc, default_tracked_files = lint.GetDefaultFilesToLint() |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 335 | if rc: |
| 336 | return rc |
Alexandre Rames | b274662 | 2016-07-11 16:12:39 +0100 | [diff] [blame] | 337 | return lint.RunLinter(map(lambda x: join(dir_root, x), default_tracked_files), |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 338 | jobs = args.jobs, progress_prefix = 'cpp lint: ') |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 339 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 340 | |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 341 | def RunClangFormat(): |
| 342 | return clang_format.ClangFormatFiles(clang_format.GetCppSourceFilesToFormat(), |
| 343 | jobs = args.jobs, |
| 344 | progress_prefix = 'clang-format: ') |
| 345 | |
| 346 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 347 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 348 | def BuildAll(build_options, jobs): |
| 349 | scons_command = ["scons", "-C", dir_root, 'all', '-j', str(jobs)] |
| 350 | scons_command += list(build_options) |
| 351 | return RunCommand(scons_command, list(environment_options)) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 352 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 353 | |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame^] | 354 | def RunBenchmarks(args): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 355 | rc = 0 |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame^] | 356 | if args.target_arch in ['both', 'aarch32']: |
| 357 | benchmark_names = util.ListCCFilesWithoutExt(config.dir_aarch32_benchmarks) |
| 358 | for bench in benchmark_names: |
| 359 | rc |= RunCommand( |
| 360 | [os.path.realpath( |
Vincent Belliard | 32cf254 | 2016-07-14 10:04:09 -0700 | [diff] [blame] | 361 | join(config.dir_build_latest, 'benchmarks/aarch32', bench))]) |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame^] | 362 | if args.target_arch in ['both', 'aarch64']: |
| 363 | benchmark_names = util.ListCCFilesWithoutExt(config.dir_aarch64_benchmarks) |
| 364 | for bench in benchmark_names: |
| 365 | rc |= RunCommand( |
| 366 | [util.relrealpath( |
| 367 | join(config.dir_build_latest, 'benchmarks/aarch64', bench))]) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 368 | return rc |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 369 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 370 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 371 | def PrintStatus(success): |
| 372 | printer.Print('\n$ ' + ' '.join(sys.argv)) |
| 373 | if success: |
| 374 | printer.Print('SUCCESS') |
| 375 | else: |
| 376 | printer.Print('FAILURE') |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 377 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 378 | |
| 379 | |
| 380 | if __name__ == '__main__': |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 381 | util.require_program('scons') |
| 382 | rc = 0 |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 383 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 384 | args = BuildOptions() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 385 | |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 386 | def MaybeExitEarly(rc): |
| 387 | if args.fail_early and rc != 0: |
| 388 | PrintStatus(rc == 0) |
| 389 | sys.exit(rc) |
| 390 | |
armvixl | 684cd2a | 2015-10-23 13:38:33 +0100 | [diff] [blame] | 391 | if args.under_valgrind: |
| 392 | util.require_program('valgrind') |
| 393 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 394 | if args.fast: |
| 395 | def SetFast(option, specified, default): |
| 396 | option.val_test_choices = \ |
Alexandre Rames | dd7de86 | 2016-07-06 13:56:11 +0100 | [diff] [blame] | 397 | [default if specified == 'all' else specified[0]] |
| 398 | # `g++` is very slow to compile a few aarch32 test files. |
| 399 | SetFast(environment_option_compiler, args.compiler, 'clang++') |
| 400 | SetFast(build_option_standard, args.std, 'c++98') |
| 401 | SetFast(build_option_mode, args.mode, 'debug') |
| 402 | SetFast(runtime_option_debugger, args.debugger, 'on') |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 403 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 404 | if not args.nolint and not args.fast: |
| 405 | rc |= RunLinter() |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 406 | MaybeExitEarly(rc) |
| 407 | |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 408 | if not args.noclang_format and not args.fast: |
| 409 | rc |= RunClangFormat() |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 410 | MaybeExitEarly(rc) |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 411 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 412 | # Don't try to test the debugger if we are not running with the simulator. |
| 413 | if not args.simulator: |
| 414 | test_runtime_options = \ |
| 415 | filter(lambda x: x.name != 'debugger', test_runtime_options) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 416 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 417 | # List all combinations of options that will be tested. |
| 418 | def ListCombinations(args, options): |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame^] | 419 | opts_list = [ |
| 420 | opt.ArgList(args.__dict__[opt.name]) |
| 421 | for opt in options |
| 422 | if not opt.test_independently |
| 423 | ] |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 424 | return list(itertools.product(*opts_list)) |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame^] | 425 | # List combinations of options that should only be tested independently. |
| 426 | def ListIndependentCombinations(args, options): |
| 427 | n = [] |
| 428 | for opt in options: |
| 429 | if opt.test_independently: |
| 430 | for o in opt.ArgList(args.__dict__[opt.name]): |
| 431 | n.append((o,)) |
| 432 | return n |
Georgia Kouveli | 38d5d1b | 2016-11-16 11:58:41 +0000 | [diff] [blame] | 433 | # TODO: We should refine the configurations we test by default, instead of |
| 434 | # always testing all possible combinations. |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 435 | test_env_combinations = ListCombinations(args, test_environment_options) |
| 436 | test_build_combinations = ListCombinations(args, test_build_options) |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame^] | 437 | test_build_combinations.extend(ListIndependentCombinations(args, test_build_options)) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 438 | test_runtime_combinations = ListCombinations(args, test_runtime_options) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 439 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 440 | for environment_options in test_env_combinations: |
| 441 | for build_options in test_build_combinations: |
| 442 | # Avoid going through the build stage if we are not using the build |
| 443 | # result. |
| 444 | if not (args.notest and args.nobench): |
| 445 | build_rc = BuildAll(build_options, args.jobs) |
| 446 | # Don't run the tests for this configuration if the build failed. |
| 447 | if build_rc != 0: |
| 448 | rc |= build_rc |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 449 | MaybeExitEarly(rc) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 450 | continue |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 451 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 452 | # Use the realpath of the test executable so that the commands printed |
| 453 | # can be copy-pasted and run. |
Alexandre Rames | 81c76e6 | 2016-07-19 09:53:09 +0100 | [diff] [blame] | 454 | test_executable = util.relrealpath( |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 455 | join(config.dir_build_latest, 'test', 'test-runner')) |
| 456 | |
| 457 | if not args.notest: |
| 458 | printer.Print(test_executable) |
| 459 | |
| 460 | for runtime_options in test_runtime_combinations: |
| 461 | if not args.notest: |
| 462 | runtime_options = [x for x in runtime_options if x is not None] |
| 463 | prefix = ' ' + ' '.join(runtime_options) + ' ' |
| 464 | rc |= threaded_tests.RunTests(test_executable, |
| 465 | args.filters, |
| 466 | list(runtime_options), |
armvixl | 684cd2a | 2015-10-23 13:38:33 +0100 | [diff] [blame] | 467 | args.under_valgrind, |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 468 | jobs = args.jobs, prefix = prefix) |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 469 | MaybeExitEarly(rc) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 470 | |
| 471 | if not args.nobench: |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame^] | 472 | rc |= RunBenchmarks(args) |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 473 | MaybeExitEarly(rc) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 474 | |
| 475 | PrintStatus(rc == 0) |
Alexandre Rames | 7c0ea8b | 2016-05-18 13:47:42 +0100 | [diff] [blame] | 476 | |
| 477 | sys.exit(rc) |