1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2023-2024 Huawei Device Co., Ltd. 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 17import argparse 18import os 19import subprocess 20import sys 21from pathlib import Path 22 23 24def parse_options(): 25 # panda root default 26 panda_env = os.environ.get('PANDA_ROOT') 27 arkdir_default = panda_env if panda_env else os.path.join(Path.home(), 'panda') 28 29 # panda build dir 30 panda_binary_env = os.environ.get('PANDA_BINARY_ROOT') 31 builddir_default = panda_binary_env if panda_binary_env else os.path.join(Path.home(), 'panda', 'build') 32 33 parser = argparse.ArgumentParser(epilog='Run the selected benchmark with Ark') 34 parser.add_argument('--arkdir', metavar='DIR', default=arkdir_default, 35 help='specify ark directory (default: %(default)s)') 36 parser.add_argument('--builddir', metavar='DIR', default=builddir_default, 37 help='specify ark directory (default: %(default)s)') 38 parser.add_argument('--timeout', metavar='SEC', type=int, default=60, help='timeout (default: %(default)s)') 39 parser.add_argument('-rt', '--runtime', action='store_true', dest='runtime', help='Runtime tests') 40 parser.add_argument('-r', '--regression', action='store_true', dest='regression', help='Regression tests') 41 parser.add_argument('-cts', '--cts', action='store_true', dest='cts', help='CTS tests') 42 parser.add_argument('-f', '--func', action='store_true', dest='functional', help='Functional tests') 43 parser.add_argument('-t', '--test262', action='store_true', dest='test262', help='Test262 tests') 44 parser.add_argument('--all', action='store_true', dest='all', help='Run the listed benchmarks') 45 46 return parser.parse_args() 47 48 49def main(): 50 options = parse_options() 51 52 if not os.path.exists(options.arkdir): 53 print("The following ark directory does not exist: {0}".format(options.arkdir)) 54 sys.exit(1) 55 56 if not os.path.exists(options.builddir): 57 print("The following build directory does not exist: {0}".format(options.builddir)) 58 sys.exit(1) 59 60 testrunner = os.path.join(options.arkdir, 'tests', 'tests-u-runner', 'main.py') 61 62 if not os.path.isfile(testrunner): 63 print("The following script is not executable or exist: {0}".format(testrunner)) 64 65 general_cmd = [ 66 'python', testrunner, '--build-dir', options.builddir, '--force-generate', 67 '--show-progress', '--processes', 'all', '--timeout', str(options.timeout) 68 ] 69 70 if options.all: 71 options.regression = options.runtime = options.cts = options.functional = options.test262 = True 72 73 if options.regression: 74 res = subprocess.call(general_cmd + ['--parser']) 75 if options.runtime: 76 res = subprocess.call(general_cmd + ['--ets-runtime']) 77 if options.functional: 78 res = subprocess.call(general_cmd + ['--ets-func-tests']) 79 if options.test262: 80 res = subprocess.call(general_cmd + ['--test262']) 81 if options.cts: 82 res = subprocess.call(general_cmd + ['--ets-cts']) 83 84 85if __name__ == '__main__': 86 main() 87