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 |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 37 | import subprocess |
| 38 | import sys |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 39 | import time |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 40 | |
| 41 | import config |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 42 | import clang_format |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 43 | import lint |
| 44 | import printer |
| 45 | import test |
| 46 | import threaded_tests |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 47 | import util |
| 48 | |
| 49 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 50 | dir_root = config.dir_root |
| 51 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 52 | |
| 53 | # Remove duplicates from a list |
| 54 | def RemoveDuplicates(values): |
| 55 | # Convert the list into a set and back to list |
| 56 | # as sets guarantee items are unique. |
| 57 | return list(set(values)) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 58 | |
| 59 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 60 | # Custom argparse.Action to automatically add and handle an 'all' option. |
| 61 | # If no 'default' value is set, it will default to 'all. |
| 62 | # If accepted options are set using 'choices' then only these values will be |
| 63 | # allowed. |
| 64 | # If they're set using 'soft_choices' then 'all' will default to these values, |
| 65 | # but other values will also be accepted. |
| 66 | class AllChoiceAction(argparse.Action): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 67 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 68 | # At least one option was set by the user. |
| 69 | WasSetByUser = False |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 70 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 71 | def __init__(self, **kwargs): |
| 72 | if 'choices' in kwargs: |
| 73 | assert 'soft_choices' not in kwargs,\ |
| 74 | "Can't have both 'choices' and 'soft_choices' options" |
| 75 | self.all_choices = list(kwargs['choices']) |
| 76 | kwargs['choices'].append('all') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 77 | else: |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 78 | self.all_choices = kwargs['soft_choices'] |
| 79 | kwargs['help'] += ' Supported values: {' + ','.join( |
| 80 | ['all'] + self.all_choices) + '}' |
| 81 | del kwargs['soft_choices'] |
| 82 | if 'default' not in kwargs: |
| 83 | kwargs['default'] = self.all_choices |
| 84 | super(AllChoiceAction, self).__init__(**kwargs) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 85 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 86 | def __call__(self, parser, namespace, values, option_string=None): |
| 87 | AllChoiceAction.WasSetByUser = True |
| 88 | if 'all' in values: |
| 89 | # Substitute 'all' by the actual values. |
| 90 | values = self.all_choices + [value for value in values if value != 'all'] |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 91 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 92 | setattr(namespace, self.dest, RemoveDuplicates(values)) |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 93 | |
| 94 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 95 | def BuildOptions(): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 96 | args = argparse.ArgumentParser( |
| 97 | description = |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 98 | '''This tool runs all tests matching the specified filters for multiple |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 99 | environment, build options, and runtime options configurations.''', |
| 100 | # Print default values. |
| 101 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 102 | |
| 103 | args.add_argument('filters', metavar='filter', nargs='*', |
| 104 | help='Run tests matching all of the (regexp) filters.') |
| 105 | |
| 106 | # We automatically build the script options from the options to be tested. |
| 107 | test_arguments = args.add_argument_group( |
| 108 | 'Test options', |
| 109 | 'These options indicate what should be tested') |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 110 | test_arguments.add_argument( |
| 111 | '--negative_testing', |
| 112 | help='Tests with negative testing enabled.', |
| 113 | action='store_const', |
| 114 | const='on', |
| 115 | default='off') |
| 116 | test_arguments.add_argument( |
| 117 | '--compiler', |
| 118 | help='Test for the specified compilers.', |
| 119 | soft_choices=config.tested_compilers, |
| 120 | action=AllChoiceAction, |
| 121 | nargs="+") |
| 122 | test_arguments.add_argument( |
| 123 | '--mode', |
| 124 | help='Test with the specified build modes.', |
| 125 | choices=config.build_options_modes, |
| 126 | action=AllChoiceAction, |
| 127 | nargs="+") |
| 128 | test_arguments.add_argument( |
| 129 | '--std', |
| 130 | help='Test with the specified C++ standard.', |
| 131 | soft_choices=config.tested_cpp_standards, |
| 132 | action=AllChoiceAction, |
| 133 | nargs="+") |
| 134 | test_arguments.add_argument( |
| 135 | '--target', |
| 136 | help='Test with the specified isa enabled.', |
| 137 | soft_choices=config.build_options_target, |
| 138 | action=AllChoiceAction, |
| 139 | nargs="+") |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 140 | |
| 141 | general_arguments = args.add_argument_group('General options') |
Jacob Bramley | 59d74ae | 2017-01-18 15:27:45 +0000 | [diff] [blame] | 142 | general_arguments.add_argument('--dry-run', action='store_true', |
| 143 | help='''Don't actually build or run anything, |
| 144 | but print the configurations that would be |
| 145 | tested.''') |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame] | 146 | general_arguments.add_argument('--verbose', action='store_true', |
| 147 | help='''Print extra information.''') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 148 | general_arguments.add_argument( |
| 149 | '--jobs', '-j', metavar='N', type=int, nargs='?', |
Anthony Barbier | 9c4ba7a | 2019-02-15 15:20:25 +0000 | [diff] [blame] | 150 | default=multiprocessing.cpu_count(), |
| 151 | const=multiprocessing.cpu_count(), |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 152 | help='''Runs the tests using N jobs. If the option is set but no value is |
| 153 | provided, the script will use as many jobs as it thinks useful.''') |
Pierre Langlois | 44096c4 | 2018-05-23 23:15:25 +0100 | [diff] [blame] | 154 | general_arguments.add_argument('--clang-format', |
| 155 | default=clang_format.DEFAULT_CLANG_FORMAT, |
| 156 | help='Path to clang-format.') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 157 | general_arguments.add_argument('--nobench', action='store_true', |
| 158 | help='Do not run benchmarks.') |
| 159 | general_arguments.add_argument('--nolint', action='store_true', |
| 160 | help='Do not run the linter.') |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 161 | general_arguments.add_argument('--noclang-format', action='store_true', |
| 162 | help='Do not run clang-format.') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 163 | general_arguments.add_argument('--notest', action='store_true', |
| 164 | help='Do not run tests.') |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 165 | general_arguments.add_argument('--fail-early', action='store_true', |
| 166 | help='Exit as soon as a test fails.') |
armvixl | 684cd2a | 2015-10-23 13:38:33 +0100 | [diff] [blame] | 167 | general_arguments.add_argument( |
| 168 | '--under_valgrind', action='store_true', |
| 169 | help='''Run the test-runner commands under Valgrind. |
| 170 | Note that a few tests are known to fail because of |
| 171 | issues in Valgrind''') |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 172 | return args.parse_args() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 173 | |
| 174 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 175 | def RunCommand(command, environment_options = None): |
| 176 | # Create a copy of the environment. We do not want to pollute the environment |
| 177 | # of future commands run. |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 178 | environment = os.environ.copy() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 179 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 180 | printable_command = '' |
| 181 | if environment_options: |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 182 | # Add the environment options to the environment: |
| 183 | environment.update(environment_options) |
| 184 | printable_command += ' ' + DictToString(environment_options) + ' ' |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 185 | printable_command += ' '.join(command) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 186 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 187 | printable_command_orange = \ |
| 188 | printer.COLOUR_ORANGE + printable_command + printer.NO_COLOUR |
| 189 | printer.PrintOverwritableLine(printable_command_orange) |
| 190 | sys.stdout.flush() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 191 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 192 | # Start a process for the command. |
| 193 | # Interleave `stderr` and `stdout`. |
| 194 | p = subprocess.Popen(command, |
| 195 | stdout=subprocess.PIPE, |
| 196 | stderr=subprocess.STDOUT, |
| 197 | env=environment) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 198 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 199 | # We want to be able to display a continuously updated 'work indicator' while |
| 200 | # the process is running. Since the process can hang if the `stdout` pipe is |
| 201 | # full, we need to pull from it regularly. We cannot do so via the |
| 202 | # `readline()` function because it is blocking, and would thus cause the |
| 203 | # indicator to not be updated properly. So use file control mechanisms |
| 204 | # instead. |
| 205 | indicator = ' (still working: %d seconds elapsed)' |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 206 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 207 | # Mark the process output as non-blocking. |
| 208 | flags = fcntl.fcntl(p.stdout, fcntl.F_GETFL) |
| 209 | fcntl.fcntl(p.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK) |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 210 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 211 | t_start = time.time() |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 212 | t_current = t_start |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 213 | t_last_indication = t_start |
Anthony Barbier | 7b4df2b | 2019-03-12 17:36:15 +0000 | [diff] [blame] | 214 | t_current = t_start |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 215 | process_output = '' |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 216 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 217 | # Keep looping as long as the process is running. |
| 218 | while p.poll() is None: |
| 219 | # Avoid polling too often. |
| 220 | time.sleep(0.1) |
| 221 | # Update the progress indicator. |
| 222 | t_current = time.time() |
| 223 | if (t_current - t_start >= 2) and (t_current - t_last_indication >= 1): |
| 224 | printer.PrintOverwritableLine( |
| 225 | printable_command_orange + indicator % int(t_current - t_start)) |
| 226 | sys.stdout.flush() |
| 227 | t_last_indication = t_current |
| 228 | # Pull from the process output. |
| 229 | while True: |
| 230 | try: |
| 231 | line = os.read(p.stdout.fileno(), 1024) |
| 232 | except OSError: |
| 233 | line = '' |
| 234 | break |
| 235 | if line == '': break |
| 236 | process_output += line |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 237 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 238 | # The process has exited. Don't forget to retrieve the rest of its output. |
| 239 | out, err = p.communicate() |
| 240 | rc = p.poll() |
| 241 | process_output += out |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 242 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 243 | printable_command += ' (took %d seconds)' % int(t_current - t_start) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 244 | if rc == 0: |
| 245 | printer.Print(printer.COLOUR_GREEN + printable_command + printer.NO_COLOUR) |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 246 | else: |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 247 | printer.Print(printer.COLOUR_RED + printable_command + printer.NO_COLOUR) |
| 248 | printer.Print(process_output) |
| 249 | return rc |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 250 | |
| 251 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 252 | def RunLinter(jobs): |
Jacob Bramley | f89cb48 | 2019-06-28 15:53:18 +0100 | [diff] [blame^] | 253 | return lint.RunLinter(map(lambda x: join(dir_root, x), |
| 254 | util.get_source_files()), |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 255 | jobs = args.jobs, progress_prefix = 'cpp lint: ') |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 256 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 257 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 258 | def RunClangFormat(clang_path, jobs): |
Jacob Bramley | f89cb48 | 2019-06-28 15:53:18 +0100 | [diff] [blame^] | 259 | return clang_format.ClangFormatFiles(util.get_source_files(), |
| 260 | clang_path, |
| 261 | jobs = jobs, |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 262 | progress_prefix = 'clang-format: ') |
| 263 | |
| 264 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 265 | def BuildAll(build_options, jobs, environment_options): |
| 266 | scons_command = ['scons', '-C', dir_root, 'all', '-j', str(jobs)] |
Anthony Barbier | 9c4ba7a | 2019-02-15 15:20:25 +0000 | [diff] [blame] | 267 | if util.IsCommandAvailable('ccache'): |
| 268 | scons_command += ['compiler_wrapper=ccache'] |
| 269 | # Fixes warnings for ccache 3.3.1 and lower: |
| 270 | environment_options = environment_options.copy() |
| 271 | environment_options["CCACHE_CPP2"] = 'yes' |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 272 | scons_command += DictToString(build_options).split() |
| 273 | return RunCommand(scons_command, environment_options) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 274 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 275 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 276 | def CanRunAarch64(options, args): |
| 277 | for target in options['target']: |
| 278 | if target in ['aarch64', 'a64']: |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 279 | return True |
| 280 | |
| 281 | return False |
| 282 | |
| 283 | |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 284 | def CanRunAarch32(options, args): |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 285 | for target in options['target']: |
| 286 | if target in ['aarch32', 'a32', 't32']: |
| 287 | return True |
| 288 | return False |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 289 | |
| 290 | |
| 291 | def RunBenchmarks(options, args): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 292 | rc = 0 |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 293 | if CanRunAarch32(options, args): |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 294 | benchmark_names = util.ListCCFilesWithoutExt(config.dir_aarch32_benchmarks) |
| 295 | for bench in benchmark_names: |
| 296 | rc |= RunCommand( |
| 297 | [os.path.realpath( |
Martyn Capewell | 9cd420f | 2017-05-12 20:30:23 +0100 | [diff] [blame] | 298 | join(config.dir_build_latest, 'benchmarks/aarch32', bench)), '10']) |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 299 | if CanRunAarch64(options, args): |
Pierre Langlois | 1c1488c | 2016-12-14 18:16:44 +0000 | [diff] [blame] | 300 | benchmark_names = util.ListCCFilesWithoutExt(config.dir_aarch64_benchmarks) |
| 301 | for bench in benchmark_names: |
| 302 | rc |= RunCommand( |
| 303 | [util.relrealpath( |
Martyn Capewell | 9cd420f | 2017-05-12 20:30:23 +0100 | [diff] [blame] | 304 | join(config.dir_build_latest, |
| 305 | 'benchmarks/aarch64', bench)), '10']) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 306 | return rc |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 307 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 308 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 309 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 310 | # It is a precommit run if the user did not specify any of the |
| 311 | # options that would affect the automatically generated combinations. |
| 312 | def IsPrecommitRun(args): |
| 313 | return args.negative_testing == "off" and not AllChoiceAction.WasSetByUser |
| 314 | |
| 315 | # Generate a list of all the possible combinations of the passed list: |
| 316 | # ListCombinations( a = [a0, a1], b = [b0, b1] ) will return |
| 317 | # [ {a : a0, b : b0}, {a : a0, b : b1}, {a: a1, b : b0}, {a : a1, b : b1}] |
| 318 | def ListCombinations(**kwargs): |
| 319 | # End of recursion: no options passed |
| 320 | if not kwargs: |
| 321 | return [{}] |
| 322 | option, values = kwargs.popitem() |
| 323 | configs = ListCombinations(**kwargs) |
| 324 | retval = [] |
| 325 | if not isinstance(values, list): |
| 326 | values = [values] |
| 327 | for value in values: |
| 328 | for config in configs: |
| 329 | new_config = config.copy() |
| 330 | new_config[option] = value |
| 331 | retval.append(new_config) |
| 332 | return retval |
| 333 | |
| 334 | # Convert a dictionary into a space separated string |
| 335 | # {a : a0, b : b0} --> "a=a0 b=b0" |
| 336 | def DictToString(options): |
| 337 | return " ".join( |
| 338 | ["{}={}".format(option, value) for option, value in options.items()]) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 339 | |
| 340 | |
| 341 | if __name__ == '__main__': |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 342 | util.require_program('scons') |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 343 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 344 | args = BuildOptions() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 345 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 346 | rc = util.ReturnCode(args.fail_early, printer.Print) |
Alexandre Rames | 73064a2 | 2016-07-08 09:17:03 +0100 | [diff] [blame] | 347 | |
armvixl | 684cd2a | 2015-10-23 13:38:33 +0100 | [diff] [blame] | 348 | if args.under_valgrind: |
| 349 | util.require_program('valgrind') |
| 350 | |
Anthony Barbier | b5f7239 | 2019-02-15 15:33:48 +0000 | [diff] [blame] | 351 | tests = threaded_tests.TestQueue(args.under_valgrind) |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 352 | if not args.nolint and not args.dry_run: |
| 353 | rc.Combine(RunLinter(args.jobs)) |
Jacob Bramley | 59d74ae | 2017-01-18 15:27:45 +0000 | [diff] [blame] | 354 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 355 | if not args.noclang_format and not args.dry_run: |
| 356 | rc.Combine(RunClangFormat(args.clang_format, args.jobs)) |
| 357 | |
| 358 | list_options = [] |
| 359 | if IsPrecommitRun(args): |
| 360 | # Maximize the coverage for precommit testing. |
| 361 | |
Pierre Langlois | a5b3cef | 2019-01-28 11:30:38 +0000 | [diff] [blame] | 362 | # Debug builds with negative testing and all targets enabled. |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 363 | list_options += ListCombinations( |
| 364 | compiler = args.compiler, |
| 365 | negative_testing = 'on', |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 366 | mode = 'debug', |
| 367 | target = 'a64,a32,t32') |
| 368 | |
| 369 | # Release builds with all targets enabled. |
| 370 | list_options += ListCombinations( |
| 371 | compiler = args.compiler, |
| 372 | negative_testing = 'off', |
| 373 | std = args.std, |
| 374 | mode = 'release', |
| 375 | target = 'a64,a32,t32') |
| 376 | |
| 377 | # c++98 builds for Thumb32 target only. |
| 378 | list_options += ListCombinations( |
| 379 | compiler = args.compiler, |
| 380 | negative_testing = 'off', |
| 381 | std = 'c++98', |
| 382 | mode = args.mode, |
| 383 | target = 't32') |
| 384 | |
| 385 | # c++11 builds for Aarch64 target only. |
| 386 | list_options += ListCombinations( |
| 387 | compiler = args.compiler, |
| 388 | negative_testing = 'off', |
| 389 | std = 'c++11', |
| 390 | mode = args.mode, |
| 391 | target = 'a64') |
| 392 | else: |
| 393 | list_options = ListCombinations( |
| 394 | compiler = args.compiler, |
| 395 | negative_testing = args.negative_testing, |
| 396 | std = args.std, |
| 397 | mode = args.mode, |
| 398 | target = args.target) |
| 399 | |
| 400 | for options in list_options: |
| 401 | if (args.dry_run): |
| 402 | print(DictToString(options)) |
| 403 | continue |
| 404 | # Convert 'compiler' into an environment variable: |
| 405 | environment_options = {'CXX': options['compiler']} |
| 406 | del options['compiler'] |
| 407 | |
| 408 | # Avoid going through the build stage if we are not using the build |
| 409 | # result. |
| 410 | if not (args.notest and args.nobench): |
| 411 | build_rc = BuildAll(options, args.jobs, environment_options) |
| 412 | # Don't run the tests for this configuration if the build failed. |
| 413 | if build_rc != 0: |
| 414 | rc.Combine(build_rc) |
| 415 | continue |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 416 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 417 | # Use the realpath of the test executable so that the commands printed |
| 418 | # can be copy-pasted and run. |
Alexandre Rames | 81c76e6 | 2016-07-19 09:53:09 +0100 | [diff] [blame] | 419 | test_executable = util.relrealpath( |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 420 | join(config.dir_build_latest, 'test', 'test-runner')) |
| 421 | |
| 422 | if not args.notest: |
| 423 | printer.Print(test_executable) |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 424 | tests.Add( |
| 425 | test_executable, |
| 426 | args.filters, |
| 427 | list()) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 428 | |
| 429 | if not args.nobench: |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 430 | rc.Combine(RunBenchmarks(options, args)) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 431 | |
Anthony Barbier | 88e1d03 | 2019-06-13 15:20:20 +0100 | [diff] [blame] | 432 | rc.Combine(tests.Run(args.jobs, args.verbose)) |
Jacob Bramley | 59d74ae | 2017-01-18 15:27:45 +0000 | [diff] [blame] | 433 | if not args.dry_run: |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 434 | rc.PrintStatus() |
Alexandre Rames | 7c0ea8b | 2016-05-18 13:47:42 +0100 | [diff] [blame] | 435 | |
Anthony Barbier | f2986e1 | 2019-02-28 16:49:23 +0000 | [diff] [blame] | 436 | sys.exit(rc.Value) |