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