Home | History | Annotate | Download | only in testrunner
      1 # Copyright 2017, The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #     http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 
     15 import os
     16 import re
     17 import tempfile
     18 import subprocess
     19 
     20 # begin import $ANDROID_BUILD_TOP/art/tools/build/var_cache.py
     21 _THIS_DIR = os.path.dirname(os.path.realpath(__file__))
     22 _TOP = os.path.join(_THIS_DIR, "../../..")
     23 _VAR_CACHE_DIR = os.path.join(_TOP, "art/tools/build/")
     24 
     25 import sys
     26 sys.path.append(_VAR_CACHE_DIR)
     27 import var_cache
     28 # end import var_cache.py
     29 
     30 _env = dict(os.environ)
     31 
     32 def _getEnvBoolean(var, default):
     33   val = _env.get(var)
     34   if val:
     35     if val == "True" or val == "true":
     36       return True
     37     if val == "False" or val == "false":
     38       return False
     39   return default
     40 
     41 def _get_build_var(var_name):
     42   return var_cache.get_build_var(var_name)
     43 
     44 def _get_build_var_boolean(var, default):
     45   val = _get_build_var(var)
     46   if val:
     47     if val == "True" or val == "true":
     48       return True
     49     if val == "False" or val == "false":
     50       return False
     51   return default
     52 
     53 def get_env(key):
     54   return _env.get(key)
     55 
     56 def _get_android_build_top():
     57   path_to_top = _env.get('ANDROID_BUILD_TOP')
     58   if not path_to_top:
     59     # nothing set. try to guess it based on the relative path of this env.py file.
     60     this_file_path = os.path.realpath(__file__)
     61     path_to_top = os.path.join(os.path.dirname(this_file_path), '../../../')
     62     path_to_top = os.path.realpath(path_to_top)
     63 
     64   if not os.path.exists(os.path.join(path_to_top, 'build/envsetup.sh')):
     65     raise AssertionError("env.py must be located inside an android source tree")
     66 
     67   return path_to_top
     68 
     69 ANDROID_BUILD_TOP = _get_android_build_top()
     70 
     71 # Directory used for temporary test files on the host.
     72 ART_HOST_TEST_DIR = tempfile.mkdtemp(prefix = 'test-art-')
     73 
     74 # Keep going after encountering a test failure?
     75 ART_TEST_KEEP_GOING = _getEnvBoolean('ART_TEST_KEEP_GOING', True)
     76 
     77 # Do you want failed tests to have their artifacts cleaned up?
     78 ART_TEST_RUN_TEST_ALWAYS_CLEAN = _getEnvBoolean('ART_TEST_RUN_TEST_ALWAYS_CLEAN', True)
     79 
     80 ART_TEST_BISECTION = _getEnvBoolean('ART_TEST_BISECTION', False)
     81 
     82 DEX2OAT_HOST_INSTRUCTION_SET_FEATURES = _env.get('DEX2OAT_HOST_INSTRUCTION_SET_FEATURES')
     83 
     84 # Do you want run-tests with the host/target's second arch?
     85 ART_TEST_RUN_TEST_2ND_ARCH = _getEnvBoolean('ART_TEST_RUN_TEST_2ND_ARCH', True)
     86 
     87 HOST_2ND_ARCH_PREFIX = _get_build_var('HOST_2ND_ARCH_PREFIX')
     88 HOST_2ND_ARCH_PREFIX_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES = _env.get(
     89   HOST_2ND_ARCH_PREFIX + 'DEX2OAT_HOST_INSTRUCTION_SET_FEATURES')
     90 
     91 ART_TEST_CHROOT = _env.get('ART_TEST_CHROOT')
     92 ART_TEST_ANDROID_ROOT = _env.get('ART_TEST_ANDROID_ROOT')
     93 ART_TEST_ANDROID_RUNTIME_ROOT = _env.get('ART_TEST_ANDROID_RUNTIME_ROOT')
     94 ART_TEST_ANDROID_TZDATA_ROOT = _env.get('ART_TEST_ANDROID_TZDATA_ROOT')
     95 
     96 ART_TEST_WITH_STRACE = _getEnvBoolean('ART_TEST_DEBUG_GC', False)
     97 
     98 EXTRA_DISABLED_TESTS = set(_env.get("ART_TEST_RUN_TEST_SKIP", "").split())
     99 
    100 ART_TEST_RUN_TEST_BUILD = _getEnvBoolean('ART_TEST_RUN_TEST_BUILD', False)
    101 
    102 TARGET_2ND_ARCH = _get_build_var('TARGET_2ND_ARCH')
    103 TARGET_ARCH = _get_build_var('TARGET_ARCH')
    104 
    105 # Note: ART_2ND_PHONY_TEST_TARGET_SUFFIX is 2ND_ART_PHONY_TEST_TARGET_SUFFIX in .mk files
    106 # Note: ART_2ND_PHONY_TEST_HOST_SUFFIX is 2ND_ART_PHONY_HOST_TARGET_SUFFIX in .mk files
    107 # Python does not let us have variable names starting with a digit, so it has differ.
    108 
    109 if TARGET_2ND_ARCH:
    110   if "64" in TARGET_ARCH:
    111     ART_PHONY_TEST_TARGET_SUFFIX = "64"
    112     ART_2ND_PHONY_TEST_TARGET_SUFFIX = "32"
    113   else:
    114     ART_PHONY_TEST_TARGET_SUFFIX = "32"
    115     ART_2ND_PHONY_TEST_TARGET_SUFFIX = ""
    116 else:
    117   if "64" in TARGET_ARCH:
    118     ART_PHONY_TEST_TARGET_SUFFIX = "64"
    119     ART_2ND_PHONY_TEST_TARGET_SUFFIX = ""
    120   else:
    121     ART_PHONY_TEST_TARGET_SUFFIX = "32"
    122     ART_2ND_PHONY_TEST_TARGET_SUFFIX = ""
    123 
    124 HOST_PREFER_32_BIT = _get_build_var('HOST_PREFER_32_BIT')
    125 if HOST_PREFER_32_BIT == "true":
    126   ART_PHONY_TEST_HOST_SUFFIX = "32"
    127   ART_2ND_PHONY_TEST_HOST_SUFFIX = ""
    128 else:
    129   ART_PHONY_TEST_HOST_SUFFIX = "64"
    130   ART_2ND_PHONY_TEST_HOST_SUFFIX = "32"
    131 
    132 HOST_OUT_EXECUTABLES = os.path.join(ANDROID_BUILD_TOP,
    133                                     _get_build_var("HOST_OUT_EXECUTABLES"))
    134 
    135 # Set up default values for $DX, $SMALI, etc to the $HOST_OUT_EXECUTABLES/$name path.
    136 for tool in ['dx', 'smali', 'jasmin', 'd8']:
    137   os.environ.setdefault(tool.upper(), HOST_OUT_EXECUTABLES + '/' + tool)
    138 
    139 ANDROID_JAVA_TOOLCHAIN = os.path.join(ANDROID_BUILD_TOP,
    140                                      _get_build_var('ANDROID_JAVA_TOOLCHAIN'))
    141 
    142 # include platform prebuilt java, javac, etc in $PATH.
    143 os.environ['PATH'] = ANDROID_JAVA_TOOLCHAIN + ':' + os.environ['PATH']
    144 
    145 DIST_DIR = _get_build_var('DIST_DIR')
    146 SOONG_OUT_DIR = _get_build_var('SOONG_OUT_DIR')
    147