13af6ab5fSopenharmony_ci#!/usr/bin/env python3 23af6ab5fSopenharmony_ci# -*- coding: utf-8 -*- 33af6ab5fSopenharmony_ci 43af6ab5fSopenharmony_ci# Copyright (c) 2023-2024 Huawei Device Co., Ltd. 53af6ab5fSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 63af6ab5fSopenharmony_ci# you may not use this file except in compliance with the License. 73af6ab5fSopenharmony_ci# You may obtain a copy of the License at 83af6ab5fSopenharmony_ci# 93af6ab5fSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 103af6ab5fSopenharmony_ci# 113af6ab5fSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 123af6ab5fSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 133af6ab5fSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 143af6ab5fSopenharmony_ci# See the License for the specific language governing permissions and 153af6ab5fSopenharmony_ci# limitations under the License. 163af6ab5fSopenharmony_ci 173af6ab5fSopenharmony_ciimport argparse 183af6ab5fSopenharmony_ciimport os 193af6ab5fSopenharmony_ciimport subprocess 203af6ab5fSopenharmony_ciimport sys 213af6ab5fSopenharmony_cifrom pathlib import Path 223af6ab5fSopenharmony_ci 233af6ab5fSopenharmony_ci 243af6ab5fSopenharmony_cidef parse_options(): 253af6ab5fSopenharmony_ci # panda root default 263af6ab5fSopenharmony_ci panda_env = os.environ.get('PANDA_ROOT') 273af6ab5fSopenharmony_ci arkdir_default = panda_env if panda_env else os.path.join(Path.home(), 'panda') 283af6ab5fSopenharmony_ci 293af6ab5fSopenharmony_ci # panda build dir 303af6ab5fSopenharmony_ci panda_binary_env = os.environ.get('PANDA_BINARY_ROOT') 313af6ab5fSopenharmony_ci builddir_default = panda_binary_env if panda_binary_env else os.path.join(Path.home(), 'panda', 'build') 323af6ab5fSopenharmony_ci 333af6ab5fSopenharmony_ci parser = argparse.ArgumentParser(epilog='Run the selected benchmark with Ark') 343af6ab5fSopenharmony_ci parser.add_argument('--arkdir', metavar='DIR', default=arkdir_default, 353af6ab5fSopenharmony_ci help='specify ark directory (default: %(default)s)') 363af6ab5fSopenharmony_ci parser.add_argument('--builddir', metavar='DIR', default=builddir_default, 373af6ab5fSopenharmony_ci help='specify ark directory (default: %(default)s)') 383af6ab5fSopenharmony_ci parser.add_argument('--timeout', metavar='SEC', type=int, default=60, help='timeout (default: %(default)s)') 393af6ab5fSopenharmony_ci parser.add_argument('-rt', '--runtime', action='store_true', dest='runtime', help='Runtime tests') 403af6ab5fSopenharmony_ci parser.add_argument('-r', '--regression', action='store_true', dest='regression', help='Regression tests') 413af6ab5fSopenharmony_ci parser.add_argument('-cts', '--cts', action='store_true', dest='cts', help='CTS tests') 423af6ab5fSopenharmony_ci parser.add_argument('-f', '--func', action='store_true', dest='functional', help='Functional tests') 433af6ab5fSopenharmony_ci parser.add_argument('-t', '--test262', action='store_true', dest='test262', help='Test262 tests') 443af6ab5fSopenharmony_ci parser.add_argument('--all', action='store_true', dest='all', help='Run the listed benchmarks') 453af6ab5fSopenharmony_ci 463af6ab5fSopenharmony_ci return parser.parse_args() 473af6ab5fSopenharmony_ci 483af6ab5fSopenharmony_ci 493af6ab5fSopenharmony_cidef main(): 503af6ab5fSopenharmony_ci options = parse_options() 513af6ab5fSopenharmony_ci 523af6ab5fSopenharmony_ci if not os.path.exists(options.arkdir): 533af6ab5fSopenharmony_ci print("The following ark directory does not exist: {0}".format(options.arkdir)) 543af6ab5fSopenharmony_ci sys.exit(1) 553af6ab5fSopenharmony_ci 563af6ab5fSopenharmony_ci if not os.path.exists(options.builddir): 573af6ab5fSopenharmony_ci print("The following build directory does not exist: {0}".format(options.builddir)) 583af6ab5fSopenharmony_ci sys.exit(1) 593af6ab5fSopenharmony_ci 603af6ab5fSopenharmony_ci testrunner = os.path.join(options.arkdir, 'tests', 'tests-u-runner', 'main.py') 613af6ab5fSopenharmony_ci 623af6ab5fSopenharmony_ci if not os.path.isfile(testrunner): 633af6ab5fSopenharmony_ci print("The following script is not executable or exist: {0}".format(testrunner)) 643af6ab5fSopenharmony_ci 653af6ab5fSopenharmony_ci general_cmd = [ 663af6ab5fSopenharmony_ci 'python', testrunner, '--build-dir', options.builddir, '--force-generate', 673af6ab5fSopenharmony_ci '--show-progress', '--processes', 'all', '--timeout', str(options.timeout) 683af6ab5fSopenharmony_ci ] 693af6ab5fSopenharmony_ci 703af6ab5fSopenharmony_ci if options.all: 713af6ab5fSopenharmony_ci options.regression = options.runtime = options.cts = options.functional = options.test262 = True 723af6ab5fSopenharmony_ci 733af6ab5fSopenharmony_ci if options.regression: 743af6ab5fSopenharmony_ci res = subprocess.call(general_cmd + ['--parser']) 753af6ab5fSopenharmony_ci if options.runtime: 763af6ab5fSopenharmony_ci res = subprocess.call(general_cmd + ['--ets-runtime']) 773af6ab5fSopenharmony_ci if options.functional: 783af6ab5fSopenharmony_ci res = subprocess.call(general_cmd + ['--ets-func-tests']) 793af6ab5fSopenharmony_ci if options.test262: 803af6ab5fSopenharmony_ci res = subprocess.call(general_cmd + ['--test262']) 813af6ab5fSopenharmony_ci if options.cts: 823af6ab5fSopenharmony_ci res = subprocess.call(general_cmd + ['--ets-cts']) 833af6ab5fSopenharmony_ci 843af6ab5fSopenharmony_ci 853af6ab5fSopenharmony_ciif __name__ == '__main__': 863af6ab5fSopenharmony_ci main() 87