xref: /aosp_15_r20/art/test.py (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker#!/usr/bin/env python3
2*795d594fSAndroid Build Coastguard Worker#
3*795d594fSAndroid Build Coastguard Worker# Copyright 2017, The Android Open Source Project
4*795d594fSAndroid Build Coastguard Worker#
5*795d594fSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*795d594fSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*795d594fSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*795d594fSAndroid Build Coastguard Worker#
9*795d594fSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
10*795d594fSAndroid Build Coastguard Worker#
11*795d594fSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*795d594fSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*795d594fSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*795d594fSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*795d594fSAndroid Build Coastguard Worker# limitations under the License.
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker# --run-test : To run run-test
18*795d594fSAndroid Build Coastguard Worker# --gtest : To run gtest
19*795d594fSAndroid Build Coastguard Worker# -j : Number of jobs
20*795d594fSAndroid Build Coastguard Worker# --host: for host tests
21*795d594fSAndroid Build Coastguard Worker# --target: for target tests
22*795d594fSAndroid Build Coastguard Worker# All the other arguments will be passed to the run-test testrunner.
23*795d594fSAndroid Build Coastguard Workerimport sys
24*795d594fSAndroid Build Coastguard Workerimport subprocess
25*795d594fSAndroid Build Coastguard Workerimport os
26*795d594fSAndroid Build Coastguard Workerimport argparse
27*795d594fSAndroid Build Coastguard Worker
28*795d594fSAndroid Build Coastguard WorkerANDROID_BUILD_TOP = os.environ.get('ANDROID_BUILD_TOP', os.getcwd())
29*795d594fSAndroid Build Coastguard WorkerTEST_RUNNER = 'art/test/testrunner/testrunner.py'
30*795d594fSAndroid Build Coastguard Worker
31*795d594fSAndroid Build Coastguard Workerparser = argparse.ArgumentParser(
32*795d594fSAndroid Build Coastguard Worker    description='Test runner wrapper to run ART run tests. All unrecognised ' +
33*795d594fSAndroid Build Coastguard Worker    'arguments are passed on to ' + TEST_RUNNER + '.')
34*795d594fSAndroid Build Coastguard Workerparser.add_argument('-j', default='', dest='n_threads', help='specify number of concurrent tests')
35*795d594fSAndroid Build Coastguard Workerparser.add_argument('--run-test', '-r', action='store_true', dest='run_test', help='execute run tests')
36*795d594fSAndroid Build Coastguard Workerparser.add_argument('--gtest', '-g', action='store_true', dest='gtest', help='execute gtest tests')
37*795d594fSAndroid Build Coastguard Workerparser.add_argument('--target', action='store_true', dest='target', help='test on target system')
38*795d594fSAndroid Build Coastguard Workerparser.add_argument('--host', action='store_true', dest='host', help='test on build host system')
39*795d594fSAndroid Build Coastguard Workerparser.add_argument('--help-runner', action='store_true', dest='help_runner', help='show help for optional run test arguments')
40*795d594fSAndroid Build Coastguard Workeroptions, unknown = parser.parse_known_args()
41*795d594fSAndroid Build Coastguard Worker
42*795d594fSAndroid Build Coastguard Workerif options.run_test or options.help_runner or not options.gtest:
43*795d594fSAndroid Build Coastguard Worker  testrunner = os.path.join('./', ANDROID_BUILD_TOP, TEST_RUNNER)
44*795d594fSAndroid Build Coastguard Worker  run_test_args = []
45*795d594fSAndroid Build Coastguard Worker  for arg in sys.argv[1:]:
46*795d594fSAndroid Build Coastguard Worker    if arg == '--run-test' or arg == '--gtest' \
47*795d594fSAndroid Build Coastguard Worker    or arg == '-r' or arg == '-g':
48*795d594fSAndroid Build Coastguard Worker      continue
49*795d594fSAndroid Build Coastguard Worker    if arg == '--help-runner':
50*795d594fSAndroid Build Coastguard Worker      run_test_args = ['--help']
51*795d594fSAndroid Build Coastguard Worker      break
52*795d594fSAndroid Build Coastguard Worker    run_test_args.append(arg)
53*795d594fSAndroid Build Coastguard Worker
54*795d594fSAndroid Build Coastguard Worker  test_runner_cmd = [testrunner] + run_test_args
55*795d594fSAndroid Build Coastguard Worker  print(' '.join(test_runner_cmd))
56*795d594fSAndroid Build Coastguard Worker  if subprocess.call(test_runner_cmd) or options.help_runner:
57*795d594fSAndroid Build Coastguard Worker    sys.exit(1)
58*795d594fSAndroid Build Coastguard Worker
59*795d594fSAndroid Build Coastguard Workerif options.gtest or not options.run_test:
60*795d594fSAndroid Build Coastguard Worker  build_target = ''
61*795d594fSAndroid Build Coastguard Worker  if options.host or not options.target:
62*795d594fSAndroid Build Coastguard Worker    build_target += ' test-art-host-gtest'
63*795d594fSAndroid Build Coastguard Worker  if options.target or not options.host:
64*795d594fSAndroid Build Coastguard Worker    build_target += ' test-art-target-gtest'
65*795d594fSAndroid Build Coastguard Worker
66*795d594fSAndroid Build Coastguard Worker  build_command = ANDROID_BUILD_TOP + '/build/soong/soong_ui.bash --make-mode'
67*795d594fSAndroid Build Coastguard Worker  build_command += ' -j' + str(options.n_threads)
68*795d594fSAndroid Build Coastguard Worker  build_command += ' ' + build_target
69*795d594fSAndroid Build Coastguard Worker  print(build_command)
70*795d594fSAndroid Build Coastguard Worker  if subprocess.call(build_command.split(), cwd=ANDROID_BUILD_TOP):
71*795d594fSAndroid Build Coastguard Worker    sys.exit(1)
72*795d594fSAndroid Build Coastguard Worker
73*795d594fSAndroid Build Coastguard Workersys.exit(0)
74