1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4""" 5Copyright (c) 2021 Huawei Device Co., Ltd. 6Licensed under the Apache License, Version 2.0 (the "License"); 7you may not use this file except in compliance with the License. 8You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12Unless required by applicable law or agreed to in writing, software 13distributed under the License is distributed on an "AS IS" BASIS, 14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15See the License for the specific language governing permissions and 16limitations under the License. 17 18Description: Use ark to execute test 262 test suite 19""" 20 21import argparse 22import datetime 23import collections 24import json 25import os 26import shutil 27import sys 28import subprocess 29from multiprocessing import Pool 30import platform 31from typing import List 32 33from utils import * 34from config import * 35 36 37def parse_args(): 38 parser = argparse.ArgumentParser() 39 parser.add_argument('--dir', metavar='DIR', 40 help='Directory to test. And support multiple directories and files separated by ":"') 41 parser.add_argument('--file', metavar='FILE', 42 help='File to test') 43 parser.add_argument('--mode', 44 nargs='?', choices=[1, 2, 3], type=int, 45 help='selection information as: ' + 46 '1: only default \n ' + 47 '2: only strict mode \n' + 48 '3: both default and strict mode\n') 49 parser.add_argument('--es51', action='store_true', 50 help='Run test262 ES5.1 version') 51 parser.add_argument('--es2021', default=False, const='all', 52 nargs='?', choices=['all', 'only', 'other'], 53 help='Run test262 - ES2021. ' + 54 'all: Contains all use cases for es5_tests and es2015_tests and es2021_tests and intl_tests' + 55 'only: Only include use cases for ES2021' + 56 'other: Contains all use cases for es5_tests and es2015_tests and es2021_tests and intl_tests' + 57 'and other_tests') 58 parser.add_argument('--sendable', default=False, const='sendable', 59 nargs='?', choices=['sendable'], 60 help='Run test262 - sendable. ' + 61 'sendable: Contains all use cases for sendable') 62 parser.add_argument('--es2022', default=False, const='all', 63 nargs='?', choices=['all', 'only', 'other'], 64 help='Run test262 - ES2022. ' + 65 'all: Contains all use cases for es5_tests and es2015_tests and es2021_tests' + 66 'and es2022_tests and intl_tests' + 67 'only: Only include use cases for ES2022' + 68 'other: Contains all use cases for es5_tests and es2015_tests and es2021_tests' + 69 'and es2022_tests and intl_tests and other_tests') 70 parser.add_argument('--es2023', default=False, const='all', 71 nargs='?', choices=['all', 'only', 'other'], 72 help='Run test262 - ES2023. ' + 73 'all: Contains all use cases for es5_tests and es2015_tests and es2021_tests' + 74 'and es2022_tests and es2023_tests and intl_tests' + 75 'only: Only include use cases for ES2023' + 76 'other: Contains all use cases for es5_tests and es2015_tests and es2021_tests' + 77 'and es2022_tests and es2023_tests and intl_tests and other_tests') 78 parser.add_argument('--intl', default=False, const='intl', 79 nargs='?', choices=['intl'], 80 help='Run test262 - Intltest. ' + 81 'intl: Only include use cases for intlcsae') 82 parser.add_argument('--other', default=False, const='other', 83 nargs='?', choices=['other'], 84 help='Run test262 - other_tests ' + 85 'other_tests: Only include use cases for other_tests') 86 parser.add_argument('--es2015', default=False, const='es2015', 87 nargs='?', choices=['es2015'], 88 help='Run test262 - es2015. ' + 89 'es2015: Only include use cases for es2015') 90 parser.add_argument('--ci-build', action='store_true', 91 help='Run test262 ES2015 filter cases for build version') 92 parser.add_argument('--esnext', action='store_true', 93 help='Run test262 - ES.next.') 94 parser.add_argument('--test-list', metavar='FILE', dest="test_list", default=None, 95 help='File with list of tests to run') 96 parser.add_argument('--engine', metavar='FILE', 97 help='Other engine binarys to run tests(as:d8,qjs...)') 98 parser.add_argument('--babel', action='store_true', 99 help='Whether to use Babel conversion') 100 parser.add_argument('--skip-list', action='append', dest='skip_list', 101 help='Use explicitly specify skip list in txt format. Can be set several times') 102 parser.add_argument('--timeout', default=DEFAULT_TIMEOUT, type=int, 103 help='Set a custom test timeout in milliseconds !!!\n') 104 parser.add_argument('--threads', default=DEFAULT_THREADS, type=int, 105 help="Run this many tests in parallel.") 106 parser.add_argument('--hostArgs', 107 help="command-line arguments to pass to eshost host\n") 108 parser.add_argument('--ark-tool', 109 help="ark's binary tool") 110 parser.add_argument('--ark-aot', action='store_true', 111 help="Run test262 with aot") 112 parser.add_argument('--ark-aot-tool', 113 help="ark's aot tool") 114 parser.add_argument("--libs-dir", 115 help="The path collection of dependent so has been divided by':'") 116 parser.add_argument('--ark-frontend', 117 nargs='?', choices=ARK_FRONTEND_LIST, type=str, 118 help="Choose one of them") 119 parser.add_argument('--ark-frontend-binary', 120 help="ark frontend conversion binary tool") 121 parser.add_argument('--icu-data-path', 122 help="ark frontend conversion binary tool") 123 parser.add_argument('--ark-arch', 124 default=DEFAULT_ARK_ARCH, 125 nargs='?', choices=ARK_ARCH_LIST, type=str, 126 help="Choose one of them") 127 parser.add_argument('--ark-arch-root', 128 default=DEFAULT_ARK_ARCH, 129 help="the root path for qemu-aarch64 or qemu-arm") 130 parser.add_argument('--opt-level', 131 default=DEFAULT_OPT_LEVEL, 132 help="the opt level for es2abc") 133 parser.add_argument('--es2abc-thread-count', 134 default=DEFAULT_ES2ABC_THREAD_COUNT, 135 help="the thread count for es2abc") 136 parser.add_argument('--merge-abc-binary', 137 help="frontend merge abc binary tool") 138 parser.add_argument('--merge-abc-mode', 139 help="run test for merge abc mode") 140 parser.add_argument('--product-name', 141 default=DEFAULT_PRODUCT_NAME, 142 help="ark's product name") 143 parser.add_argument('--run-pgo', action='store_true', 144 help="Run test262 with aot pgo") 145 parser.add_argument('--enable-litecg', action='store_true', 146 help="Run test262 with aot litecg enabled") 147 parser.add_argument('--run-jit', action='store_true', 148 help="Run test262 with JIT") 149 parser.add_argument('--run-baseline-jit', action='store_true', 150 help="Run test262 with baseline JIT") 151 parser.add_argument('--enable-rm', action='store_true', 152 help="Enable force remove of the data directory") 153 parser.add_argument('--abc2program', action='store_true', 154 help="Use abc2prog to generate abc, aot or pgo is not supported yet under this option") 155 parser.add_argument('--stub-file', 156 default=DEFAULT_STUB_FILE, 157 help="stub file") 158 parser.add_argument('--disable-force-gc', action='store_true', 159 help="Run test262 with close force-gc") 160 parser.add_argument('--multi-context', action='store_true', 161 help="Run test262 with multi context") 162 parser.add_argument('--enable-arkguard', action='store_true', 163 help="enable arkguard for 262 tests") 164 165 args = parser.parse_args() 166 if args.abc2program and (args.run_pgo or args.ark_aot): 167 sys.exit("Error: '--abc2program' used together with '--ark-aot' or '--run-pgo' is not supported") 168 return args 169 170 171def run_check(runnable, env=None): 172 report_command('Test command:', runnable, env=env) 173 174 if env is not None: 175 full_env = dict(os.environ) 176 full_env.update(env) 177 env = full_env 178 179 proc = subprocess.Popen(runnable, env=env) 180 proc.wait() 181 return proc.returncode 182 183 184def excuting_npm_install(args): 185 ark_frontend = DEFAULT_ARK_FRONTEND 186 if args.ark_frontend: 187 ark_frontend = args.ark_frontend 188 189 if ark_frontend != ARK_FRONTEND_LIST[0]: 190 return 191 192 ark_frontend_binary = os.path.join(ARK_FRONTEND_BINARY_LIST[0]) 193 if args.ark_frontend_binary: 194 ark_frontend_binary = os.path.join(args.ark_frontend_binary) 195 196 ts2abc_build_dir = os.path.join(os.path.dirname( 197 os.path.realpath(ark_frontend_binary)), "..") 198 199 if not os.path.exists(os.path.join(ts2abc_build_dir, "package.json")) and \ 200 not os.path.exists(os.path.join(ts2abc_build_dir, "..", "package.json")): 201 return 202 203 if os.path.exists(os.path.join(ts2abc_build_dir, "..", "package.json")) and \ 204 not os.path.exists(os.path.join(ts2abc_build_dir, "package.json")): 205 ts2abc_build_dir = os.path.join(ts2abc_build_dir, "..") 206 # copy deps/ohos-typescript 207 deps_dir = os.path.join(ts2abc_build_dir, "deps") 208 mkdir(deps_dir) 209 210 shutil.copyfile(OHOS_TYPESCRIPT_TGZ_PATH, os.path.join(deps_dir, OHOS_TYPESCRIPT)) 211 212 npm_install(ts2abc_build_dir) 213 214 215def init(args): 216 remove_dir(BASE_OUT_DIR) 217 remove_dir(TEST_ES5_DIR) 218 remove_dir(TEST_ES2015_DIR) 219 remove_dir(TEST_INTL_DIR) 220 remove_dir(TEST_ES2021_DIR) 221 remove_dir(TEST_SENDABLE_DIR) 222 remove_dir(TEST_ES2022_DIR) 223 remove_dir(TEST_ES2023_DIR) 224 remove_dir(TEST_CI_DIR) 225 get_all_skip_tests(args) 226 excuting_npm_install(args) 227 228 229def get_all_skip_tests(args): 230 # !!! plz correct the condition when changing the default frontend 231 if args.ark_frontend and args.ark_frontend == ARK_FRONTEND_LIST[1]: 232 SKIP_LIST_FILES.append(ES2ABC_SKIP_LIST_FILE) 233 else: 234 SKIP_LIST_FILES.append(TS2ABC_SKIP_LIST_FILE) 235 236 if args.skip_list: 237 SKIP_LIST_FILES.append(os.path.join("test262", args.skip_list[0])) 238 239 for file in SKIP_LIST_FILES: 240 if file.endswith('.txt'): 241 with open(file, 'r') as txtfile: 242 for line in txtfile: 243 # skip "#" 244 line = line.strip() 245 if line and not line.startswith('#'): 246 new_line = "/".join(line.split("/")[3:]) 247 ALL_SKIP_TESTS.append(new_line) 248 else: 249 with open(file) as jsonfile: 250 json_data = json.load(jsonfile) 251 for key in json_data: 252 ALL_SKIP_TESTS.extend(key["files"]) 253 254 255def collect_files(path): 256 if os.path.isfile(path): 257 yield path 258 return 259 260 if not os.path.isdir(path): 261 raise ValueError(f'Not found: "{path}"') 262 263 for root, _, file_names in os.walk(path): 264 for file_name in file_names: 265 if file_name.startswith('.') or not file_name.endswith(".js"): 266 continue 267 268 yield os.path.join(root, file_name) 269 270 271def mkdstdir(file, src_dir, dist_dir): 272 idx = file.rfind(src_dir) 273 if idx == -1: 274 raise SystemExit(f'{file} can not found in {src_dir}') 275 276 fpath, fname = os.path.split(file[idx:]) 277 fpath = fpath.replace(src_dir, dist_dir) 278 mkdir(fpath) 279 280 281class TestPrepare(): 282 def __init__(self, args): 283 self.args = args 284 self.out_dir = BASE_OUT_DIR 285 286 @staticmethod 287 def get_tests_from_file(file): 288 with open(file) as fopen: 289 files = [line.strip() for line in fopen.readlines() if not line.startswith("#") and line.strip()] 290 return files 291 292 def prepare_test262_code(self): 293 if not os.path.isdir(os.path.join(DATA_DIR, '.git')): 294 if self.args.run_jit: 295 git_clone(TEST262_JIT_GIT_URL, DATA_DIR) 296 git_checkout(TEST262_JIT_GIT_HASH, DATA_DIR) 297 elif self.args.sendable == "sendable": 298 git_clone(SENDABLE_GIT_URL, DATA_DIR) 299 git_checkout(SENDABLE_GIT_HASH, DATA_DIR) 300 else: 301 git_clone(TEST262_GIT_URL, DATA_DIR) 302 git_checkout(TEST262_GIT_HASH, DATA_DIR) 303 304 if self.args.enable_rm and self.args.run_jit and not os.path.isfile(TEST262_JIT_LABEL): 305 remove_dir(DATA_DIR) 306 git_clone(TEST262_JIT_GIT_URL, DATA_DIR) 307 git_checkout(TEST262_JIT_GIT_HASH, DATA_DIR) 308 309 if not os.path.isdir(os.path.join(ESHOST_DIR, '.git')): 310 git_clone(ESHOST_GIT_URL, ESHOST_DIR) 311 git_checkout(ESHOST_GIT_HASH, ESHOST_DIR) 312 git_apply('../eshost.patch', ESHOST_DIR) 313 314 npm_install(ESHOST_DIR) 315 316 if not os.path.isdir(os.path.join(HARNESS_DIR, '.git')): 317 git_clone(HARNESS_GIT_URL, HARNESS_DIR) 318 git_checkout(HARNESS_GIT_HASH, HARNESS_DIR) 319 git_apply('../harness.patch', HARNESS_DIR) 320 321 npm_install(HARNESS_DIR) 322 323 def prepare_clean_data(self): 324 git_clean(DATA_DIR) 325 if self.args.run_jit: 326 git_checkout(TEST262_JIT_GIT_HASH, DATA_DIR) 327 elif self.args.sendable == "sendable": 328 git_checkout(SENDABLE_GIT_HASH, DATA_DIR) 329 else: 330 git_checkout(TEST262_GIT_HASH, DATA_DIR) 331 332 def patching_the_plugin(self): 333 remove_file(os.path.join(ESHOST_DIR, "lib/agents/panda.js")) 334 remove_file(os.path.join(ESHOST_DIR, "runtimes/panda.js")) 335 336 git_clean(ESHOST_DIR) 337 git_apply("../eshost.patch", ESHOST_DIR) 338 git_clean(HARNESS_DIR) 339 git_apply("../harness.patch", HARNESS_DIR) 340 341 def prepare_args_es51_es2021(self): 342 if self.args.dir: 343 if TEST_ES5_DIR in self.args.dir: 344 self.args.es51 = True 345 elif TEST_ES2015_DIR in self.args.dir: 346 self.args.es2015 = "es2015" 347 elif TEST_INTL_DIR in self.args.dir: 348 self.args.intl = "intl" 349 elif TEST_ES2021_DIR in self.args.dir: 350 self.args.es2021 = "all" 351 elif TEST_ES2022_DIR in self.args.dir: 352 self.args.es2022 = "all" 353 elif TEST_ES2023_DIR in self.args.dir: 354 self.args.es2023 = "all" 355 elif TEST_OTHERTESTS_DIR in self.args.dir: 356 self.args.other = "other" 357 358 if self.args.file: 359 if TEST_ES5_DIR in self.args.file: 360 self.args.es51 = True 361 elif TEST_ES2015_DIR in self.args.file: 362 self.args.es2015 = "es2015" 363 elif TEST_INTL_DIR in self.args.file: 364 self.args.intl = "intl" 365 elif TEST_ES2021_DIR in self.args.file: 366 self.args.es2021 = "all" 367 elif TEST_ES2022_DIR in self.args.file: 368 self.args.es2022 = "all" 369 elif TEST_ES2023_DIR in self.args.file: 370 self.args.es2023 = "all" 371 elif TEST_OTHERTESTS_DIR in self.args.file: 372 self.args.other = "other" 373 374 def prepare_out_dir(self): 375 if self.args.es51: 376 self.out_dir = os.path.join(BASE_OUT_DIR, "test_es51") 377 elif self.args.es2015: 378 self.out_dir = os.path.join(BASE_OUT_DIR, "test_es2015") 379 elif self.args.intl: 380 self.out_dir = os.path.join(BASE_OUT_DIR, "test_intl") 381 elif self.args.es2021: 382 self.out_dir = os.path.join(BASE_OUT_DIR, "test_es2021") 383 elif self.args.es2022: 384 self.out_dir = os.path.join(BASE_OUT_DIR, "test_es2022") 385 elif self.args.es2023: 386 self.out_dir = os.path.join(BASE_OUT_DIR, "test_es2023") 387 elif self.args.ci_build: 388 self.out_dir = os.path.join(BASE_OUT_DIR, "test_CI") 389 elif self.args.sendable: 390 self.out_dir = os.path.join(BASE_OUT_DIR, "test_sendable") 391 elif self.args.other: 392 self.out_dir = os.path.join(BASE_OUT_DIR, "other_tests") 393 else: 394 self.out_dir = os.path.join(BASE_OUT_DIR, "test") 395 396 def prepare_args_testdir(self): 397 if self.args.dir: 398 return 399 400 if self.args.es51: 401 self.args.dir = TEST_ES5_DIR 402 elif self.args.es2015: 403 self.args.dir = TEST_ES2015_DIR 404 elif self.args.intl: 405 self.args.dir = TEST_INTL_DIR 406 elif self.args.es2021: 407 self.args.dir = TEST_ES2021_DIR 408 elif self.args.sendable: 409 self.args.dir = TEST_SENDABLE_DIR 410 elif self.args.es2022: 411 self.args.dir = TEST_ES2022_DIR 412 elif self.args.es2023: 413 self.args.dir = TEST_ES2023_DIR 414 elif self.args.other: 415 self.args.dir = TEST_OTHERTESTS_DIR 416 elif self.args.ci_build: 417 self.args.dir = TEST_CI_DIR 418 else: 419 self.args.dir = os.path.join(DATA_DIR, "test") 420 421 def copyfile(self, file, all_skips): 422 dstdir = os.path.join(DATA_DIR, "test") 423 file = file.strip() 424 file = file.strip('\n') 425 file = file.replace("\\", "/") 426 if file in all_skips: 427 return 428 429 srcdir = os.path.join(DATA_DIR, "test", file) 430 if self.args.es51: 431 dstdir = os.path.join(TEST_ES5_DIR, file) 432 elif self.args.es2015: 433 dstdir = os.path.join(TEST_ES2015_DIR, file) 434 elif self.args.intl: 435 dstdir = os.path.join(TEST_INTL_DIR, file) 436 elif self.args.es2021: 437 dstdir = os.path.join(TEST_ES2021_DIR, file) 438 elif self.args.sendable: 439 dstdir = os.path.join(TEST_SENDABLE_DIR, file) 440 elif self.args.es2022: 441 dstdir = os.path.join(TEST_ES2022_DIR, file) 442 elif self.args.es2023: 443 dstdir = os.path.join(TEST_ES2023_DIR, file) 444 elif self.args.other: 445 dstdir = os.path.join(TEST_OTHERTESTS_DIR, file) 446 elif self.args.ci_build: 447 dstdir = os.path.join(TEST_CI_DIR, file) 448 449 if os.path.isfile(srcdir): 450 shutil.copyfile(srcdir, dstdir) 451 452 453 def collect_tests(self): 454 files = [] 455 origin_dir = os.path.join(DATA_DIR, "test/") 456 file_names = collect_files(origin_dir) 457 esid = "" 458 if self.args.es51: 459 esid = "es5id" 460 elif self.args.es2021 or self.args.es2022 or self.args.es2023: 461 esid = "es6id" 462 463 for file_name in file_names: 464 with open(file_name, 'r', encoding='utf-8') as file: 465 file_content = file.read() 466 if esid in file_content: 467 files.append(file_name.split(origin_dir)[1]) 468 return files 469 470 def prepare_es2021_tests(self): 471 files = [] 472 files = self.collect_tests() 473 files.extend(self.get_tests_from_file(ES2021_LIST_FILE)) 474 if self.args.es2021 == "all": 475 files.extend(self.get_tests_from_file(ES5_LIST_FILE)) 476 files.extend(self.get_tests_from_file(INTL_LIST_FILE)) 477 files.extend(self.get_tests_from_file(ES2015_LIST_FILE)) 478 if self.args.es2021 == "other": 479 files.extend(self.get_tests_from_file(ES5_LIST_FILE)) 480 files.extend(self.get_tests_from_file(INTL_LIST_FILE)) 481 files.extend(self.get_tests_from_file(ES2015_LIST_FILE)) 482 files.extend(self.get_tests_from_file(OTHER_LIST_FILE)) 483 return files 484 485 def prepare_sendable_tests(self): 486 files = [] 487 if self.args.sendable == "sendable": 488 files.extend(self.get_tests_from_file(SENDABLE_LIST_FILE)) 489 return files 490 491 def prepare_es2022_tests(self): 492 files = [] 493 files.extend(self.get_tests_from_file(ES2022_LIST_FILE)) 494 if self.args.es2022 == "all": 495 files.extend(self.get_tests_from_file(ES5_LIST_FILE)) 496 files.extend(self.get_tests_from_file(INTL_LIST_FILE)) 497 files.extend(self.get_tests_from_file(ES2015_LIST_FILE)) 498 files.extend(self.collect_tests()) 499 files.extend(self.get_tests_from_file(ES2021_LIST_FILE)) 500 if self.args.es2022 == "other": 501 files.extend(self.get_tests_from_file(ES5_LIST_FILE)) 502 files.extend(self.get_tests_from_file(INTL_LIST_FILE)) 503 files.extend(self.get_tests_from_file(ES2015_LIST_FILE)) 504 files.extend(self.collect_tests()) 505 files.extend(self.get_tests_from_file(ES2021_LIST_FILE)) 506 files.extend(self.get_tests_from_file(OTHER_LIST_FILE)) 507 return files 508 509 def prepare_es2023_tests(self): 510 files = [] 511 files.extend(self.get_tests_from_file(ES2023_LIST_FILE)) 512 if self.args.es2023 == "all": 513 files.extend(self.get_tests_from_file(ES5_LIST_FILE)) 514 files.extend(self.get_tests_from_file(INTL_LIST_FILE)) 515 files.extend(self.get_tests_from_file(ES2015_LIST_FILE)) 516 files.extend(self.collect_tests()) 517 files.extend(self.get_tests_from_file(ES2021_LIST_FILE)) 518 files.extend(self.get_tests_from_file(ES2022_LIST_FILE)) 519 if self.args.es2023 == "other": 520 files.extend(self.get_tests_from_file(ES5_LIST_FILE)) 521 files.extend(self.get_tests_from_file(INTL_LIST_FILE)) 522 files.extend(self.get_tests_from_file(ES2015_LIST_FILE)) 523 files.extend(self.collect_tests()) 524 files.extend(self.get_tests_from_file(ES2021_LIST_FILE)) 525 files.extend(self.get_tests_from_file(ES2022_LIST_FILE)) 526 files.extend(self.get_tests_from_file(OTHER_LIST_FILE)) 527 return files 528 529 def prepare_intl_tests(self): 530 files = [] 531 files = self.collect_tests() 532 if self.args.intl: 533 files = self.get_tests_from_file(INTL_LIST_FILE) 534 return files 535 536 def prepare_other_tests(self): 537 files = [] 538 files = self.collect_tests() 539 if self.args.other: 540 files = self.get_tests_from_file(OTHER_LIST_FILE) 541 return files 542 543 def prepare_es2015_tests(self): 544 files = [] 545 files = self.collect_tests() 546 if self.args.es2015: 547 files = self.get_tests_from_file(ES2015_LIST_FILE) 548 return files 549 550 def prepare_test_suit(self): 551 files = [] 552 test_dir = "" 553 if self.args.es51: 554 test_dir = TEST_ES5_DIR 555 files = self.get_tests_from_file(ES5_LIST_FILE) 556 elif self.args.es2015: 557 test_dir = TEST_ES2015_DIR 558 files = self.prepare_es2015_tests() 559 elif self.args.intl: 560 test_dir = TEST_INTL_DIR 561 files = self.prepare_intl_tests() 562 elif self.args.other: 563 test_dir = TEST_OTHERTESTS_DIR 564 files = self.prepare_other_tests() 565 elif self.args.es2021: 566 test_dir = TEST_ES2021_DIR 567 files = self.prepare_es2021_tests() 568 elif self.args.es2022: 569 test_dir = TEST_ES2022_DIR 570 files = self.prepare_es2022_tests() 571 elif self.args.es2023: 572 test_dir = TEST_ES2023_DIR 573 files = self.prepare_es2023_tests() 574 elif self.args.sendable: 575 test_dir = TEST_SENDABLE_DIR 576 files = self.prepare_sendable_tests() 577 elif self.args.ci_build: 578 test_dir = TEST_CI_DIR 579 files = self.get_tests_from_file(CI_LIST_FILE) 580 581 for file in files: 582 path = os.path.split(file)[0] 583 if not path.startswith(test_dir): 584 path = os.path.join(test_dir, path) 585 mkdir(path) 586 587 self.copyfile(file, ALL_SKIP_TESTS) 588 589 def prepare_test262_test(self): 590 src_dir = TEST_FULL_DIR 591 if self.args.es51: 592 self.prepare_test_suit() 593 src_dir = TEST_ES5_DIR 594 elif self.args.es2015: 595 self.prepare_test_suit() 596 src_dir = TEST_ES2015_DIR 597 elif self.args.intl: 598 self.prepare_test_suit() 599 src_dir = TEST_INTL_DIR 600 elif self.args.other: 601 self.prepare_test_suit() 602 src_dir = TEST_OTHERTESTS_DIR 603 elif self.args.es2021: 604 self.prepare_test_suit() 605 src_dir = TEST_ES2021_DIR 606 elif self.args.sendable: 607 self.prepare_test_suit() 608 src_dir = TEST_SENDABLE_DIR 609 elif self.args.es2022: 610 self.prepare_test_suit() 611 src_dir = TEST_ES2022_DIR 612 elif self.args.es2023: 613 self.prepare_test_suit() 614 src_dir = TEST_ES2023_DIR 615 elif self.args.ci_build: 616 self.prepare_test_suit() 617 src_dir = TEST_CI_DIR 618 elif self.args.esnext: 619 git_checkout(ESNEXT_GIT_HASH, DATA_DIR) 620 else: 621 if self.args.run_jit: 622 git_checkout(TEST262_JIT_GIT_HASH, DATA_DIR) 623 else: 624 git_checkout(TEST262_GIT_HASH, DATA_DIR) 625 626 if self.args.file: 627 mkdstdir(self.args.file, src_dir, self.out_dir) 628 return 629 630 files = [] 631 if ':' in self.args.dir: 632 path = self.args.dir.split(':') 633 for p in path: 634 files.extend(collect_files(p)) 635 else: 636 files = collect_files(self.args.dir) 637 for file in files: 638 mkdstdir(file, src_dir, self.out_dir) 639 640 def get_code(self): 641 self.prepare_test262_code() 642 self.prepare_clean_data() 643 self.patching_the_plugin() 644 645 def run(self): 646 self.prepare_args_es51_es2021() 647 self.prepare_out_dir() 648 self.prepare_args_testdir() 649 self.prepare_test262_test() 650 651 652def modetype_to_string(mode): 653 if mode == 1: 654 return "only default" 655 if mode == 2: 656 return "only strict mode" 657 return "both default and strict mode" 658 659 660def run_test262_mode(args): 661 if args.mode: 662 return modetype_to_string(args.mode) 663 return modetype_to_string(DEFAULT_MODE) 664 665 666def get_execute_arg(args) -> list[str]: 667 execute_args = [] 668 669 if args.file: 670 execute_args.append(args.file) 671 else: 672 path = args.dir.split(':') 673 for p in path: 674 if not p.endswith('.js'): 675 execute_args.append(os.path.join(p, "**", "*.js")) 676 else: 677 execute_args.append(p) 678 return execute_args 679 680 681def get_host_path_type(args): 682 host_path = DEFAULT_HOST_PATH 683 host_type = DEFAULT_HOST_TYPE 684 if args.engine: 685 host_path = args.engine 686 host_type = os.path.split(args.engine.strip())[1] 687 return host_path, host_type 688 689 690def get_timeout(args, threads): 691 timeout = DEFAULT_TIMEOUT * threads 692 if args.timeout: 693 timeout = args.timeout 694 return timeout 695 696 697def get_threads(args): 698 threads = DEFAULT_THREADS 699 if args.threads: 700 threads = args.threads 701 return threads 702 703 704def get_host_args_of_product_name(args): 705 product_name = args.product_name 706 ark_dir = f"{ARGS_PREFIX}{product_name}/{ARK_DIR_SUFFIX}" 707 icui_dir = f"{ARGS_PREFIX}{product_name}/{ICUI_DIR_SUFFIX}" 708 ark_js_runtime_dir = f"{ARGS_PREFIX}{product_name}/{ARK_JS_RUNTIME_DIR_SUFFIX}" 709 zlib_dir = f"{ARGS_PREFIX}{product_name}/{ZLIB_DIR_SUFFIX}" 710 711 ark_tool = os.path.join(ark_js_runtime_dir, "ark_js_vm") 712 libs_dir = f"{icui_dir}:{LLVM_DIR}:{ark_js_runtime_dir}:{zlib_dir}" 713 ark_aot_tool = os.path.join(ark_js_runtime_dir, "ark_aot_compiler") 714 merge_abc_binary = os.path.join(ark_dir, "merge_abc") 715 716 return ark_tool, libs_dir, ark_aot_tool, merge_abc_binary 717 718 719def get_host_args_of_host_type(args, host_args, ark_tool, ark_aot_tool, libs_dir, ark_frontend, 720 ark_frontend_binary, opt_level, es2abc_thread_count, 721 merge_abc_binary, merge_abc_mode, product_name, icu_data_path): 722 host_args = f"-B test262/run_sunspider.py " 723 host_args += f"--ark-tool={ark_tool} " 724 if args.ark_aot: 725 host_args += f"--ark-aot " 726 if args.run_pgo: 727 host_args += f"--run-pgo " 728 if args.enable_litecg: 729 host_args += f"--enable-litecg " 730 if args.run_jit: 731 host_args += f"--run-jit " 732 if args.run_baseline_jit: 733 host_args += f"--run-baseline-jit " 734 host_args += f"--ark-aot-tool={ark_aot_tool} " 735 host_args += f"--libs-dir={libs_dir} " 736 host_args += f"--ark-frontend={ark_frontend} " 737 host_args += f"--ark-frontend-binary={ark_frontend_binary} " 738 host_args += f"--opt-level={opt_level} " 739 host_args += f"--icu-data-path={icu_data_path} " 740 host_args += f"--es2abc-thread-count={es2abc_thread_count} " 741 host_args += f"--merge-abc-binary={merge_abc_binary} " 742 host_args += f"--merge-abc-mode={merge_abc_mode} " 743 host_args += f"--product-name={product_name} " 744 if args.abc2program: 745 host_args = f"{host_args}--abc2program " 746 if args.enable_arkguard: 747 host_args = f"{host_args}--enable-arkguard " 748 return host_args 749 750 751def get_host_args_of_ark_arch(args, host_args): 752 host_args += f"--ark-arch={args.ark_arch} " 753 host_args += f"--ark-arch-root={args.ark_arch_root} " 754 755 return host_args 756 757 758def get_disable_force_gc(host_args, args): 759 host_args += f"--disable-force-gc " 760 761 return host_args 762 763def get_multi_context(args, host_args): 764 host_args += f"--multi-context " 765 766 return host_args 767 768def get_host_args_of_stub_file(args, host_args): 769 host_args += f"--stub-file={args.stub_file} " 770 771 return host_args 772 773 774def get_host_args(args, host_type): 775 host_args = "" 776 ark_tool = DEFAULT_ARK_TOOL 777 ark_aot_tool = DEFAULT_ARK_AOT_TOOL 778 libs_dir = DEFAULT_LIBS_DIR 779 ark_frontend = DEFAULT_ARK_FRONTEND 780 ark_frontend_binary = DEFAULT_ARK_FRONTEND_BINARY 781 ark_arch = DEFAULT_ARK_ARCH 782 stub_file = DEFAULT_STUB_FILE 783 opt_level = DEFAULT_OPT_LEVEL 784 es2abc_thread_count = DEFAULT_ES2ABC_THREAD_COUNT 785 merge_abc_binary = DEFAULT_MERGE_ABC_BINARY 786 merge_abc_mode = DEFAULT_MERGE_ABC_MODE 787 product_name = DEFAULT_PRODUCT_NAME 788 icu_data_path = DEFAULT_ICU_PATH 789 790 if args.product_name: 791 ark_tool, libs_dir, ark_aot_tool, merge_abc_binary = get_host_args_of_product_name(args) 792 793 if args.hostArgs: 794 host_args = args.hostArgs 795 796 if args.ark_tool: 797 ark_tool = args.ark_tool 798 799 if args.ark_aot_tool: 800 ark_aot_tool = args.ark_aot_tool 801 802 if args.libs_dir: 803 libs_dir = args.libs_dir 804 805 if args.ark_frontend: 806 ark_frontend = args.ark_frontend 807 808 if args.ark_frontend_binary: 809 ark_frontend_binary = args.ark_frontend_binary 810 811 if args.opt_level: 812 opt_level = args.opt_level 813 814 if args.es2abc_thread_count: 815 es2abc_thread_count = args.es2abc_thread_count 816 817 if args.merge_abc_binary: 818 merge_abc_binary = args.merge_abc_binary 819 820 if args.icu_data_path: 821 icu_data_path = args.icu_data_path 822 if args.merge_abc_mode: 823 merge_abc_mode = args.merge_abc_mode 824 825 if host_type == DEFAULT_HOST_TYPE: 826 host_args = get_host_args_of_host_type(args, host_args, ark_tool, ark_aot_tool, libs_dir, ark_frontend, 827 ark_frontend_binary, opt_level, es2abc_thread_count, 828 merge_abc_binary, merge_abc_mode, product_name, icu_data_path) 829 830 if args.ark_arch != ark_arch: 831 host_args = get_host_args_of_ark_arch(args, host_args) 832 833 if args.stub_file != stub_file: 834 host_args = get_host_args_of_stub_file(args, host_args) 835 836 if args.disable_force_gc: 837 host_args = get_disable_force_gc(host_args, args) 838 839 if args.multi_context: 840 host_args = get_multi_context(args, host_args) 841 842 return host_args 843 844 845def run_test262_test(args): 846 execute_args = get_execute_arg(args) 847 host_path, host_type = get_host_path_type(args) 848 host_args = get_host_args(args, host_type) 849 threads = get_threads(args) 850 timeout = get_timeout(args, threads) 851 852 test_cmd = ["node", TEST262_RUNNER_SCRIPT] 853 test_cmd.append(f"--hostType={host_type}") 854 test_cmd.append(f"--hostPath={host_path}") 855 if host_args != "": 856 test_cmd.append(f"--hostArgs='{host_args}'") 857 test_cmd.append(f"--threads={threads}") 858 test_cmd.append(f"--mode={run_test262_mode(args)}") 859 test_cmd.append(f"--timeout={timeout}") 860 if platform.system() == "Windows" : 861 global BASE_OUT_DIR 862 global DATA_DIR 863 BASE_OUT_DIR = BASE_OUT_DIR.replace("/","\\") 864 DATA_DIR = DATA_DIR.replace("/","\\") 865 execute_args = [p.replace("/","\\") for p in execute_args] 866 test_cmd.append(f"--tempDir={BASE_OUT_DIR}") 867 test_cmd.append(f"--test262Dir={DATA_DIR}") 868 if args.test_list: 869 test_cmd.append("--isTestListSet") 870 if args.babel: 871 test_cmd.append("--preprocessor='test262/babel-preprocessor.js'") 872 test_cmd.append(DEFAULT_OTHER_ARGS) 873 test_cmd.extend(execute_args) 874 875 run_check(test_cmd) 876 877Check = collections.namedtuple('Check', ['enabled', 'runner', 'arg']) 878 879 880def prepare_test_list(args) -> List[str]: 881 if not os.path.exists(args.test_list): 882 args.test_list = os.path.join("test262", args.test_list) 883 test_list = TestPrepare.get_tests_from_file(args.test_list) 884 dirs: List[str] = [] 885 for test in test_list: 886 parts = test.split(os.path.sep)[:3] 887 dirs.append(os.path.sep.join(parts)) 888 return list(set(dirs)) 889 890 891def reset_args(args): 892 args.es51 = None 893 args.es2015 = None 894 args.intl = None 895 args.other = None 896 args.es2021 = None 897 args.es2022 = None 898 args.es2023 = None 899 args.ci_build = None 900 args.esnext = None 901 args.dir = None 902 903 904def prepare_file_from_test_list(args, test_prepare): 905 folders = prepare_test_list(args) 906 for folder in folders: 907 reset_args(args) 908 args.dir = folder 909 test_prepare.run() 910 args.file = args.test_list 911 912 913def run(args): 914 init(args) 915 916 test_prepare = TestPrepare(args) 917 test_prepare.get_code() 918 if args.test_list: 919 prepare_file_from_test_list(args, test_prepare) 920 else: 921 test_prepare.run() 922 check = Check(True, run_test262_test, args) 923 check.runner(check.arg) 924 925 926def main(args): 927 print("\nWait a moment..........\n") 928 starttime = datetime.datetime.now() 929 run(args) 930 endtime = datetime.datetime.now() 931 print(f"used time is: {str(endtime - starttime)}") 932 933 934if __name__ == "__main__": 935 # Script returns 0 if it's completed despite whether there are some failed tests or no 936 sys.exit(main(parse_args())) 937