blob: 77ef25a75bb5da0367e7d1da6b300764d70dddf5 [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 Ajmera65adb8b2017-02-06 16:04:25 +000048import fnmatch
49import itertools
50import json
Shubham Ajmera4a5a1622017-03-22 10:07:19 -070051import multiprocessing
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000052import os
53import re
54import subprocess
55import sys
Shubham Ajmera29f89682017-03-24 14:44:10 -070056import tempfile
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000057import threading
58import time
59
60import env
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -080061from target_config import target_config
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000062
63TARGET_TYPES = set()
64RUN_TYPES = set()
65PREBUILD_TYPES = set()
66COMPILER_TYPES = set()
67RELOCATE_TYPES = set()
68TRACE_TYPES = set()
69GC_TYPES = set()
70JNI_TYPES = set()
71IMAGE_TYPES = set()
72PICTEST_TYPES = set()
73DEBUGGABLE_TYPES = set()
74ADDRESS_SIZES = set()
75OPTIMIZING_COMPILER_TYPES = set()
Alex Light8f2c6d42017-04-10 16:27:35 -070076JVMTI_TYPES = set()
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000077ADDRESS_SIZES_TARGET = {'host': set(), 'target': set()}
Shubham Ajmerafe793492017-03-16 13:31:35 -070078# timeout for individual tests.
79# TODO: make it adjustable per tests and for buildbots
80timeout = 3000 # 50 minutes
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000081
82# DISABLED_TEST_CONTAINER holds information about the disabled tests. It is a map
83# that has key as the test name (like 001-HelloWorld), and value as set of
84# variants that the test is disabled for.
85DISABLED_TEST_CONTAINER = {}
86
87# The Dict contains the list of all possible variants for a given type. For example,
88# for key TARGET, the value would be target and host. The list is used to parse
89# the test name given as the argument to run.
90VARIANT_TYPE_DICT = {}
91
92# The set contains all the variants of each time.
93TOTAL_VARIANTS_SET = set()
94
95# The colors are used in the output. When a test passes, COLOR_PASS is used,
96# and so on.
97COLOR_ERROR = '\033[91m'
98COLOR_PASS = '\033[92m'
99COLOR_SKIP = '\033[93m'
100COLOR_NORMAL = '\033[0m'
101
102# The mutex object is used by the threads for exclusive access of test_count
103# to make any changes in its value.
104test_count_mutex = threading.Lock()
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000105
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000106# The set contains the list of all the possible run tests that are in art/test
107# directory.
108RUN_TEST_SET = set()
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000109
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000110# The semaphore object is used by the testrunner to limit the number of
111# threads to the user requested concurrency value.
112semaphore = threading.Semaphore(1)
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000113
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000114# The mutex object is used to provide exclusive access to a thread to print
115# its output.
116print_mutex = threading.Lock()
117failed_tests = []
118skipped_tests = []
119
120# Flags
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700121n_thread = -1
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000122test_count = 0
123total_test_count = 0
124verbose = False
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000125dry_run = False
126build = False
127gdb = False
128gdb_arg = ''
129stop_testrunner = False
130
131def gather_test_info():
132 """The method gathers test information about the test to be run which includes
133 generating the list of total tests from the art/test directory and the list
134 of disabled test. It also maps various variants to types.
135 """
136 global TOTAL_VARIANTS_SET
137 global DISABLED_TEST_CONTAINER
138 # TODO: Avoid duplication of the variant names in different lists.
139 VARIANT_TYPE_DICT['pictest'] = {'pictest', 'npictest'}
140 VARIANT_TYPE_DICT['run'] = {'ndebug', 'debug'}
141 VARIANT_TYPE_DICT['target'] = {'target', 'host'}
142 VARIANT_TYPE_DICT['trace'] = {'trace', 'ntrace', 'stream'}
Richard Uhlerbb00f812017-02-16 14:21:10 +0000143 VARIANT_TYPE_DICT['image'] = {'picimage', 'no-image', 'multipicimage'}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000144 VARIANT_TYPE_DICT['debuggable'] = {'ndebuggable', 'debuggable'}
145 VARIANT_TYPE_DICT['gc'] = {'gcstress', 'gcverify', 'cms'}
146 VARIANT_TYPE_DICT['prebuild'] = {'no-prebuild', 'no-dex2oat', 'prebuild'}
147 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 Light8f2c6d42017-04-10 16:27:35 -0700150 VARIANT_TYPE_DICT['jvmti'] = {'no-jvmti', 'jvmti-stress'}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000151 VARIANT_TYPE_DICT['compiler'] = {'interp-ac', 'interpreter', 'jit', 'optimizing',
Jeff Hao002b9312017-03-27 16:23:08 -0700152 'regalloc_gc', 'speed-profile'}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000153
154 for v_type in VARIANT_TYPE_DICT:
155 TOTAL_VARIANTS_SET = TOTAL_VARIANTS_SET.union(VARIANT_TYPE_DICT.get(v_type))
156
157 test_dir = env.ANDROID_BUILD_TOP + '/art/test'
158 for f in os.listdir(test_dir):
159 if fnmatch.fnmatch(f, '[0-9]*'):
160 RUN_TEST_SET.add(f)
161 DISABLED_TEST_CONTAINER = get_disabled_test_info()
162
163
164def setup_test_env():
165 """The method sets default value for the various variants of the tests if they
166 are already not set.
167 """
168 if env.ART_TEST_BISECTION:
169 env.ART_TEST_RUN_TEST_NO_PREBUILD = True
170 env.ART_TEST_RUN_TEST_PREBUILD = False
171 # Bisection search writes to standard output.
172 env.ART_TEST_QUIET = False
173
174 if not TARGET_TYPES:
175 TARGET_TYPES.add('host')
176 TARGET_TYPES.add('target')
177
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000178 if env.ART_TEST_RUN_TEST_NO_PREBUILD:
179 PREBUILD_TYPES.add('no-prebuild')
180 if env.ART_TEST_RUN_TEST_NO_DEX2OAT:
181 PREBUILD_TYPES.add('no-dex2oat')
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000182 if env.ART_TEST_RUN_TEST_PREBUILD or not PREBUILD_TYPES: # Default
183 PREBUILD_TYPES.add('prebuild')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000184
185 if env.ART_TEST_INTERPRETER_ACCESS_CHECKS:
186 COMPILER_TYPES.add('interp-ac')
187 if env.ART_TEST_INTERPRETER:
188 COMPILER_TYPES.add('interpreter')
189 if env.ART_TEST_JIT:
190 COMPILER_TYPES.add('jit')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000191 if env.ART_TEST_OPTIMIZING_GRAPH_COLOR:
192 COMPILER_TYPES.add('regalloc_gc')
193 OPTIMIZING_COMPILER_TYPES.add('regalloc_gc')
Nicolas Geoffray70b21bd2017-03-15 10:18:50 +0000194 if env.ART_TEST_OPTIMIZING:
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000195 COMPILER_TYPES.add('optimizing')
196 OPTIMIZING_COMPILER_TYPES.add('optimizing')
Jeff Hao002b9312017-03-27 16:23:08 -0700197 if env.ART_TEST_SPEED_PROFILE:
198 COMPILER_TYPES.add('speed-profile')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000199
Alex Light8f2c6d42017-04-10 16:27:35 -0700200 # By default only run without jvmti
201 if not JVMTI_TYPES:
202 JVMTI_TYPES.add('no-jvmti')
203
Nicolas Geoffray70b21bd2017-03-15 10:18:50 +0000204 # By default we run all 'compiler' variants.
205 if not COMPILER_TYPES:
206 COMPILER_TYPES.add('optimizing')
207 COMPILER_TYPES.add('jit')
208 COMPILER_TYPES.add('interpreter')
209 COMPILER_TYPES.add('interp-ac')
Jeff Hao002b9312017-03-27 16:23:08 -0700210 COMPILER_TYPES.add('speed-profile')
Nicolas Geoffray70b21bd2017-03-15 10:18:50 +0000211 OPTIMIZING_COMPILER_TYPES.add('optimizing')
212
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000213 if env.ART_TEST_RUN_TEST_RELOCATE:
214 RELOCATE_TYPES.add('relocate')
215 if env.ART_TEST_RUN_TEST_RELOCATE_NO_PATCHOAT:
216 RELOCATE_TYPES.add('relocate-npatchoat')
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000217 if not RELOCATE_TYPES: # Default
218 RELOCATE_TYPES.add('no-relocate')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000219
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000220 if env.ART_TEST_TRACE:
221 TRACE_TYPES.add('trace')
222 if env.ART_TEST_TRACE_STREAM:
223 TRACE_TYPES.add('stream')
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000224 if not TRACE_TYPES: # Default
225 TRACE_TYPES.add('ntrace')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000226
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000227 if env.ART_TEST_GC_STRESS:
228 GC_TYPES.add('gcstress')
229 if env.ART_TEST_GC_VERIFY:
230 GC_TYPES.add('gcverify')
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000231 if not GC_TYPES: # Default
232 GC_TYPES.add('cms')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000233
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000234 if env.ART_TEST_JNI_FORCECOPY:
235 JNI_TYPES.add('forcecopy')
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000236 if not JNI_TYPES: # Default
237 JNI_TYPES.add('checkjni')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000238
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000239 if env.ART_TEST_RUN_TEST_NO_IMAGE:
240 IMAGE_TYPES.add('no-image')
241 if env.ART_TEST_RUN_TEST_MULTI_IMAGE:
242 IMAGE_TYPES.add('multipicimage')
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000243 if env.ART_TEST_RUN_TEST_IMAGE or not IMAGE_TYPES: # Default
244 IMAGE_TYPES.add('picimage')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000245
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000246 if env.ART_TEST_PIC_TEST:
247 PICTEST_TYPES.add('pictest')
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000248 if not PICTEST_TYPES: # Default
249 PICTEST_TYPES.add('npictest')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000250
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000251 if env.ART_TEST_RUN_TEST_NDEBUG:
252 RUN_TYPES.add('ndebug')
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000253 if env.ART_TEST_RUN_TEST_DEBUG or not RUN_TYPES: # Default
254 RUN_TYPES.add('debug')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000255
256 if env.ART_TEST_RUN_TEST_DEBUGGABLE:
257 DEBUGGABLE_TYPES.add('debuggable')
Shubham Ajmera4b8c53d2017-02-15 16:38:16 +0000258 if not DEBUGGABLE_TYPES: # Default
259 DEBUGGABLE_TYPES.add('ndebuggable')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000260
261 if not ADDRESS_SIZES:
262 ADDRESS_SIZES_TARGET['target'].add(env.ART_PHONY_TEST_TARGET_SUFFIX)
263 ADDRESS_SIZES_TARGET['host'].add(env.ART_PHONY_TEST_HOST_SUFFIX)
264 if env.ART_TEST_RUN_TEST_2ND_ARCH:
Igor Murashkin6b61c802017-04-03 14:33:22 -0700265 ADDRESS_SIZES_TARGET['host'].add(env.ART_2ND_PHONY_TEST_HOST_SUFFIX)
266 ADDRESS_SIZES_TARGET['target'].add(env.ART_2ND_PHONY_TEST_TARGET_SUFFIX)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000267 else:
268 ADDRESS_SIZES_TARGET['host'] = ADDRESS_SIZES_TARGET['host'].union(ADDRESS_SIZES)
269 ADDRESS_SIZES_TARGET['target'] = ADDRESS_SIZES_TARGET['target'].union(ADDRESS_SIZES)
270
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700271 global n_thread
272 if n_thread is -1:
273 if 'target' in TARGET_TYPES:
274 n_thread = get_default_threads('target')
275 else:
276 n_thread = get_default_threads('host')
277
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000278 global semaphore
279 semaphore = threading.Semaphore(n_thread)
280
Shubham Ajmera22499e22017-03-22 18:33:37 -0700281 if not sys.stdout.isatty():
282 global COLOR_ERROR
283 global COLOR_PASS
284 global COLOR_SKIP
285 global COLOR_NORMAL
286 COLOR_ERROR = ''
287 COLOR_PASS = ''
288 COLOR_SKIP = ''
289 COLOR_NORMAL = ''
290
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000291
292def run_tests(tests):
293 """Creates thread workers to run the tests.
294
295 The method generates command and thread worker to run the tests. Depending on
296 the user input for the number of threads to be used, the method uses a
297 semaphore object to keep a count in control for the thread workers. When a new
298 worker is created, it acquires the semaphore object, and when the number of
299 workers reaches the maximum allowed concurrency, the method wait for an
300 existing thread worker to release the semaphore object. Worker releases the
301 semaphore object when they finish printing the output.
302
303 Args:
304 tests: The set of tests to be run.
305 """
306 options_all = ''
307 global total_test_count
308 total_test_count = len(tests)
309 total_test_count *= len(RUN_TYPES)
310 total_test_count *= len(PREBUILD_TYPES)
311 total_test_count *= len(RELOCATE_TYPES)
312 total_test_count *= len(TRACE_TYPES)
313 total_test_count *= len(GC_TYPES)
314 total_test_count *= len(JNI_TYPES)
315 total_test_count *= len(IMAGE_TYPES)
316 total_test_count *= len(PICTEST_TYPES)
317 total_test_count *= len(DEBUGGABLE_TYPES)
318 total_test_count *= len(COMPILER_TYPES)
Alex Light8f2c6d42017-04-10 16:27:35 -0700319 total_test_count *= len(JVMTI_TYPES)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000320 target_address_combinations = 0
321 for target in TARGET_TYPES:
322 for address_size in ADDRESS_SIZES_TARGET[target]:
323 target_address_combinations += 1
324 total_test_count *= target_address_combinations
325
326 if env.ART_TEST_WITH_STRACE:
327 options_all += ' --strace'
328
329 if env.ART_TEST_RUN_TEST_ALWAYS_CLEAN:
330 options_all += ' --always-clean'
331
332 if env.ART_TEST_BISECTION:
333 options_all += ' --bisection-search'
334
335 if env.ART_TEST_ANDROID_ROOT:
336 options_all += ' --android-root ' + env.ART_TEST_ANDROID_ROOT
337
338 if gdb:
339 options_all += ' --gdb'
340 if gdb_arg:
341 options_all += ' --gdb-arg ' + gdb_arg
342
343 config = itertools.product(tests, TARGET_TYPES, RUN_TYPES, PREBUILD_TYPES,
344 COMPILER_TYPES, RELOCATE_TYPES, TRACE_TYPES,
345 GC_TYPES, JNI_TYPES, IMAGE_TYPES, PICTEST_TYPES,
Alex Light8f2c6d42017-04-10 16:27:35 -0700346 DEBUGGABLE_TYPES, JVMTI_TYPES)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000347
348 for test, target, run, prebuild, compiler, relocate, trace, gc, \
Alex Light8f2c6d42017-04-10 16:27:35 -0700349 jni, image, pictest, debuggable, jvmti in config:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000350 for address_size in ADDRESS_SIZES_TARGET[target]:
351 if stop_testrunner:
352 # When ART_TEST_KEEP_GOING is set to false, then as soon as a test
353 # fails, stop_testrunner is set to True. When this happens, the method
354 # stops creating any any thread and wait for all the exising threads
355 # to end.
356 while threading.active_count() > 2:
357 time.sleep(0.1)
358 return
359 test_name = 'test-art-'
360 test_name += target + '-run-test-'
361 test_name += run + '-'
362 test_name += prebuild + '-'
363 test_name += compiler + '-'
364 test_name += relocate + '-'
365 test_name += trace + '-'
366 test_name += gc + '-'
367 test_name += jni + '-'
368 test_name += image + '-'
369 test_name += pictest + '-'
370 test_name += debuggable + '-'
Alex Light8f2c6d42017-04-10 16:27:35 -0700371 test_name += jvmti + '-'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000372 test_name += test
373 test_name += address_size
374
375 variant_set = {target, run, prebuild, compiler, relocate, trace, gc, jni,
Alex Light8f2c6d42017-04-10 16:27:35 -0700376 image, pictest, debuggable, jvmti, address_size}
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000377
378 options_test = options_all
379
380 if target == 'host':
381 options_test += ' --host'
382
383 if run == 'ndebug':
384 options_test += ' -O'
385
386 if prebuild == 'prebuild':
387 options_test += ' --prebuild'
388 elif prebuild == 'no-prebuild':
389 options_test += ' --no-prebuild'
390 elif prebuild == 'no-dex2oat':
391 options_test += ' --no-prebuild --no-dex2oat'
392
393 if compiler == 'optimizing':
394 options_test += ' --optimizing'
395 elif compiler == 'regalloc_gc':
396 options_test += ' --optimizing -Xcompiler-option --register-allocation-strategy=graph-color'
397 elif compiler == 'interpreter':
398 options_test += ' --interpreter'
399 elif compiler == 'interp-ac':
400 options_test += ' --interpreter --verify-soft-fail'
401 elif compiler == 'jit':
402 options_test += ' --jit'
Jeff Hao002b9312017-03-27 16:23:08 -0700403 elif compiler == 'speed-profile':
404 options_test += ' --random-profile'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000405
406 if relocate == 'relocate':
407 options_test += ' --relocate'
408 elif relocate == 'no-relocate':
409 options_test += ' --no-relocate'
410 elif relocate == 'relocate-npatchoat':
411 options_test += ' --relocate --no-patchoat'
412
413 if trace == 'trace':
414 options_test += ' --trace'
415 elif trace == 'stream':
416 options_test += ' --trace --stream'
417
418 if gc == 'gcverify':
419 options_test += ' --gcverify'
420 elif gc == 'gcstress':
421 options_test += ' --gcstress'
422
423 if jni == 'forcecopy':
424 options_test += ' --runtime-option -Xjniopts:forcecopy'
425 elif jni == 'checkjni':
426 options_test += ' --runtime-option -Xcheck:jni'
427
428 if image == 'no-image':
429 options_test += ' --no-image'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000430 elif image == 'multipicimage':
431 options_test += ' --multi-image'
432
433 if pictest == 'pictest':
434 options_test += ' --pic-test'
435
436 if debuggable == 'debuggable':
437 options_test += ' --debuggable'
438
Alex Light8f2c6d42017-04-10 16:27:35 -0700439 if jvmti == 'jvmti-stress':
440 options_test += ' --jvmti-stress'
441
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000442 if address_size == '64':
443 options_test += ' --64'
444
445 if env.DEX2OAT_HOST_INSTRUCTION_SET_FEATURES:
446 options_test += ' --instruction-set-features' + env.DEX2OAT_HOST_INSTRUCTION_SET_FEATURES
447
448 elif address_size == '32':
449 if env.HOST_2ND_ARCH_PREFIX_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES:
450 options_test += ' --instruction-set-features ' + \
451 env.HOST_2ND_ARCH_PREFIX_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES
452
Igor Murashkin8889a892017-04-24 16:09:15 -0700453 # Use the default run-test behavior unless ANDROID_COMPILE_WITH_JACK is explicitly set.
454 if env.ANDROID_COMPILE_WITH_JACK == True:
455 options_test += ' --build-with-jack'
456 elif env.ANDROID_COMPILE_WITH_JACK == False:
457 options_test += ' --build-with-javac-dx'
458
Shubham Ajmera29f89682017-03-24 14:44:10 -0700459 # TODO(http://36039166): This is a temporary solution to
460 # fix build breakages.
461 options_test = (' --output-path %s') % (
462 tempfile.mkdtemp(dir=env.ART_HOST_TEST_DIR)) + options_test
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000463
464 run_test_sh = env.ANDROID_BUILD_TOP + '/art/test/run-test'
465 command = run_test_sh + ' ' + options_test + ' ' + test
466
467 semaphore.acquire()
468 worker = threading.Thread(target=run_test, args=(command, test, variant_set, test_name))
469 worker.daemon = True
470 worker.start()
471
472 while threading.active_count() > 2:
473 time.sleep(0.1)
474
475
476def run_test(command, test, test_variant, test_name):
477 """Runs the test.
478
479 It invokes art/test/run-test script to run the test. The output of the script
480 is checked, and if it ends with "Succeeded!", it assumes that the tests
481 passed, otherwise, put it in the list of failed test. Before actually running
482 the test, it also checks if the test is placed in the list of disabled tests,
483 and if yes, it skips running it, and adds the test in the list of skipped
484 tests. The method uses print_text method to actually print the output. After
485 successfully running and capturing the output for the test, it releases the
486 semaphore object.
487
488 Args:
489 command: The command to be used to invoke the script
490 test: The name of the test without the variant information.
491 test_variant: The set of variant for the test.
492 test_name: The name of the test along with the variants.
493 """
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000494 global stop_testrunner
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000495 try:
496 if is_test_disabled(test, test_variant):
497 test_skipped = True
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000498 else:
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000499 test_skipped = False
Shubham Ajmerab4949f52017-05-08 13:52:46 -0700500 if gdb:
501 proc = subprocess.Popen(command.split(), stderr=subprocess.STDOUT, universal_newlines=True)
502 else:
503 proc = subprocess.Popen(command.split(), stderr=subprocess.STDOUT, stdout = subprocess.PIPE,
504 universal_newlines=True)
Shubham Ajmerafe793492017-03-16 13:31:35 -0700505 script_output = proc.communicate(timeout=timeout)[0]
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000506 test_passed = not proc.wait()
507
508 if not test_skipped:
509 if test_passed:
510 print_test_info(test_name, 'PASS')
511 else:
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700512 failed_tests.append((test_name, script_output))
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000513 if not env.ART_TEST_KEEP_GOING:
514 stop_testrunner = True
515 print_test_info(test_name, 'FAIL', ('%s\n%s') % (
516 command, script_output))
517 elif not dry_run:
518 print_test_info(test_name, 'SKIP')
519 skipped_tests.append(test_name)
520 else:
521 print_test_info(test_name, '')
Shubham Ajmerafe793492017-03-16 13:31:35 -0700522 except subprocess.TimeoutExpired as e:
Goran Jakovljevic2679e492017-04-06 07:47:59 +0200523 failed_tests.append((test_name, 'Timed out in %d seconds' % timeout))
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700524 print_test_info(test_name, 'TIMEOUT', 'Timed out in %d seconds\n%s' % (
Shubham Ajmerafe793492017-03-16 13:31:35 -0700525 timeout, command))
526 except Exception as e:
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700527 failed_tests.append((test_name, str(e)))
528 print_test_info(test_name, 'FAIL',
529 ('%s\n%s\n\n') % (command, str(e)))
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000530 finally:
531 semaphore.release()
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000532
533
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000534def print_test_info(test_name, result, failed_test_info=""):
535 """Print the continous test information
536
537 If verbose is set to True, it continuously prints test status information
538 on a new line.
539 If verbose is set to False, it keeps on erasing test
540 information by overriding it with the latest test information. Also,
541 in this case it stictly makes sure that the information length doesn't
542 exceed the console width. It does so by shortening the test_name.
543
544 When a test fails, it prints the output of the run-test script and
545 command used to invoke the script. It doesn't override the failing
546 test information in either of the cases.
547 """
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000548
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000549 global test_count
550 info = ''
551 if not verbose:
552 # Without --verbose, the testrunner erases passing test info. It
553 # does that by overriding the printed text with white spaces all across
554 # the console width.
555 console_width = int(os.popen('stty size', 'r').read().split()[1])
556 info = '\r' + ' ' * console_width + '\r'
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000557 try:
558 print_mutex.acquire()
559 test_count += 1
560 percent = (test_count * 100) / total_test_count
561 progress_info = ('[ %d%% %d/%d ]') % (
562 percent,
563 test_count,
564 total_test_count)
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000565
Shubham Ajmerafe793492017-03-16 13:31:35 -0700566 if result == 'FAIL' or result == 'TIMEOUT':
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000567 info += ('%s %s %s\n%s\n') % (
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000568 progress_info,
569 test_name,
Shubham Ajmerafe793492017-03-16 13:31:35 -0700570 COLOR_ERROR + result + COLOR_NORMAL,
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000571 failed_test_info)
572 else:
573 result_text = ''
574 if result == 'PASS':
575 result_text += COLOR_PASS + 'PASS' + COLOR_NORMAL
576 elif result == 'SKIP':
577 result_text += COLOR_SKIP + 'SKIP' + COLOR_NORMAL
578
579 if verbose:
580 info += ('%s %s %s\n') % (
581 progress_info,
582 test_name,
583 result_text)
584 else:
585 total_output_length = 2 # Two spaces
586 total_output_length += len(progress_info)
587 total_output_length += len(result)
588 allowed_test_length = console_width - total_output_length
589 test_name_len = len(test_name)
590 if allowed_test_length < test_name_len:
Shubham Ajmerafe793492017-03-16 13:31:35 -0700591 test_name = ('...%s') % (
592 test_name[-(allowed_test_length - 3):])
Alex Lightc14311c2017-02-23 17:02:46 -0800593 info += ('%s %s %s') % (
594 progress_info,
595 test_name,
596 result_text)
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000597 print_text(info)
Shubham Ajmerafe793492017-03-16 13:31:35 -0700598 except Exception as e:
Shubham Ajmerabbd84332017-02-17 00:41:10 +0000599 print_text(('%s\n%s\n') % (test_name, str(e)))
600 failed_tests.append(test_name)
601 finally:
602 print_mutex.release()
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000603
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700604def verify_knownfailure_entry(entry):
605 supported_field = {
Shubham Ajmerafe793492017-03-16 13:31:35 -0700606 'tests' : (list, str),
607 'description' : (list, str),
608 'bug' : (str,),
609 'variant' : (str,),
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700610 'env_vars' : (dict,),
611 }
612 for field in entry:
613 field_type = type(entry[field])
614 if field_type not in supported_field[field]:
615 raise ValueError('%s is not supported type for %s\n%s' % (
616 str(field_type),
617 field,
618 str(entry)))
619
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000620def get_disabled_test_info():
621 """Generate set of known failures.
622
623 It parses the art/test/knownfailures.json file to generate the list of
624 disabled tests.
625
626 Returns:
627 The method returns a dict of tests mapped to the variants list
628 for which the test should not be run.
629 """
630 known_failures_file = env.ANDROID_BUILD_TOP + '/art/test/knownfailures.json'
631 with open(known_failures_file) as known_failures_json:
632 known_failures_info = json.loads(known_failures_json.read())
633
634 disabled_test_info = {}
635 for failure in known_failures_info:
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700636 verify_knownfailure_entry(failure)
637 tests = failure.get('tests', [])
Shubham Ajmerafe793492017-03-16 13:31:35 -0700638 if isinstance(tests, str):
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000639 tests = [tests]
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000640 variants = parse_variants(failure.get('variant'))
641 env_vars = failure.get('env_vars')
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700642
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000643 if check_env_vars(env_vars):
644 for test in tests:
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700645 if test not in RUN_TEST_SET:
646 raise ValueError('%s is not a valid run-test' % (
647 test))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000648 if test in disabled_test_info:
649 disabled_test_info[test] = disabled_test_info[test].union(variants)
650 else:
651 disabled_test_info[test] = variants
652 return disabled_test_info
653
654
655def check_env_vars(env_vars):
656 """Checks if the env variables are set as required to run the test.
657
658 Returns:
659 True if all the env variables are set as required, otherwise False.
660 """
661
662 if not env_vars:
663 return True
664 for key in env_vars:
665 if env.get_env(key) != env_vars.get(key):
666 return False
667 return True
668
669
670def is_test_disabled(test, variant_set):
671 """Checks if the test along with the variant_set is disabled.
672
673 Args:
674 test: The name of the test as in art/test directory.
675 variant_set: Variants to be used for the test.
676 Returns:
677 True, if the test is disabled.
678 """
679 if dry_run:
680 return True
Alex Lightbc319b22017-02-17 14:21:33 -0800681 if test in env.EXTRA_DISABLED_TESTS:
682 return True
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000683 variants_list = DISABLED_TEST_CONTAINER.get(test, {})
684 for variants in variants_list:
685 variants_present = True
686 for variant in variants:
687 if variant not in variant_set:
688 variants_present = False
689 break
690 if variants_present:
691 return True
692 return False
693
694
695def parse_variants(variants):
696 """Parse variants fetched from art/test/knownfailures.json.
697 """
698 if not variants:
699 variants = ''
700 for variant in TOTAL_VARIANTS_SET:
701 variants += variant
702 variants += '|'
703 variants = variants[:-1]
704 variant_list = set()
705 or_variants = variants.split('|')
706 for or_variant in or_variants:
707 and_variants = or_variant.split('&')
708 variant = set()
709 for and_variant in and_variants:
710 and_variant = and_variant.strip()
Shubham Ajmera14de5c42017-03-13 10:51:14 -0700711 if and_variant not in TOTAL_VARIANTS_SET:
712 raise ValueError('%s is not a valid variant' % (
713 and_variant))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000714 variant.add(and_variant)
715 variant_list.add(frozenset(variant))
716 return variant_list
717
718def print_text(output):
719 sys.stdout.write(output)
720 sys.stdout.flush()
721
722def print_analysis():
723 if not verbose:
Shubham Ajmera14d340c2017-02-15 18:49:10 +0000724 # Without --verbose, the testrunner erases passing test info. It
725 # does that by overriding the printed text with white spaces all across
726 # the console width.
727 console_width = int(os.popen('stty size', 'r').read().split()[1])
728 eraser_text = '\r' + ' ' * console_width + '\r'
729 print_text(eraser_text)
Shubham Ajmeracbf56282017-03-13 09:54:23 -0700730
731 # Prints information about the total tests run.
732 # E.g., "2/38 (5%) tests passed".
733 passed_test_count = total_test_count - len(skipped_tests) - len(failed_tests)
734 passed_test_information = ('%d/%d (%d%%) %s passed.\n') % (
735 passed_test_count,
736 total_test_count,
737 (passed_test_count*100)/total_test_count,
738 'tests' if passed_test_count > 1 else 'test')
739 print_text(passed_test_information)
740
741 # Prints the list of skipped tests, if any.
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000742 if skipped_tests:
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700743 print_text(COLOR_SKIP + 'SKIPPED TESTS: ' + COLOR_NORMAL + '\n')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000744 for test in skipped_tests:
745 print_text(test + '\n')
746 print_text('\n')
747
Shubham Ajmeracbf56282017-03-13 09:54:23 -0700748 # Prints the list of failed tests, if any.
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000749 if failed_tests:
Shubham Ajmera3092c6e2017-03-24 16:19:48 -0700750 print_text(COLOR_ERROR + 'FAILED: ' + COLOR_NORMAL + '\n')
751 for test_info in failed_tests:
752 print_text(('%s\n%s\n' % (test_info[0], test_info[1])))
Andreas Gampe0dd7e852017-05-24 21:44:23 -0700753 print_text(COLOR_ERROR + '----------' + COLOR_NORMAL + '\n')
754 for failed_test in sorted([test_info[0] for test_info in failed_tests]):
755 print_text(('%s\n' % (failed_test)))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000756
757
758def parse_test_name(test_name):
759 """Parses the testname provided by the user.
760 It supports two types of test_name:
761 1) Like 001-HelloWorld. In this case, it will just verify if the test actually
762 exists and if it does, it returns the testname.
763 2) Like test-art-host-run-test-debug-prebuild-interpreter-no-relocate-ntrace-cms-checkjni-picimage-npictest-ndebuggable-001-HelloWorld32
764 In this case, it will parse all the variants and check if they are placed
765 correctly. If yes, it will set the various VARIANT_TYPES to use the
766 variants required to run the test. Again, it returns the test_name
767 without the variant information like 001-HelloWorld.
768 """
Shubham Ajmerafaf12502017-02-15 17:19:44 +0000769 test_set = set()
770 for test in RUN_TEST_SET:
771 if test.startswith(test_name):
772 test_set.add(test)
773 if test_set:
774 return test_set
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000775
776 regex = '^test-art-'
777 regex += '(' + '|'.join(VARIANT_TYPE_DICT['target']) + ')-'
778 regex += 'run-test-'
779 regex += '(' + '|'.join(VARIANT_TYPE_DICT['run']) + ')-'
780 regex += '(' + '|'.join(VARIANT_TYPE_DICT['prebuild']) + ')-'
781 regex += '(' + '|'.join(VARIANT_TYPE_DICT['compiler']) + ')-'
782 regex += '(' + '|'.join(VARIANT_TYPE_DICT['relocate']) + ')-'
783 regex += '(' + '|'.join(VARIANT_TYPE_DICT['trace']) + ')-'
784 regex += '(' + '|'.join(VARIANT_TYPE_DICT['gc']) + ')-'
785 regex += '(' + '|'.join(VARIANT_TYPE_DICT['jni']) + ')-'
786 regex += '(' + '|'.join(VARIANT_TYPE_DICT['image']) + ')-'
787 regex += '(' + '|'.join(VARIANT_TYPE_DICT['pictest']) + ')-'
788 regex += '(' + '|'.join(VARIANT_TYPE_DICT['debuggable']) + ')-'
Alex Light8f2c6d42017-04-10 16:27:35 -0700789 regex += '(' + '|'.join(VARIANT_TYPE_DICT['jvmti']) + ')-'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000790 regex += '(' + '|'.join(RUN_TEST_SET) + ')'
791 regex += '(' + '|'.join(VARIANT_TYPE_DICT['address_sizes']) + ')$'
792 match = re.match(regex, test_name)
793 if match:
794 TARGET_TYPES.add(match.group(1))
795 RUN_TYPES.add(match.group(2))
796 PREBUILD_TYPES.add(match.group(3))
797 COMPILER_TYPES.add(match.group(4))
798 RELOCATE_TYPES.add(match.group(5))
799 TRACE_TYPES.add(match.group(6))
800 GC_TYPES.add(match.group(7))
801 JNI_TYPES.add(match.group(8))
802 IMAGE_TYPES.add(match.group(9))
803 PICTEST_TYPES.add(match.group(10))
804 DEBUGGABLE_TYPES.add(match.group(11))
Alex Light8f2c6d42017-04-10 16:27:35 -0700805 JVMTI_TYPES.add(match.group(12))
806 ADDRESS_SIZES.add(match.group(14))
807 return {match.group(13)}
Shubham Ajmerafaf12502017-02-15 17:19:44 +0000808 raise ValueError(test_name + " is not a valid test")
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000809
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800810
811def setup_env_for_build_target(build_target, parser, options):
812 """Setup environment for the build target
813
814 The method setup environment for the master-art-host targets.
815 """
816 os.environ.update(build_target['env'])
817 os.environ['SOONG_ALLOW_MISSING_DEPENDENCIES'] = 'true'
818 print_text('%s\n' % (str(os.environ)))
819
820 target_options = vars(parser.parse_args(build_target['flags']))
821 target_options['host'] = True
822 target_options['verbose'] = True
823 target_options['build'] = True
824 target_options['n_thread'] = options['n_thread']
825 target_options['dry_run'] = options['dry_run']
826
827 return target_options
828
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700829def get_default_threads(target):
830 if target is 'target':
831 adb_command = 'adb shell cat /sys/devices/system/cpu/present'
832 cpu_info_proc = subprocess.Popen(adb_command.split(), stdout=subprocess.PIPE)
833 cpu_info = cpu_info_proc.stdout.read()
Shubham Ajmera8fd26942017-05-09 11:30:47 -0700834 if type(cpu_info) is bytes:
835 cpu_info = cpu_info.decode('utf-8')
836 cpu_info_regex = '\d*-(\d*)'
837 match = re.match(cpu_info_regex, cpu_info)
838 if match:
839 return int(match.group(1))
840 else:
841 raise ValueError('Unable to predict the concurrency for the target. '
842 'Is device connected?')
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700843 else:
844 return multiprocessing.cpu_count()
845
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000846def parse_option():
847 global verbose
848 global dry_run
849 global n_thread
850 global build
851 global gdb
852 global gdb_arg
Shubham Ajmerafe793492017-03-16 13:31:35 -0700853 global timeout
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000854
Alex Light7a1ccf82017-02-21 09:52:34 -0800855 parser = argparse.ArgumentParser(description="Runs all or a subset of the ART test suite.")
856 parser.add_argument('-t', '--test', dest='test', help='name of the test')
857 parser.add_argument('-j', type=int, dest='n_thread')
Shubham Ajmerafe793492017-03-16 13:31:35 -0700858 parser.add_argument('--timeout', default=timeout, type=int, dest='timeout')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000859 for variant in TOTAL_VARIANTS_SET:
860 flag = '--' + variant
861 flag_dest = variant.replace('-', '_')
862 if variant == '32' or variant == '64':
863 flag_dest = 'n' + flag_dest
Alex Light7a1ccf82017-02-21 09:52:34 -0800864 parser.add_argument(flag, action='store_true', dest=flag_dest)
865 parser.add_argument('--verbose', '-v', action='store_true', dest='verbose')
866 parser.add_argument('--dry-run', action='store_true', dest='dry_run')
867 parser.add_argument("--skip", action="append", dest="skips", default=[],
868 help="Skip the given test in all circumstances.")
Alex Light9b6b13e2017-02-22 11:46:50 -0800869 parser.add_argument('--no-build-dependencies',
870 action='store_false', dest='build',
871 help="Don't build dependencies under any circumstances. This is the " +
872 "behavior if ART_TEST_RUN_TEST_ALWAYS_BUILD is not set to 'true'.")
873 parser.add_argument('-b', '--build-dependencies',
874 action='store_true', dest='build',
875 help="Build dependencies under all circumstances. By default we will " +
876 "not build dependencies unless ART_TEST_RUN_TEST_BUILD=true.")
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800877 parser.add_argument('--build-target', dest='build_target', help='master-art-host targets')
Alex Light9b6b13e2017-02-22 11:46:50 -0800878 parser.set_defaults(build = env.ART_TEST_RUN_TEST_BUILD)
Alex Light7a1ccf82017-02-21 09:52:34 -0800879 parser.add_argument('--gdb', action='store_true', dest='gdb')
880 parser.add_argument('--gdb-arg', dest='gdb_arg')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000881
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800882 options = vars(parser.parse_args())
883 if options['build_target']:
884 options = setup_env_for_build_target(target_config[options['build_target']],
885 parser, options)
886
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000887 test = ''
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800888 env.EXTRA_DISABLED_TESTS.update(set(options['skips']))
889 if options['test']:
890 test = parse_test_name(options['test'])
891 if options['pictest']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000892 PICTEST_TYPES.add('pictest')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800893 if options['ndebug']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000894 RUN_TYPES.add('ndebug')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800895 if options['interp_ac']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000896 COMPILER_TYPES.add('interp-ac')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800897 if options['picimage']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000898 IMAGE_TYPES.add('picimage')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800899 if options['n64']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000900 ADDRESS_SIZES.add('64')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800901 if options['interpreter']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000902 COMPILER_TYPES.add('interpreter')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800903 if options['jni']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000904 JNI_TYPES.add('jni')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800905 if options['relocate_npatchoat']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000906 RELOCATE_TYPES.add('relocate-npatchoat')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800907 if options['no_prebuild']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000908 PREBUILD_TYPES.add('no-prebuild')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800909 if options['npictest']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000910 PICTEST_TYPES.add('npictest')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800911 if options['no_dex2oat']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000912 PREBUILD_TYPES.add('no-dex2oat')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800913 if options['jit']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000914 COMPILER_TYPES.add('jit')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800915 if options['relocate']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000916 RELOCATE_TYPES.add('relocate')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800917 if options['ndebuggable']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000918 DEBUGGABLE_TYPES.add('ndebuggable')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800919 if options['no_image']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000920 IMAGE_TYPES.add('no-image')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800921 if options['optimizing']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000922 COMPILER_TYPES.add('optimizing')
Jeff Hao002b9312017-03-27 16:23:08 -0700923 if options['speed_profile']:
924 COMPILER_TYPES.add('speed-profile')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800925 if options['trace']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000926 TRACE_TYPES.add('trace')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800927 if options['gcstress']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000928 GC_TYPES.add('gcstress')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800929 if options['no_relocate']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000930 RELOCATE_TYPES.add('no-relocate')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800931 if options['target']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000932 TARGET_TYPES.add('target')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800933 if options['forcecopy']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000934 JNI_TYPES.add('forcecopy')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800935 if options['n32']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000936 ADDRESS_SIZES.add('32')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800937 if options['host']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000938 TARGET_TYPES.add('host')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800939 if options['gcverify']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000940 GC_TYPES.add('gcverify')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800941 if options['debuggable']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000942 DEBUGGABLE_TYPES.add('debuggable')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800943 if options['prebuild']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000944 PREBUILD_TYPES.add('prebuild')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800945 if options['debug']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000946 RUN_TYPES.add('debug')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800947 if options['checkjni']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000948 JNI_TYPES.add('checkjni')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800949 if options['ntrace']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000950 TRACE_TYPES.add('ntrace')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800951 if options['cms']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000952 GC_TYPES.add('cms')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800953 if options['multipicimage']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000954 IMAGE_TYPES.add('multipicimage')
Alex Light8f2c6d42017-04-10 16:27:35 -0700955 if options['jvmti_stress']:
956 JVMTI_TYPES.add('jvmti-stress')
957 if options['no_jvmti']:
958 JVMTI_TYPES.add('no-jvmti')
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800959 if options['verbose']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000960 verbose = True
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800961 if options['n_thread']:
962 n_thread = max(1, options['n_thread'])
963 if options['dry_run']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000964 dry_run = True
965 verbose = True
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800966 build = options['build']
967 if options['gdb']:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000968 n_thread = 1
969 gdb = True
Shubham Ajmerab9d09ca2017-03-07 10:45:05 -0800970 if options['gdb_arg']:
971 gdb_arg = options['gdb_arg']
Shubham Ajmerafe793492017-03-16 13:31:35 -0700972 timeout = options['timeout']
Shubham Ajmera22499e22017-03-22 18:33:37 -0700973
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000974 return test
975
976def main():
977 gather_test_info()
978 user_requested_test = parse_option()
979 setup_test_env()
980 if build:
981 build_targets = ''
982 if 'host' in TARGET_TYPES:
983 build_targets += 'test-art-host-run-test-dependencies'
984 if 'target' in TARGET_TYPES:
985 build_targets += 'test-art-target-run-test-dependencies'
Shubham Ajmera06cde292017-02-10 23:15:05 +0000986 build_command = 'make'
Shubham Ajmera4a5a1622017-03-22 10:07:19 -0700987 build_command += ' -j'
Shubham Ajmera06cde292017-02-10 23:15:05 +0000988 build_command += ' -C ' + env.ANDROID_BUILD_TOP
989 build_command += ' ' + build_targets
Nicolas Geoffray300c09b2017-03-22 12:26:32 +0000990 # Add 'dist' to avoid Jack issues b/36169180.
991 build_command += ' dist'
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000992 if subprocess.call(build_command.split()):
993 sys.exit(1)
994 if user_requested_test:
995 test_runner_thread = threading.Thread(target=run_tests, args=(user_requested_test,))
996 else:
997 test_runner_thread = threading.Thread(target=run_tests, args=(RUN_TEST_SET,))
998 test_runner_thread.daemon = True
999 try:
1000 test_runner_thread.start()
1001 while threading.active_count() > 1:
1002 time.sleep(0.1)
1003 print_analysis()
Shubham Ajmerafe793492017-03-16 13:31:35 -07001004 except Exception as e:
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001005 print_analysis()
Shubham Ajmerafaf12502017-02-15 17:19:44 +00001006 print_text(str(e))
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001007 sys.exit(1)
Shubham Ajmerac5aae872017-02-16 19:58:59 +00001008 if failed_tests:
1009 sys.exit(1)
1010 sys.exit(0)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001011
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001012if __name__ == '__main__':
1013 main()