11cb0ef41Sopenharmony_ci# Copyright 2012 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci# Redistribution and use in source and binary forms, with or without 31cb0ef41Sopenharmony_ci# modification, are permitted provided that the following conditions are 41cb0ef41Sopenharmony_ci# met: 51cb0ef41Sopenharmony_ci# 61cb0ef41Sopenharmony_ci# * Redistributions of source code must retain the above copyright 71cb0ef41Sopenharmony_ci# notice, this list of conditions and the following disclaimer. 81cb0ef41Sopenharmony_ci# * Redistributions in binary form must reproduce the above 91cb0ef41Sopenharmony_ci# copyright notice, this list of conditions and the following 101cb0ef41Sopenharmony_ci# disclaimer in the documentation and/or other materials provided 111cb0ef41Sopenharmony_ci# with the distribution. 121cb0ef41Sopenharmony_ci# * Neither the name of Google Inc. nor the names of its 131cb0ef41Sopenharmony_ci# contributors may be used to endorse or promote products derived 141cb0ef41Sopenharmony_ci# from this software without specific prior written permission. 151cb0ef41Sopenharmony_ci# 161cb0ef41Sopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171cb0ef41Sopenharmony_ci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181cb0ef41Sopenharmony_ci# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191cb0ef41Sopenharmony_ci# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201cb0ef41Sopenharmony_ci# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211cb0ef41Sopenharmony_ci# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221cb0ef41Sopenharmony_ci# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231cb0ef41Sopenharmony_ci# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241cb0ef41Sopenharmony_ci# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251cb0ef41Sopenharmony_ci# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261cb0ef41Sopenharmony_ci# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_cifrom os.path import exists 291cb0ef41Sopenharmony_cifrom os.path import isdir 301cb0ef41Sopenharmony_cifrom os.path import join 311cb0ef41Sopenharmony_ciimport os 321cb0ef41Sopenharmony_ciimport platform 331cb0ef41Sopenharmony_ciimport re 341cb0ef41Sopenharmony_ciimport urllib 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci### Exit codes and their meaning. 381cb0ef41Sopenharmony_ci# Normal execution. 391cb0ef41Sopenharmony_ciEXIT_CODE_PASS = 0 401cb0ef41Sopenharmony_ci# Execution with test failures. 411cb0ef41Sopenharmony_ciEXIT_CODE_FAILURES = 1 421cb0ef41Sopenharmony_ci# Execution with no tests executed. 431cb0ef41Sopenharmony_ciEXIT_CODE_NO_TESTS = 2 441cb0ef41Sopenharmony_ci# Execution aborted with SIGINT (Ctrl-C). 451cb0ef41Sopenharmony_ciEXIT_CODE_INTERRUPTED = 3 461cb0ef41Sopenharmony_ci# Execution aborted with SIGTERM. 471cb0ef41Sopenharmony_ciEXIT_CODE_TERMINATED = 4 481cb0ef41Sopenharmony_ci# Internal error. 491cb0ef41Sopenharmony_ciEXIT_CODE_INTERNAL_ERROR = 5 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_cidef GetSuitePaths(test_root): 531cb0ef41Sopenharmony_ci return [ f for f in os.listdir(test_root) if isdir(join(test_root, f)) ] 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci# Reads a file into an array of strings 571cb0ef41Sopenharmony_cidef ReadLinesFrom(name): 581cb0ef41Sopenharmony_ci lines = [] 591cb0ef41Sopenharmony_ci with open(name) as f: 601cb0ef41Sopenharmony_ci for line in f: 611cb0ef41Sopenharmony_ci if line.startswith('#'): continue 621cb0ef41Sopenharmony_ci if '#' in line: 631cb0ef41Sopenharmony_ci line = line[:line.find('#')] 641cb0ef41Sopenharmony_ci line = line.strip() 651cb0ef41Sopenharmony_ci if not line: continue 661cb0ef41Sopenharmony_ci lines.append(line) 671cb0ef41Sopenharmony_ci return lines 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_cidef GuessOS(): 711cb0ef41Sopenharmony_ci system = platform.system() 721cb0ef41Sopenharmony_ci if system == 'Linux': 731cb0ef41Sopenharmony_ci return 'linux' 741cb0ef41Sopenharmony_ci elif system == 'Darwin': 751cb0ef41Sopenharmony_ci return 'macos' 761cb0ef41Sopenharmony_ci elif system.find('CYGWIN') >= 0: 771cb0ef41Sopenharmony_ci return 'cygwin' 781cb0ef41Sopenharmony_ci elif system == 'Windows' or system == 'Microsoft': 791cb0ef41Sopenharmony_ci # On Windows Vista platform.system() can return 'Microsoft' with some 801cb0ef41Sopenharmony_ci # versions of Python, see http://bugs.python.org/issue1082 811cb0ef41Sopenharmony_ci return 'windows' 821cb0ef41Sopenharmony_ci elif system == 'FreeBSD': 831cb0ef41Sopenharmony_ci return 'freebsd' 841cb0ef41Sopenharmony_ci elif system == 'OpenBSD': 851cb0ef41Sopenharmony_ci return 'openbsd' 861cb0ef41Sopenharmony_ci elif system == 'SunOS': 871cb0ef41Sopenharmony_ci return 'solaris' 881cb0ef41Sopenharmony_ci elif system == 'NetBSD': 891cb0ef41Sopenharmony_ci return 'netbsd' 901cb0ef41Sopenharmony_ci elif system in ['AIX', 'OS400']: 911cb0ef41Sopenharmony_ci # OS400 runs an AIX emulator called PASE 921cb0ef41Sopenharmony_ci return 'aix' 931cb0ef41Sopenharmony_ci else: 941cb0ef41Sopenharmony_ci return None 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci# Check if Vector Enhancement Facility 1 is available on the 981cb0ef41Sopenharmony_ci# host S390 machine. This facility is required for supporting Simd on V8. 991cb0ef41Sopenharmony_cidef IsS390SimdSupported(): 1001cb0ef41Sopenharmony_ci import subprocess 1011cb0ef41Sopenharmony_ci cpuinfo = subprocess.check_output("cat /proc/cpuinfo", shell=True) 1021cb0ef41Sopenharmony_ci cpuinfo_list = cpuinfo.strip().decode("utf-8").splitlines() 1031cb0ef41Sopenharmony_ci facilities = "".join(x for x in cpuinfo_list if x.startswith("facilities")) 1041cb0ef41Sopenharmony_ci facilities_list = facilities.split(" ") 1051cb0ef41Sopenharmony_ci # Having bit 135 set indicates VEF1 is available. 1061cb0ef41Sopenharmony_ci return "135" in facilities_list 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ci# Returns power processor version, taking compatibility mode into account. 1101cb0ef41Sopenharmony_ci# (Power9 running in Power8 compatibility mode returns 8) 1111cb0ef41Sopenharmony_ci# Only useful if arch is ppc64 1121cb0ef41Sopenharmony_cidef GuessPowerProcessorVersion(): 1131cb0ef41Sopenharmony_ci import ctypes, ctypes.util 1141cb0ef41Sopenharmony_ci os = GuessOS() 1151cb0ef41Sopenharmony_ci if os == 'linux': 1161cb0ef41Sopenharmony_ci AT_PLATFORM = 15 # from linux/auxvec.h 1171cb0ef41Sopenharmony_ci _LIBC = ctypes.CDLL(ctypes.util.find_library('c')) 1181cb0ef41Sopenharmony_ci _LIBC.getauxval.argtypes = [ctypes.c_ulong] 1191cb0ef41Sopenharmony_ci _LIBC.getauxval.restype = ctypes.c_char_p 1201cb0ef41Sopenharmony_ci at_platform = _LIBC.getauxval(AT_PLATFORM).decode('utf-8').lower() 1211cb0ef41Sopenharmony_ci if at_platform.startswith('power6'): 1221cb0ef41Sopenharmony_ci return 6 1231cb0ef41Sopenharmony_ci elif at_platform.startswith('power7'): 1241cb0ef41Sopenharmony_ci return 7 1251cb0ef41Sopenharmony_ci elif at_platform.startswith('power8'): 1261cb0ef41Sopenharmony_ci return 8 1271cb0ef41Sopenharmony_ci elif at_platform.startswith('power9'): 1281cb0ef41Sopenharmony_ci return 9 1291cb0ef41Sopenharmony_ci elif at_platform.startswith('power10'): 1301cb0ef41Sopenharmony_ci return 10 1311cb0ef41Sopenharmony_ci else: 1321cb0ef41Sopenharmony_ci raise Exception('Unable to guess power processor version') 1331cb0ef41Sopenharmony_ci elif os == 'aix': 1341cb0ef41Sopenharmony_ci # covers aix and os400 1351cb0ef41Sopenharmony_ci RTLD_MEMBER = 0x00040000 1361cb0ef41Sopenharmony_ci _LIBC = ctypes.CDLL(ctypes.util.find_library('c'), 1371cb0ef41Sopenharmony_ci ctypes.DEFAULT_MODE | RTLD_MEMBER) 1381cb0ef41Sopenharmony_ci class _system_configuration(ctypes.Structure): 1391cb0ef41Sopenharmony_ci _fields_ = [ 1401cb0ef41Sopenharmony_ci ('architecture', ctypes.c_int), 1411cb0ef41Sopenharmony_ci ('implementation', ctypes.c_int), 1421cb0ef41Sopenharmony_ci ] 1431cb0ef41Sopenharmony_ci cfg = _system_configuration.in_dll(_LIBC, '_system_configuration') 1441cb0ef41Sopenharmony_ci # Values found in sys/systemcfg.h 1451cb0ef41Sopenharmony_ci if cfg.implementation == 0x4000: 1461cb0ef41Sopenharmony_ci return 6 1471cb0ef41Sopenharmony_ci elif cfg.implementation == 0x8000: 1481cb0ef41Sopenharmony_ci return 7 1491cb0ef41Sopenharmony_ci elif cfg.implementation == 0x10000: 1501cb0ef41Sopenharmony_ci return 8 1511cb0ef41Sopenharmony_ci elif cfg.implementation == 0x20000: 1521cb0ef41Sopenharmony_ci return 9 1531cb0ef41Sopenharmony_ci elif cfg.implementation == 0x40000: 1541cb0ef41Sopenharmony_ci return 10 1551cb0ef41Sopenharmony_ci else: 1561cb0ef41Sopenharmony_ci raise Exception('Unable to guess power processor version') 1571cb0ef41Sopenharmony_ci else: 1581cb0ef41Sopenharmony_ci raise Exception('Unable to guess power processor version') 1591cb0ef41Sopenharmony_ci 1601cb0ef41Sopenharmony_ci 1611cb0ef41Sopenharmony_cidef UseSimulator(arch): 1621cb0ef41Sopenharmony_ci machine = platform.machine() 1631cb0ef41Sopenharmony_ci return (machine and 1641cb0ef41Sopenharmony_ci (arch == "mipsel" or arch == "arm" or arch == "arm64") and 1651cb0ef41Sopenharmony_ci not arch.startswith(machine)) 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ci 1681cb0ef41Sopenharmony_ci# This will default to building the 32 bit VM even on machines that are 1691cb0ef41Sopenharmony_ci# capable of running the 64 bit VM. 1701cb0ef41Sopenharmony_cidef DefaultArch(): 1711cb0ef41Sopenharmony_ci machine = platform.machine() 1721cb0ef41Sopenharmony_ci machine = machine.lower() # Windows 7 capitalizes 'AMD64'. 1731cb0ef41Sopenharmony_ci if machine.startswith('arm'): 1741cb0ef41Sopenharmony_ci return 'arm' 1751cb0ef41Sopenharmony_ci elif (not machine) or (not re.match('(x|i[3-6])86$', machine) is None): 1761cb0ef41Sopenharmony_ci return 'ia32' 1771cb0ef41Sopenharmony_ci elif machine == 'i86pc': 1781cb0ef41Sopenharmony_ci return 'ia32' 1791cb0ef41Sopenharmony_ci elif machine == 'x86_64': 1801cb0ef41Sopenharmony_ci return 'ia32' 1811cb0ef41Sopenharmony_ci elif machine == 'amd64': 1821cb0ef41Sopenharmony_ci return 'ia32' 1831cb0ef41Sopenharmony_ci elif machine == 's390x': 1841cb0ef41Sopenharmony_ci return 's390' 1851cb0ef41Sopenharmony_ci elif machine == 'ppc64': 1861cb0ef41Sopenharmony_ci return 'ppc' 1871cb0ef41Sopenharmony_ci else: 1881cb0ef41Sopenharmony_ci return None 1891cb0ef41Sopenharmony_ci 1901cb0ef41Sopenharmony_ci 1911cb0ef41Sopenharmony_cidef GuessWordsize(): 1921cb0ef41Sopenharmony_ci if '64' in platform.machine(): 1931cb0ef41Sopenharmony_ci return '64' 1941cb0ef41Sopenharmony_ci else: 1951cb0ef41Sopenharmony_ci return '32' 1961cb0ef41Sopenharmony_ci 1971cb0ef41Sopenharmony_ci 1981cb0ef41Sopenharmony_cidef IsWindows(): 1991cb0ef41Sopenharmony_ci return GuessOS() == 'windows' 2001cb0ef41Sopenharmony_ci 2011cb0ef41Sopenharmony_ci 2021cb0ef41Sopenharmony_ciclass FrozenDict(dict): 2031cb0ef41Sopenharmony_ci def __setitem__(self, *args, **kwargs): 2041cb0ef41Sopenharmony_ci raise Exception('Tried to mutate a frozen dict') 2051cb0ef41Sopenharmony_ci 2061cb0ef41Sopenharmony_ci def update(self, *args, **kwargs): 2071cb0ef41Sopenharmony_ci raise Exception('Tried to mutate a frozen dict') 2081cb0ef41Sopenharmony_ci 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_cidef Freeze(obj): 2111cb0ef41Sopenharmony_ci if isinstance(obj, dict): 2121cb0ef41Sopenharmony_ci return FrozenDict((k, Freeze(v)) for k, v in list(obj.items())) 2131cb0ef41Sopenharmony_ci elif isinstance(obj, set): 2141cb0ef41Sopenharmony_ci return frozenset(obj) 2151cb0ef41Sopenharmony_ci elif isinstance(obj, list): 2161cb0ef41Sopenharmony_ci return tuple(Freeze(item) for item in obj) 2171cb0ef41Sopenharmony_ci else: 2181cb0ef41Sopenharmony_ci # Make sure object is hashable. 2191cb0ef41Sopenharmony_ci hash(obj) 2201cb0ef41Sopenharmony_ci return obj 221