blob: 540acd8b4ed28481e0bde35792765bb275f9efed [file] [log] [blame]
Shubham Ajmerafe793492017-03-16 13:31:35 -07001#!/usr/bin/env python3
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00002#
3# Copyright 2017, The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""ART Run-Test TestRunner
18
19The testrunner runs the ART run-tests by simply invoking the script.
20It fetches the list of eligible tests from art/test directory, and list of
21disabled tests from art/test/knownfailures.json. It runs the tests by
22invoking art/test/run-test script and checks the exit value to decide if the
23test passed or failed.
24
25Before invoking the script, first build all the tests dependencies.
26There are two major build targets for building target and host tests
27dependencies:
281) test-art-host-run-test
292) test-art-target-run-test
30
31There are various options to invoke the script which are:
32-t: Either the test name as in art/test or the test name including the variant
33 information. Eg, "-t 001-HelloWorld",
34 "-t test-art-host-run-test-debug-prebuild-optimizing-relocate-ntrace-cms-checkjni-picimage-npictest-ndebuggable-001-HelloWorld32"
35-j: Number of thread workers to be used. Eg - "-j64"
36--dry-run: Instead of running the test name, just print its name.
37--verbose
38-b / --build-dependencies: to build the dependencies before running the test
39
40To specify any specific variants for the test, use --<<variant-name>>.
41For eg, for compiler type as optimizing, use --optimizing.
42
43
44In the end, the script will print the failed and skipped tests if any.
45
46"""
Alex Light7a1ccf82017-02-21 09:52:34 -080047import argparse
Shubham Ajmera85853952017-08-29 16:26:21 -070048import collections
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000049import fnmatch
50import itertools
51import json
Shubham Ajmera4a5a1622017-03-22 10:07:19 -070052import multiprocessing
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000053import os
54import re
55import subprocess
56import sys
Shubham Ajmera29f89682017-03-24 14:44:10 -070057import tempfile
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000058import threading
59import time
60
61import env
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -080062from target_config import target_config
Alex Light3412a002017-10-20 13:44:40 +000063from device_config import device_config
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000064
Shubham Ajmera186d3212017-07-21 01:20:57 +000065# timeout for individual tests.
66# TODO: make it adjustable per tests and for buildbots
67timeout = 3000 # 50 minutes
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000068
69# DISABLED_TEST_CONTAINER holds information about the disabled tests. It is a map
70# that has key as the test name (like 001-HelloWorld), and value as set of
71# variants that the test is disabled for.
72DISABLED_TEST_CONTAINER = {}
73
74# The Dict contains the list of all possible variants for a given type. For example,
75# for key TARGET, the value would be target and host. The list is used to parse
76# the test name given as the argument to run.
77VARIANT_TYPE_DICT = {}
78
79# The set contains all the variants of each time.
80TOTAL_VARIANTS_SET = set()
81
82# The colors are used in the output. When a test passes, COLOR_PASS is used,
83# and so on.
84COLOR_ERROR = '\033[91m'
85COLOR_PASS = '\033[92m'
86COLOR_SKIP = '\033[93m'
87COLOR_NORMAL = '\033[0m'
88
89# The mutex object is used by the threads for exclusive access of test_count
90# to make any changes in its value.
91test_count_mutex = threading.Lock()
Shubham Ajmera14d340c2017-02-15 18:49:10 +000092
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000093# The set contains the list of all the possible run tests that are in art/test
94# directory.
95RUN_TEST_SET = set()
Shubham Ajmera14d340c2017-02-15 18:49:10 +000096
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000097# The semaphore object is used by the testrunner to limit the number of
98# threads to the user requested concurrency value.
99semaphore = threading.Semaphore(1)
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000100
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000101# The mutex object is used to provide exclusive access to a thread to print
102# its output.
103print_mutex = threading.Lock()
104failed_tests = []
105skipped_tests = []
106
107# Flags
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700108n_thread = -1
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000109test_count = 0
110total_test_count = 0
111verbose = False
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000112dry_run = False
Alex Light42242dd2018-02-16 09:23:57 -0800113ignore_skips = False
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000114build = False
115gdb = False
116gdb_arg = ''
Vladimir Marko41b1f0e2018-03-21 11:17:12 +0000117runtime_option = ''
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000118stop_testrunner = False
Shubham Ajmera981d99c2017-08-17 14:11:08 -0700119dex2oat_jobs = -1 # -1 corresponds to default threads for dex2oat
Shubham Ajmera42ea83b2017-09-25 21:05:57 -0700120run_all_configs = False
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000121
Alex Light3412a002017-10-20 13:44:40 +0000122# Dict containing extra arguments
123extra_arguments = { "host" : [], "target" : [] }
124
Shubham Ajmera85853952017-08-29 16:26:21 -0700125# Dict to store user requested test variants.
126# key: variant_type.
127# value: set of variants user wants to run of type <key>.
128_user_input_variants = collections.defaultdict(set)
129
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000130def gather_test_info():
131 """The method gathers test information about the test to be run which includes
132 generating the list of total tests from the art/test directory and the list
133 of disabled test. It also maps various variants to types.
134 """
135 global TOTAL_VARIANTS_SET
136 global DISABLED_TEST_CONTAINER
137 # TODO: Avoid duplication of the variant names in different lists.
138 VARIANT_TYPE_DICT['pictest'] = {'pictest', 'npictest'}
139 VARIANT_TYPE_DICT['run'] = {'ndebug', 'debug'}
Igor Murashkinbab15062018-02-23 14:53:24 -0800140 VARIANT_TYPE_DICT['target'] = {'target', 'host', 'jvm'}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000141 VARIANT_TYPE_DICT['trace'] = {'trace', 'ntrace', 'stream'}
Richard Uhlerbb00f812017-02-16 14:21:10 +0000142 VARIANT_TYPE_DICT['image'] = {'picimage', 'no-image', 'multipicimage'}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000143 VARIANT_TYPE_DICT['debuggable'] = {'ndebuggable', 'debuggable'}
144 VARIANT_TYPE_DICT['gc'] = {'gcstress', 'gcverify', 'cms'}
145 VARIANT_TYPE_DICT['prebuild'] = {'no-prebuild', 'no-dex2oat', 'prebuild'}
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800146 VARIANT_TYPE_DICT['cdex_level'] = {'cdex-none', 'cdex-fast'}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000147 VARIANT_TYPE_DICT['relocate'] = {'relocate-npatchoat', 'relocate', 'no-relocate'}
148 VARIANT_TYPE_DICT['jni'] = {'jni', 'forcecopy', 'checkjni'}
149 VARIANT_TYPE_DICT['address_sizes'] = {'64', '32'}
Alex Light43e935d2017-06-19 15:40:40 -0700150 VARIANT_TYPE_DICT['jvmti'] = {'no-jvmti', 'jvmti-stress', 'redefine-stress', 'trace-stress',
Alex Lightc38c3692017-06-27 15:45:14 -0700151 'field-stress', 'step-stress'}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000152 VARIANT_TYPE_DICT['compiler'] = {'interp-ac', 'interpreter', 'jit', 'optimizing',
Shubham Ajmera85853952017-08-29 16:26:21 -0700153 'regalloc_gc', 'speed-profile'}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000154
155 for v_type in VARIANT_TYPE_DICT:
156 TOTAL_VARIANTS_SET = TOTAL_VARIANTS_SET.union(VARIANT_TYPE_DICT.get(v_type))
157
158 test_dir = env.ANDROID_BUILD_TOP + '/art/test'
159 for f in os.listdir(test_dir):
160 if fnmatch.fnmatch(f, '[0-9]*'):
161 RUN_TEST_SET.add(f)
162 DISABLED_TEST_CONTAINER = get_disabled_test_info()
163
164
165def setup_test_env():
166 """The method sets default value for the various variants of the tests if they
167 are already not set.
168 """
169 if env.ART_TEST_BISECTION:
170 env.ART_TEST_RUN_TEST_NO_PREBUILD = True
171 env.ART_TEST_RUN_TEST_PREBUILD = False
172 # Bisection search writes to standard output.
173 env.ART_TEST_QUIET = False
174
Shubham Ajmera42ea83b2017-09-25 21:05:57 -0700175 global _user_input_variants
176 global run_all_configs
Alex Lighta90c68c2018-03-26 14:50:24 -0700177 # These are the default variant-options we will use if nothing in the group is specified.
178 default_variants = {
179 'target': {'host', 'target'},
180 'pictest': {'npictest'},
181 'prebuild': {'prebuild'},
182 'cdex_level': {'cdex-fast'},
183 'jvmti': { 'no-jvmti'},
184 'compiler': {'optimizing',
185 'jit',
186 'interpreter',
187 'interp-ac',
188 'speed-profile'},
189 'relocate': {'no-relocate'},
190 'trace': {'ntrace'},
191 'gc': {'cms'},
192 'jni': {'checkjni'},
193 'image': {'picimage'},
194 'pictest': {'pictest'},
195 'debuggable': {'ndebuggable'},
196 'run': {'debug'},
197 # address_sizes_target depends on the target so it is dealt with below.
198 }
199 # We want to pull these early since the full VARIANT_TYPE_DICT has a few additional ones we don't
200 # want to pick up if we pass --all.
201 default_variants_keys = default_variants.keys()
Shubham Ajmera42ea83b2017-09-25 21:05:57 -0700202 if run_all_configs:
Alex Lighta90c68c2018-03-26 14:50:24 -0700203 default_variants = VARIANT_TYPE_DICT
Shubham Ajmera42ea83b2017-09-25 21:05:57 -0700204
Alex Lighta90c68c2018-03-26 14:50:24 -0700205 for key in default_variants_keys:
206 if not _user_input_variants[key]:
207 _user_input_variants[key] = default_variants[key]
Shubham Ajmerad0358f82017-09-25 20:57:32 -0700208
Shubham Ajmera85853952017-08-29 16:26:21 -0700209 _user_input_variants['address_sizes_target'] = collections.defaultdict(set)
210 if not _user_input_variants['address_sizes']:
211 _user_input_variants['address_sizes_target']['target'].add(
212 env.ART_PHONY_TEST_TARGET_SUFFIX)
213 _user_input_variants['address_sizes_target']['host'].add(
214 env.ART_PHONY_TEST_HOST_SUFFIX)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000215 if env.ART_TEST_RUN_TEST_2ND_ARCH:
Shubham Ajmera85853952017-08-29 16:26:21 -0700216 _user_input_variants['address_sizes_target']['host'].add(
217 env.ART_2ND_PHONY_TEST_HOST_SUFFIX)
218 _user_input_variants['address_sizes_target']['target'].add(
219 env.ART_2ND_PHONY_TEST_TARGET_SUFFIX)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000220 else:
Shubham Ajmera85853952017-08-29 16:26:21 -0700221 _user_input_variants['address_sizes_target']['host'] = _user_input_variants['address_sizes']
222 _user_input_variants['address_sizes_target']['target'] = _user_input_variants['address_sizes']
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000223
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700224 global n_thread
225 if n_thread is -1:
Shubham Ajmera85853952017-08-29 16:26:21 -0700226 if 'target' in _user_input_variants['target']:
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700227 n_thread = get_default_threads('target')
228 else:
229 n_thread = get_default_threads('host')
Shubham Ajmera93857f22017-10-09 13:47:35 -0700230 print_text("Concurrency: " + str(n_thread) + "\n")
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700231
Alex Light3412a002017-10-20 13:44:40 +0000232 global extra_arguments
233 for target in _user_input_variants['target']:
234 extra_arguments[target] = find_extra_device_arguments(target)
235
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000236 global semaphore
237 semaphore = threading.Semaphore(n_thread)
238
Shubham Ajmera22499e22017-03-22 18:33:37 -0700239 if not sys.stdout.isatty():
240 global COLOR_ERROR
241 global COLOR_PASS
242 global COLOR_SKIP
243 global COLOR_NORMAL
244 COLOR_ERROR = ''
245 COLOR_PASS = ''
246 COLOR_SKIP = ''
247 COLOR_NORMAL = ''
248
Alex Light3412a002017-10-20 13:44:40 +0000249def find_extra_device_arguments(target):
250 """
251 Gets any extra arguments from the device_config.
252 """
Igor Murashkinbab15062018-02-23 14:53:24 -0800253 device_name = target
254 if target == 'target':
255 device_name = get_device_name()
256 return device_config.get(device_name, { 'run-test-args' : [] })['run-test-args']
Alex Light3412a002017-10-20 13:44:40 +0000257
258def get_device_name():
259 """
260 Gets the value of ro.product.name from remote device.
261 """
262 proc = subprocess.Popen(['adb', 'shell', 'getprop', 'ro.product.name'],
263 stderr=subprocess.STDOUT,
264 stdout = subprocess.PIPE,
265 universal_newlines=True)
266 # only wait 2 seconds.
267 output = proc.communicate(timeout = 2)[0]
268 success = not proc.wait()
269 if success:
270 return output.strip()
271 else:
272 print_text("Unable to determine device type!\n")
273 print_text("Continuing anyway.\n")
274 return "UNKNOWN_TARGET"
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000275
276def run_tests(tests):
277 """Creates thread workers to run the tests.
278
279 The method generates command and thread worker to run the tests. Depending on
280 the user input for the number of threads to be used, the method uses a
281 semaphore object to keep a count in control for the thread workers. When a new
282 worker is created, it acquires the semaphore object, and when the number of
283 workers reaches the maximum allowed concurrency, the method wait for an
284 existing thread worker to release the semaphore object. Worker releases the
285 semaphore object when they finish printing the output.
286
287 Args:
288 tests: The set of tests to be run.
289 """
290 options_all = ''
Igor Murashkinbab15062018-02-23 14:53:24 -0800291
292 # jvm does not run with all these combinations,
293 # or at least it doesn't make sense for most of them.
294 # TODO: support some jvm variants like jvmti ?
295 target_input_variants = _user_input_variants['target']
296 uncombinated_target_input_variants = []
297 if 'jvm' in target_input_variants:
298 _user_input_variants['target'].remove('jvm')
299 uncombinated_target_input_variants.append('jvm')
300
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000301 global total_test_count
302 total_test_count = len(tests)
Igor Murashkinbab15062018-02-23 14:53:24 -0800303 if target_input_variants:
304 for variant_type in VARIANT_TYPE_DICT:
305 if not (variant_type == 'target' or 'address_sizes' in variant_type):
306 total_test_count *= len(_user_input_variants[variant_type])
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000307 target_address_combinations = 0
Igor Murashkinbab15062018-02-23 14:53:24 -0800308 for target in target_input_variants:
Shubham Ajmera85853952017-08-29 16:26:21 -0700309 for address_size in _user_input_variants['address_sizes_target'][target]:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000310 target_address_combinations += 1
Igor Murashkinbab15062018-02-23 14:53:24 -0800311 target_address_combinations += len(uncombinated_target_input_variants)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000312 total_test_count *= target_address_combinations
313
314 if env.ART_TEST_WITH_STRACE:
315 options_all += ' --strace'
316
317 if env.ART_TEST_RUN_TEST_ALWAYS_CLEAN:
318 options_all += ' --always-clean'
319
320 if env.ART_TEST_BISECTION:
321 options_all += ' --bisection-search'
322
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000323 if gdb:
324 options_all += ' --gdb'
325 if gdb_arg:
326 options_all += ' --gdb-arg ' + gdb_arg
327
Vladimir Marko41b1f0e2018-03-21 11:17:12 +0000328 if runtime_option:
329 for opt in runtime_option:
330 options_all += ' --runtime-option ' + opt
331
Shubham Ajmera981d99c2017-08-17 14:11:08 -0700332 if dex2oat_jobs != -1:
333 options_all += ' --dex2oat-jobs ' + str(dex2oat_jobs)
334
Igor Murashkinbab15062018-02-23 14:53:24 -0800335 def iter_config(tests, input_variants, user_input_variants):
336 config = itertools.product(tests, input_variants, user_input_variants['run'],
337 user_input_variants['prebuild'], user_input_variants['compiler'],
338 user_input_variants['relocate'], user_input_variants['trace'],
339 user_input_variants['gc'], user_input_variants['jni'],
340 user_input_variants['image'], user_input_variants['pictest'],
341 user_input_variants['debuggable'], user_input_variants['jvmti'],
342 user_input_variants['cdex_level'])
343 return config
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000344
Igor Murashkinbab15062018-02-23 14:53:24 -0800345 # [--host, --target] combines with all the other user input variants.
346 config = iter_config(tests, target_input_variants, _user_input_variants)
347 # [--jvm] currently combines with nothing else. most of the extra flags we'd insert
348 # would be unrecognizable by the 'java' binary, so avoid inserting any extra flags for now.
349 uncombinated_config = iter_config(tests, uncombinated_target_input_variants, { 'run': [''],
350 'prebuild': [''], 'compiler': [''],
351 'relocate': [''], 'trace': [''],
352 'gc': [''], 'jni': [''],
353 'image': [''], 'pictest': [''],
354 'debuggable': [''], 'jvmti': [''],
355 'cdex_level': ['']})
356
357 def start_combination(config_tuple, address_size):
358 test, target, run, prebuild, compiler, relocate, trace, gc, \
359 jni, image, pictest, debuggable, jvmti, cdex_level = config_tuple
360
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000361 if stop_testrunner:
362 # When ART_TEST_KEEP_GOING is set to false, then as soon as a test
363 # fails, stop_testrunner is set to True. When this happens, the method
364 # stops creating any any thread and wait for all the exising threads
365 # to end.
366 while threading.active_count() > 2:
367 time.sleep(0.1)
368 return
Orion Hodson75a58dc2018-02-05 14:37:31 +0000369 # NB The order of components here should match the order of
370 # components in the regex parser in parse_test_name.
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000371 test_name = 'test-art-'
372 test_name += target + '-run-test-'
373 test_name += run + '-'
374 test_name += prebuild + '-'
375 test_name += compiler + '-'
376 test_name += relocate + '-'
377 test_name += trace + '-'
378 test_name += gc + '-'
379 test_name += jni + '-'
380 test_name += image + '-'
381 test_name += pictest + '-'
382 test_name += debuggable + '-'
Alex Light8f2c6d42017-04-10 16:27:35 -0700383 test_name += jvmti + '-'
Orion Hodson75a58dc2018-02-05 14:37:31 +0000384 test_name += cdex_level + '-'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000385 test_name += test
386 test_name += address_size
387
388 variant_set = {target, run, prebuild, compiler, relocate, trace, gc, jni,
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800389 image, pictest, debuggable, jvmti, cdex_level, address_size}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000390
391 options_test = options_all
392
393 if target == 'host':
394 options_test += ' --host'
Igor Murashkinbab15062018-02-23 14:53:24 -0800395 elif target == 'jvm':
396 options_test += ' --jvm'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000397
Roland Levillainb0633b22018-05-24 15:59:18 +0100398 # Honor ART_TEST_CHROOT and ART_TEST_ANDROID_ROOT, but only for target tests.
399 if target == 'target':
400 if env.ART_TEST_CHROOT:
401 options_test += ' --chroot ' + env.ART_TEST_CHROOT
402 if env.ART_TEST_ANDROID_ROOT:
403 options_test += ' --android-root ' + env.ART_TEST_ANDROID_ROOT
404
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000405 if run == 'ndebug':
406 options_test += ' -O'
407
408 if prebuild == 'prebuild':
409 options_test += ' --prebuild'
410 elif prebuild == 'no-prebuild':
411 options_test += ' --no-prebuild'
412 elif prebuild == 'no-dex2oat':
413 options_test += ' --no-prebuild --no-dex2oat'
414
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800415 # Add option and remove the cdex- prefix.
416 options_test += ' --compact-dex-level ' + cdex_level.replace('cdex-','')
417
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000418 if compiler == 'optimizing':
419 options_test += ' --optimizing'
420 elif compiler == 'regalloc_gc':
421 options_test += ' --optimizing -Xcompiler-option --register-allocation-strategy=graph-color'
422 elif compiler == 'interpreter':
423 options_test += ' --interpreter'
424 elif compiler == 'interp-ac':
425 options_test += ' --interpreter --verify-soft-fail'
426 elif compiler == 'jit':
427 options_test += ' --jit'
Jeff Hao002b9312017-03-27 16:23:08 -0700428 elif compiler == 'speed-profile':
429 options_test += ' --random-profile'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000430
431 if relocate == 'relocate':
432 options_test += ' --relocate'
433 elif relocate == 'no-relocate':
434 options_test += ' --no-relocate'
435 elif relocate == 'relocate-npatchoat':
436 options_test += ' --relocate --no-patchoat'
437
438 if trace == 'trace':
439 options_test += ' --trace'
440 elif trace == 'stream':
441 options_test += ' --trace --stream'
442
443 if gc == 'gcverify':
444 options_test += ' --gcverify'
445 elif gc == 'gcstress':
446 options_test += ' --gcstress'
447
448 if jni == 'forcecopy':
449 options_test += ' --runtime-option -Xjniopts:forcecopy'
450 elif jni == 'checkjni':
451 options_test += ' --runtime-option -Xcheck:jni'
452
453 if image == 'no-image':
454 options_test += ' --no-image'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000455 elif image == 'multipicimage':
456 options_test += ' --multi-image'
457
458 if pictest == 'pictest':
459 options_test += ' --pic-test'
460
461 if debuggable == 'debuggable':
462 options_test += ' --debuggable'
463
Alex Light8f2c6d42017-04-10 16:27:35 -0700464 if jvmti == 'jvmti-stress':
Alex Light43e935d2017-06-19 15:40:40 -0700465 options_test += ' --jvmti-trace-stress --jvmti-redefine-stress --jvmti-field-stress'
466 elif jvmti == 'field-stress':
467 options_test += ' --jvmti-field-stress'
Alex Lightb7edcda2017-04-27 13:20:31 -0700468 elif jvmti == 'trace-stress':
469 options_test += ' --jvmti-trace-stress'
470 elif jvmti == 'redefine-stress':
471 options_test += ' --jvmti-redefine-stress'
Alex Lightc38c3692017-06-27 15:45:14 -0700472 elif jvmti == 'step-stress':
473 options_test += ' --jvmti-step-stress'
Alex Light8f2c6d42017-04-10 16:27:35 -0700474
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000475 if address_size == '64':
476 options_test += ' --64'
477
478 if env.DEX2OAT_HOST_INSTRUCTION_SET_FEATURES:
479 options_test += ' --instruction-set-features' + env.DEX2OAT_HOST_INSTRUCTION_SET_FEATURES
480
481 elif address_size == '32':
482 if env.HOST_2ND_ARCH_PREFIX_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES:
483 options_test += ' --instruction-set-features ' + \
484 env.HOST_2ND_ARCH_PREFIX_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES
485
Shubham Ajmera29f89682017-03-24 14:44:10 -0700486 # TODO(http://36039166): This is a temporary solution to
487 # fix build breakages.
488 options_test = (' --output-path %s') % (
489 tempfile.mkdtemp(dir=env.ART_HOST_TEST_DIR)) + options_test
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000490
491 run_test_sh = env.ANDROID_BUILD_TOP + '/art/test/run-test'
Alex Light3412a002017-10-20 13:44:40 +0000492 command = ' '.join((run_test_sh, options_test, ' '.join(extra_arguments[target]), test))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000493
494 semaphore.acquire()
495 worker = threading.Thread(target=run_test, args=(command, test, variant_set, test_name))
496 worker.daemon = True
497 worker.start()
498
Igor Murashkinbab15062018-02-23 14:53:24 -0800499 for config_tuple in config:
500 target = config_tuple[1]
501 for address_size in _user_input_variants['address_sizes_target'][target]:
502 start_combination(config_tuple, address_size)
503
504 for config_tuple in uncombinated_config:
505 start_combination(config_tuple, "") # no address size
506
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000507 while threading.active_count() > 2:
508 time.sleep(0.1)
509
510
511def run_test(command, test, test_variant, test_name):
512 """Runs the test.
513
514 It invokes art/test/run-test script to run the test. The output of the script
515 is checked, and if it ends with "Succeeded!", it assumes that the tests
516 passed, otherwise, put it in the list of failed test. Before actually running
517 the test, it also checks if the test is placed in the list of disabled tests,
518 and if yes, it skips running it, and adds the test in the list of skipped
519 tests. The method uses print_text method to actually print the output. After
520 successfully running and capturing the output for the test, it releases the
521 semaphore object.
522
523 Args:
524 command: The command to be used to invoke the script
525 test: The name of the test without the variant information.
526 test_variant: The set of variant for the test.
527 test_name: The name of the test along with the variants.
528 """
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000529 global stop_testrunner
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000530 try:
531 if is_test_disabled(test, test_variant):
532 test_skipped = True
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000533 else:
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000534 test_skipped = False
Shubham Ajmerab4949f52017-05-08 13:52:46 -0700535 if gdb:
536 proc = subprocess.Popen(command.split(), stderr=subprocess.STDOUT, universal_newlines=True)
537 else:
538 proc = subprocess.Popen(command.split(), stderr=subprocess.STDOUT, stdout = subprocess.PIPE,
539 universal_newlines=True)
Shubham Ajmera186d3212017-07-21 01:20:57 +0000540 script_output = proc.communicate(timeout=timeout)[0]
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000541 test_passed = not proc.wait()
542
543 if not test_skipped:
544 if test_passed:
545 print_test_info(test_name, 'PASS')
546 else:
Alex Light1ebe6142017-10-03 15:00:10 -0700547 failed_tests.append((test_name, str(command) + "\n" + script_output))
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000548 if not env.ART_TEST_KEEP_GOING:
549 stop_testrunner = True
550 print_test_info(test_name, 'FAIL', ('%s\n%s') % (
551 command, script_output))
552 elif not dry_run:
553 print_test_info(test_name, 'SKIP')
554 skipped_tests.append(test_name)
555 else:
556 print_test_info(test_name, '')
Shubham Ajmerafe793492017-03-16 13:31:35 -0700557 except subprocess.TimeoutExpired as e:
Shubham Ajmera186d3212017-07-21 01:20:57 +0000558 failed_tests.append((test_name, 'Timed out in %d seconds' % timeout))
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700559 print_test_info(test_name, 'TIMEOUT', 'Timed out in %d seconds\n%s' % (
Shubham Ajmera186d3212017-07-21 01:20:57 +0000560 timeout, command))
Shubham Ajmerafe793492017-03-16 13:31:35 -0700561 except Exception as e:
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700562 failed_tests.append((test_name, str(e)))
563 print_test_info(test_name, 'FAIL',
564 ('%s\n%s\n\n') % (command, str(e)))
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000565 finally:
566 semaphore.release()
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000567
568
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000569def print_test_info(test_name, result, failed_test_info=""):
570 """Print the continous test information
571
572 If verbose is set to True, it continuously prints test status information
573 on a new line.
574 If verbose is set to False, it keeps on erasing test
575 information by overriding it with the latest test information. Also,
576 in this case it stictly makes sure that the information length doesn't
577 exceed the console width. It does so by shortening the test_name.
578
579 When a test fails, it prints the output of the run-test script and
580 command used to invoke the script. It doesn't override the failing
581 test information in either of the cases.
582 """
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000583
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000584 global test_count
585 info = ''
586 if not verbose:
587 # Without --verbose, the testrunner erases passing test info. It
588 # does that by overriding the printed text with white spaces all across
589 # the console width.
590 console_width = int(os.popen('stty size', 'r').read().split()[1])
591 info = '\r' + ' ' * console_width + '\r'
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000592 try:
593 print_mutex.acquire()
594 test_count += 1
595 percent = (test_count * 100) / total_test_count
596 progress_info = ('[ %d%% %d/%d ]') % (
597 percent,
598 test_count,
599 total_test_count)
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000600
Shubham Ajmerafe793492017-03-16 13:31:35 -0700601 if result == 'FAIL' or result == 'TIMEOUT':
Alex Light1ebe6142017-10-03 15:00:10 -0700602 if not verbose:
603 info += ('%s %s %s\n') % (
604 progress_info,
605 test_name,
606 COLOR_ERROR + result + COLOR_NORMAL)
607 else:
608 info += ('%s %s %s\n%s\n') % (
609 progress_info,
610 test_name,
611 COLOR_ERROR + result + COLOR_NORMAL,
612 failed_test_info)
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000613 else:
614 result_text = ''
615 if result == 'PASS':
616 result_text += COLOR_PASS + 'PASS' + COLOR_NORMAL
617 elif result == 'SKIP':
618 result_text += COLOR_SKIP + 'SKIP' + COLOR_NORMAL
619
620 if verbose:
621 info += ('%s %s %s\n') % (
622 progress_info,
623 test_name,
624 result_text)
625 else:
626 total_output_length = 2 # Two spaces
627 total_output_length += len(progress_info)
628 total_output_length += len(result)
629 allowed_test_length = console_width - total_output_length
630 test_name_len = len(test_name)
631 if allowed_test_length < test_name_len:
Shubham Ajmerafe793492017-03-16 13:31:35 -0700632 test_name = ('...%s') % (
633 test_name[-(allowed_test_length - 3):])
Alex Lightc14311c2017-02-23 17:02:46 -0800634 info += ('%s %s %s') % (
635 progress_info,
636 test_name,
637 result_text)
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000638 print_text(info)
Shubham Ajmerafe793492017-03-16 13:31:35 -0700639 except Exception as e:
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000640 print_text(('%s\n%s\n') % (test_name, str(e)))
641 failed_tests.append(test_name)
642 finally:
643 print_mutex.release()
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000644
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700645def verify_knownfailure_entry(entry):
646 supported_field = {
Shubham Ajmerafe793492017-03-16 13:31:35 -0700647 'tests' : (list, str),
Alex Light6fdc1b62017-09-18 11:33:56 -0700648 'test_patterns' : (list,),
Shubham Ajmerafe793492017-03-16 13:31:35 -0700649 'description' : (list, str),
650 'bug' : (str,),
651 'variant' : (str,),
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700652 'env_vars' : (dict,),
653 }
654 for field in entry:
655 field_type = type(entry[field])
656 if field_type not in supported_field[field]:
657 raise ValueError('%s is not supported type for %s\n%s' % (
658 str(field_type),
659 field,
660 str(entry)))
661
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000662def get_disabled_test_info():
663 """Generate set of known failures.
664
665 It parses the art/test/knownfailures.json file to generate the list of
666 disabled tests.
667
668 Returns:
669 The method returns a dict of tests mapped to the variants list
670 for which the test should not be run.
671 """
672 known_failures_file = env.ANDROID_BUILD_TOP + '/art/test/knownfailures.json'
673 with open(known_failures_file) as known_failures_json:
674 known_failures_info = json.loads(known_failures_json.read())
675
676 disabled_test_info = {}
677 for failure in known_failures_info:
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700678 verify_knownfailure_entry(failure)
679 tests = failure.get('tests', [])
Shubham Ajmerafe793492017-03-16 13:31:35 -0700680 if isinstance(tests, str):
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000681 tests = [tests]
Alex Light6fdc1b62017-09-18 11:33:56 -0700682 patterns = failure.get("test_patterns", [])
683 if (not isinstance(patterns, list)):
684 raise ValueError("test_patters is not a list in %s" % failure)
685
686 tests += [f for f in RUN_TEST_SET if any(re.match(pat, f) is not None for pat in patterns)]
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000687 variants = parse_variants(failure.get('variant'))
688 env_vars = failure.get('env_vars')
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700689
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000690 if check_env_vars(env_vars):
691 for test in tests:
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700692 if test not in RUN_TEST_SET:
693 raise ValueError('%s is not a valid run-test' % (
694 test))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000695 if test in disabled_test_info:
696 disabled_test_info[test] = disabled_test_info[test].union(variants)
697 else:
698 disabled_test_info[test] = variants
699 return disabled_test_info
700
701
702def check_env_vars(env_vars):
703 """Checks if the env variables are set as required to run the test.
704
705 Returns:
706 True if all the env variables are set as required, otherwise False.
707 """
708
709 if not env_vars:
710 return True
711 for key in env_vars:
712 if env.get_env(key) != env_vars.get(key):
713 return False
714 return True
715
716
717def is_test_disabled(test, variant_set):
718 """Checks if the test along with the variant_set is disabled.
719
720 Args:
721 test: The name of the test as in art/test directory.
722 variant_set: Variants to be used for the test.
723 Returns:
724 True, if the test is disabled.
725 """
726 if dry_run:
727 return True
Alex Lightbc319b22017-02-17 14:21:33 -0800728 if test in env.EXTRA_DISABLED_TESTS:
729 return True
Alex Light42242dd2018-02-16 09:23:57 -0800730 if ignore_skips:
731 return False
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000732 variants_list = DISABLED_TEST_CONTAINER.get(test, {})
733 for variants in variants_list:
734 variants_present = True
735 for variant in variants:
736 if variant not in variant_set:
737 variants_present = False
738 break
739 if variants_present:
740 return True
741 return False
742
743
744def parse_variants(variants):
745 """Parse variants fetched from art/test/knownfailures.json.
746 """
747 if not variants:
748 variants = ''
749 for variant in TOTAL_VARIANTS_SET:
750 variants += variant
751 variants += '|'
752 variants = variants[:-1]
753 variant_list = set()
754 or_variants = variants.split('|')
755 for or_variant in or_variants:
756 and_variants = or_variant.split('&')
757 variant = set()
758 for and_variant in and_variants:
759 and_variant = and_variant.strip()
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700760 if and_variant not in TOTAL_VARIANTS_SET:
761 raise ValueError('%s is not a valid variant' % (
762 and_variant))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000763 variant.add(and_variant)
764 variant_list.add(frozenset(variant))
765 return variant_list
766
767def print_text(output):
768 sys.stdout.write(output)
769 sys.stdout.flush()
770
771def print_analysis():
772 if not verbose:
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000773 # Without --verbose, the testrunner erases passing test info. It
774 # does that by overriding the printed text with white spaces all across
775 # the console width.
776 console_width = int(os.popen('stty size', 'r').read().split()[1])
777 eraser_text = '\r' + ' ' * console_width + '\r'
778 print_text(eraser_text)
Shubham Ajmeracbf56282017-03-13 09:54:23 -0700779
780 # Prints information about the total tests run.
781 # E.g., "2/38 (5%) tests passed".
782 passed_test_count = total_test_count - len(skipped_tests) - len(failed_tests)
783 passed_test_information = ('%d/%d (%d%%) %s passed.\n') % (
784 passed_test_count,
785 total_test_count,
786 (passed_test_count*100)/total_test_count,
787 'tests' if passed_test_count > 1 else 'test')
788 print_text(passed_test_information)
789
790 # Prints the list of skipped tests, if any.
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000791 if skipped_tests:
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700792 print_text(COLOR_SKIP + 'SKIPPED TESTS: ' + COLOR_NORMAL + '\n')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000793 for test in skipped_tests:
794 print_text(test + '\n')
795 print_text('\n')
796
Shubham Ajmeracbf56282017-03-13 09:54:23 -0700797 # Prints the list of failed tests, if any.
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000798 if failed_tests:
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700799 print_text(COLOR_ERROR + 'FAILED: ' + COLOR_NORMAL + '\n')
800 for test_info in failed_tests:
801 print_text(('%s\n%s\n' % (test_info[0], test_info[1])))
Andreas Gampe0dd7e852017-05-24 21:44:23 -0700802 print_text(COLOR_ERROR + '----------' + COLOR_NORMAL + '\n')
803 for failed_test in sorted([test_info[0] for test_info in failed_tests]):
804 print_text(('%s\n' % (failed_test)))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000805
806
807def parse_test_name(test_name):
808 """Parses the testname provided by the user.
809 It supports two types of test_name:
810 1) Like 001-HelloWorld. In this case, it will just verify if the test actually
811 exists and if it does, it returns the testname.
812 2) Like test-art-host-run-test-debug-prebuild-interpreter-no-relocate-ntrace-cms-checkjni-picimage-npictest-ndebuggable-001-HelloWorld32
813 In this case, it will parse all the variants and check if they are placed
814 correctly. If yes, it will set the various VARIANT_TYPES to use the
815 variants required to run the test. Again, it returns the test_name
816 without the variant information like 001-HelloWorld.
817 """
Shubham Ajmerafaf12502017-02-15 17:19:44 +0000818 test_set = set()
819 for test in RUN_TEST_SET:
820 if test.startswith(test_name):
821 test_set.add(test)
822 if test_set:
823 return test_set
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000824
825 regex = '^test-art-'
826 regex += '(' + '|'.join(VARIANT_TYPE_DICT['target']) + ')-'
827 regex += 'run-test-'
828 regex += '(' + '|'.join(VARIANT_TYPE_DICT['run']) + ')-'
829 regex += '(' + '|'.join(VARIANT_TYPE_DICT['prebuild']) + ')-'
830 regex += '(' + '|'.join(VARIANT_TYPE_DICT['compiler']) + ')-'
831 regex += '(' + '|'.join(VARIANT_TYPE_DICT['relocate']) + ')-'
832 regex += '(' + '|'.join(VARIANT_TYPE_DICT['trace']) + ')-'
833 regex += '(' + '|'.join(VARIANT_TYPE_DICT['gc']) + ')-'
834 regex += '(' + '|'.join(VARIANT_TYPE_DICT['jni']) + ')-'
835 regex += '(' + '|'.join(VARIANT_TYPE_DICT['image']) + ')-'
836 regex += '(' + '|'.join(VARIANT_TYPE_DICT['pictest']) + ')-'
837 regex += '(' + '|'.join(VARIANT_TYPE_DICT['debuggable']) + ')-'
Alex Light8f2c6d42017-04-10 16:27:35 -0700838 regex += '(' + '|'.join(VARIANT_TYPE_DICT['jvmti']) + ')-'
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800839 regex += '(' + '|'.join(VARIANT_TYPE_DICT['cdex_level']) + ')-'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000840 regex += '(' + '|'.join(RUN_TEST_SET) + ')'
841 regex += '(' + '|'.join(VARIANT_TYPE_DICT['address_sizes']) + ')$'
842 match = re.match(regex, test_name)
843 if match:
Shubham Ajmera85853952017-08-29 16:26:21 -0700844 _user_input_variants['target'].add(match.group(1))
845 _user_input_variants['run'].add(match.group(2))
846 _user_input_variants['prebuild'].add(match.group(3))
847 _user_input_variants['compiler'].add(match.group(4))
848 _user_input_variants['relocate'].add(match.group(5))
849 _user_input_variants['trace'].add(match.group(6))
850 _user_input_variants['gc'].add(match.group(7))
851 _user_input_variants['jni'].add(match.group(8))
852 _user_input_variants['image'].add(match.group(9))
853 _user_input_variants['pictest'].add(match.group(10))
854 _user_input_variants['debuggable'].add(match.group(11))
855 _user_input_variants['jvmti'].add(match.group(12))
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800856 _user_input_variants['cdex_level'].add(match.group(13))
857 _user_input_variants['address_sizes'].add(match.group(15))
858 return {match.group(14)}
Shubham Ajmerafaf12502017-02-15 17:19:44 +0000859 raise ValueError(test_name + " is not a valid test")
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000860
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800861
862def setup_env_for_build_target(build_target, parser, options):
863 """Setup environment for the build target
864
865 The method setup environment for the master-art-host targets.
866 """
867 os.environ.update(build_target['env'])
868 os.environ['SOONG_ALLOW_MISSING_DEPENDENCIES'] = 'true'
869 print_text('%s\n' % (str(os.environ)))
870
871 target_options = vars(parser.parse_args(build_target['flags']))
872 target_options['host'] = True
873 target_options['verbose'] = True
874 target_options['build'] = True
875 target_options['n_thread'] = options['n_thread']
876 target_options['dry_run'] = options['dry_run']
877
878 return target_options
879
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700880def get_default_threads(target):
881 if target is 'target':
882 adb_command = 'adb shell cat /sys/devices/system/cpu/present'
883 cpu_info_proc = subprocess.Popen(adb_command.split(), stdout=subprocess.PIPE)
884 cpu_info = cpu_info_proc.stdout.read()
Shubham Ajmera8fd26942017-05-09 11:30:47 -0700885 if type(cpu_info) is bytes:
886 cpu_info = cpu_info.decode('utf-8')
887 cpu_info_regex = '\d*-(\d*)'
888 match = re.match(cpu_info_regex, cpu_info)
889 if match:
890 return int(match.group(1))
891 else:
892 raise ValueError('Unable to predict the concurrency for the target. '
893 'Is device connected?')
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700894 else:
895 return multiprocessing.cpu_count()
896
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000897def parse_option():
898 global verbose
899 global dry_run
Alex Light42242dd2018-02-16 09:23:57 -0800900 global ignore_skips
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000901 global n_thread
902 global build
903 global gdb
904 global gdb_arg
Vladimir Marko41b1f0e2018-03-21 11:17:12 +0000905 global runtime_option
Shubham Ajmerafe793492017-03-16 13:31:35 -0700906 global timeout
Shubham Ajmera981d99c2017-08-17 14:11:08 -0700907 global dex2oat_jobs
Shubham Ajmera42ea83b2017-09-25 21:05:57 -0700908 global run_all_configs
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000909
Alex Light7a1ccf82017-02-21 09:52:34 -0800910 parser = argparse.ArgumentParser(description="Runs all or a subset of the ART test suite.")
Andreas Gampe09b2d502017-11-29 19:08:16 -0800911 parser.add_argument('-t', '--test', action='append', dest='tests', help='name(s) of the test(s)')
Alex Lightc0322512018-03-13 10:33:52 -0700912 global_group = parser.add_argument_group('Global options',
913 'Options that affect all tests being run')
914 global_group.add_argument('-j', type=int, dest='n_thread')
915 global_group.add_argument('--timeout', default=timeout, type=int, dest='timeout')
916 global_group.add_argument('--verbose', '-v', action='store_true', dest='verbose')
917 global_group.add_argument('--dry-run', action='store_true', dest='dry_run')
Vladimir Marko41b1f0e2018-03-21 11:17:12 +0000918 global_group.add_argument("--skip", action='append', dest="skips", default=[],
Alex Lightc0322512018-03-13 10:33:52 -0700919 help="Skip the given test in all circumstances.")
Vladimir Marko41b1f0e2018-03-21 11:17:12 +0000920 global_group.add_argument("--no-skips", dest="ignore_skips", action='store_true', default=False,
Alex Lightc0322512018-03-13 10:33:52 -0700921 help="""Don't skip any run-test configurations listed in
922 knownfailures.json.""")
923 global_group.add_argument('--no-build-dependencies',
924 action='store_false', dest='build',
925 help="""Don't build dependencies under any circumstances. This is the
926 behavior if ART_TEST_RUN_TEST_ALWAYS_BUILD is not set to 'true'.""")
927 global_group.add_argument('-b', '--build-dependencies',
928 action='store_true', dest='build',
929 help="""Build dependencies under all circumstances. By default we will
930 not build dependencies unless ART_TEST_RUN_TEST_BUILD=true.""")
931 global_group.add_argument('--build-target', dest='build_target', help='master-art-host targets')
932 global_group.set_defaults(build = env.ART_TEST_RUN_TEST_BUILD)
933 global_group.add_argument('--gdb', action='store_true', dest='gdb')
934 global_group.add_argument('--gdb-arg', dest='gdb_arg')
Vladimir Marko41b1f0e2018-03-21 11:17:12 +0000935 global_group.add_argument('--runtime-option', action='append', dest='runtime_option',
936 help="""Pass an option to the runtime. Runtime options
937 starting with a '-' must be separated by a '=', for
938 example '--runtime-option=-Xjitthreshold:0'.""")
Alex Lightc0322512018-03-13 10:33:52 -0700939 global_group.add_argument('--dex2oat-jobs', type=int, dest='dex2oat_jobs',
940 help='Number of dex2oat jobs')
941 global_group.add_argument('-a', '--all', action='store_true', dest='run_all',
942 help="Run all the possible configurations for the input test set")
943 for variant_type, variant_set in VARIANT_TYPE_DICT.items():
944 var_group = parser.add_argument_group(
945 '{}-type Options'.format(variant_type),
946 "Options that control the '{}' variants.".format(variant_type))
947 for variant in variant_set:
948 flag = '--' + variant
949 var_group.add_argument(flag, action='store_true', dest=variant)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000950
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800951 options = vars(parser.parse_args())
952 if options['build_target']:
953 options = setup_env_for_build_target(target_config[options['build_target']],
954 parser, options)
955
Andreas Gampe09b2d502017-11-29 19:08:16 -0800956 tests = None
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800957 env.EXTRA_DISABLED_TESTS.update(set(options['skips']))
Andreas Gampe09b2d502017-11-29 19:08:16 -0800958 if options['tests']:
959 tests = set()
960 for test_name in options['tests']:
961 tests |= parse_test_name(test_name)
Shubham Ajmera85853952017-08-29 16:26:21 -0700962
963 for variant_type in VARIANT_TYPE_DICT:
964 for variant in VARIANT_TYPE_DICT[variant_type]:
965 if options.get(variant):
966 _user_input_variants[variant_type].add(variant)
967
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800968 if options['verbose']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000969 verbose = True
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800970 if options['n_thread']:
971 n_thread = max(1, options['n_thread'])
Alex Light42242dd2018-02-16 09:23:57 -0800972 ignore_skips = options['ignore_skips']
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800973 if options['dry_run']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000974 dry_run = True
975 verbose = True
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800976 build = options['build']
977 if options['gdb']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000978 n_thread = 1
979 gdb = True
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800980 if options['gdb_arg']:
981 gdb_arg = options['gdb_arg']
Vladimir Marko41b1f0e2018-03-21 11:17:12 +0000982 runtime_option = options['runtime_option'];
Shubham Ajmerafe793492017-03-16 13:31:35 -0700983 timeout = options['timeout']
Shubham Ajmera981d99c2017-08-17 14:11:08 -0700984 if options['dex2oat_jobs']:
985 dex2oat_jobs = options['dex2oat_jobs']
Shubham Ajmera42ea83b2017-09-25 21:05:57 -0700986 if options['run_all']:
987 run_all_configs = True
Shubham Ajmera22499e22017-03-22 18:33:37 -0700988
Andreas Gampe09b2d502017-11-29 19:08:16 -0800989 return tests
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000990
991def main():
992 gather_test_info()
Andreas Gampe09b2d502017-11-29 19:08:16 -0800993 user_requested_tests = parse_option()
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000994 setup_test_env()
995 if build:
996 build_targets = ''
Shubham Ajmera85853952017-08-29 16:26:21 -0700997 if 'host' in _user_input_variants['target']:
Shubham Ajmera186d3212017-07-21 01:20:57 +0000998 build_targets += 'test-art-host-run-test-dependencies'
Shubham Ajmera85853952017-08-29 16:26:21 -0700999 if 'target' in _user_input_variants['target']:
Shubham Ajmera186d3212017-07-21 01:20:57 +00001000 build_targets += 'test-art-target-run-test-dependencies'
Igor Murashkinbab15062018-02-23 14:53:24 -08001001 if 'jvm' in _user_input_variants['target']:
1002 build_targets += 'test-art-host-run-test-dependencies'
Shubham Ajmera06cde292017-02-10 23:15:05 +00001003 build_command = 'make'
Colin Cross91f55e62017-10-21 12:45:26 -07001004 build_command += ' DX='
Shubham Ajmera4a5a1622017-03-22 10:07:19 -07001005 build_command += ' -j'
Shubham Ajmera06cde292017-02-10 23:15:05 +00001006 build_command += ' -C ' + env.ANDROID_BUILD_TOP
1007 build_command += ' ' + build_targets
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001008 if subprocess.call(build_command.split()):
1009 sys.exit(1)
Andreas Gampe09b2d502017-11-29 19:08:16 -08001010 if user_requested_tests:
1011 test_runner_thread = threading.Thread(target=run_tests, args=(user_requested_tests,))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001012 else:
1013 test_runner_thread = threading.Thread(target=run_tests, args=(RUN_TEST_SET,))
1014 test_runner_thread.daemon = True
1015 try:
1016 test_runner_thread.start()
Shubham Ajmera535a15c2017-11-02 11:31:14 -07001017 # This loops waits for all the threads to finish, unless
1018 # stop_testrunner is set to True. When ART_TEST_KEEP_GOING
1019 # is set to false, stop_testrunner is set to True as soon as
1020 # a test fails to signal the parent thread to stop
1021 # the execution of the testrunner.
1022 while threading.active_count() > 1 and not stop_testrunner:
Shubham Ajmera186d3212017-07-21 01:20:57 +00001023 time.sleep(0.1)
1024 print_analysis()
Shubham Ajmerafe793492017-03-16 13:31:35 -07001025 except Exception as e:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001026 print_analysis()
Shubham Ajmerafaf12502017-02-15 17:19:44 +00001027 print_text(str(e))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001028 sys.exit(1)
Shubham Ajmerac5aae872017-02-16 19:58:59 +00001029 if failed_tests:
1030 sys.exit(1)
1031 sys.exit(0)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001032
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001033if __name__ == '__main__':
1034 main()