1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# 4# Copyright (c) 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# 17 18import os 19import random 20from typing import List 21import logging 22 23import stress_common 24from stress_test262 import Test262StressTest 25from stress_common import SCRIPT_DIR, collect_from 26 27# CC-OFFNXT(WordsTool.66) false positive 28HERMES_REVISION = "3feac7b2f9759d83879b04232479041baa805e7b" 29HERMES_URL = "https://github.com/facebook/hermes.git" 30 31 32class HermesStressTest(Test262StressTest): 33 34 def __init__(self, args): 35 super().__init__(args) 36 self.js_dir = os.path.join(stress_common.TMP_DIR, 'abckit_hermes') 37 38 def get_fail_list_path(self) -> str: 39 return os.path.join(SCRIPT_DIR, 'fail_list_hermes.json') 40 41 def prepare(self) -> None: 42 self.download_hermes() 43 44 def download_hermes(self) -> None: 45 if not os.path.exists(self.js_dir): 46 stress_common.stress_exec( 47 ['git', 'clone', HERMES_URL, self.js_dir], repeats=5) 48 stress_common.stress_exec( 49 ['git', '-C', self.js_dir, 'checkout', HERMES_REVISION]) 50 51 def collect(self) -> List[str]: 52 logger = stress_common.create_logger() 53 tests: List[str] = [] 54 sp = os.path.join(self.js_dir, 'test') 55 tests.extend( 56 collect_from( 57 sp, lambda name: name.endswith('.js') and not name.startswith( 58 '.'))) 59 random.shuffle(tests) 60 61 logger.debug('Total tests: %s', len(tests)) 62 return tests 63