1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4""" 5Copyright (c) 2023 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""" 18 19import os 20 21CUR_FILE_DIR = os.path.dirname(__file__) 22DEFAULT_ES2ABC_TOOL = os.path.join(CUR_FILE_DIR, 'es2abc') 23REPORT_DIR = os.path.join(CUR_FILE_DIR, 'output') 24DEFAULT_TESTCASES_DIR = 'test_cases' 25DEFAULT_OUTPUT_DIR = os.path.join(CUR_FILE_DIR, 'es2abc_output') 26HERMES_CODE_PATH = os.path.join(CUR_FILE_DIR, 'hermes_workingdir') 27DEFAULT_HERMES_PATH = os.path.join(HERMES_CODE_PATH, 'build', "bin", 'hermes') 28HERMES_BUILD_PATH = os.path.join(HERMES_CODE_PATH, "build") 29HERMES_BUILD_LOG_PATH = os.path.join(HERMES_CODE_PATH, "build.log") 30HERMES_CLONE_PATH = os.path.join(HERMES_CODE_PATH, "hermes") 31BUILD_HERMES_CMDS = cmds = [['cmake', '-S', HERMES_CLONE_PATH, '-B', HERMES_BUILD_PATH, '-G', 'Ninja', 32 "-DCMAKE_BUILD_TYPE=Release"], 33 ['cmake', '--build', HERMES_BUILD_PATH]] 34DEFAULT_RUNS = 20 35DEFAULT_PARAMS = ["--module", "--merge-abc"] 36DEFAULT_HERMES_PARAMS = ["-emit-binary", "-out"] 37JS_FILE_SUFFIX = ".js" 38TS_FILE_SUFFIX = ".Ts" 39HERMES_FILE_SUFFIX = ".hbc" 40CASE_DATA_SUFFIX = "-data.js" 41OCTANE = "Octane" 42KRAKEN = "Kraken" 43SUNSPIDER = "Sunspider" 44KRAKENBENCHMARK_CASE_PATH = "tests" 45KRAKEN_CASE_PATH = 'kraken-1.1' 46SUNSPIDER_CASE_PATH = 'sunspider-0.9.1' 47ABC_FILE_SUFFIX = ".abc" 48TEST_RESULT_FILE = "test_result.html" 49LOG_FILE = "test_result.txt" 50PARSE_ONLY = "parse-only(Only do parsing actions)" 51OPT_LEVEL = "opt-level(level of compilation optimization)" 52COMP = "engine-comp(Compared with the Hermes engine)" 53RUNS_NUM = "runs(Number of runs)" 54SELECTED_PARAMETERS = "Runtime parameters" 55SELECTED_PARAMETERS_BASE = "Selected parameters:" 56DEFAULT_TIME = "Time" 57AVERAGE_TIME = "Average time of one round" 58GIT_DIR = ".git" 59CLONE_DIR_SUFFIX = "_base" 60ES2ABC = "es2abc" 61HERMES = "hermes" 62HERMES_GIT_URL = 'https://github.com/facebook/hermes.git' 63CASE_URLS = [{"name": "Octane", "url": "https://github.com/chromium/octane.git", "dir": "."}, 64 {"name": "Kraken", "url": "https://github.com/mozilla/krakenbenchmark.mozilla.org.git", "dir": "test"}, 65 {"name": "Sunspider", "url": "https://github.com/mozilla/krakenbenchmark.mozilla.org.git", "dir": "test"}] 66 67CASE_LIST = { 68 "Octane": ['box2d.js', 'code-load.js', 'crypto.js', 'deltablue.js', 'gbemu.js', 'navier-stokes.js', 69 'pdfjs.js', 'raytrace.js', 'regexp.js', 'richards.js', 'splay.js', 'typescript.js'], 70 "Kraken": ['ai-astar.js', 'audio-beat-detection.js', 'audio-dft.js', 'audio-fft.js', 'audio-oscillator.js', 71 'json-parse-financial.js', 'json-stringify-tinderbox.js', 'stanford-crypto-aes.js', 72 'stanford-crypto-ccm.js', 73 'stanford-crypto-pbkdf2.js', 'stanford-crypto-sha256-iterative.js'], 74 "Sunspider": ['3d-cube.js', '3d-morph.js', '3d-raytrace.js', 'access-binary-trees.js', 'access-fannkuch.js', 75 'access-nbody.js', 'access-nsieve.js', 'bitops-3bit-bits-in-byte.js', 'bitops-bits-in-byte.js', 76 'bitops-bitwise-and.js', 'bitops-nsieve-bits.js', 'controlflow-recursive.js', 'crypto-aes.js', 77 'crypto-md5.js', 'crypto-sha1.js', 'date-format-tofte.js', 'date-format-xparb.js', 'math-cordic.js', 78 'math-partial-sums.js', 'math-spectral-norm.js', 'regexp-dna.js', 'string-base64.js', 79 'string-fasta.js', 'string-tagcloud.js', 'string-unpack-code.js', 'string-validate-input.js']} 80 81HTML_TEMPLATE = """ 82 <html> 83 <head> 84 <title>es2abc Benchmark Test Report</title> 85 </head> 86 <style> 87 body { 88 font-family: Arial, sans-serif; 89 margin: 0; 90 padding: 20px; 91 } 92 h1, h2 { 93 color: #333; 94 } 95 h1 { 96 text-align: center; 97 } 98 table { 99 border-collapse: collapse; 100 width: 100%; 101 } 102 th, td { 103 border: 1px solid #ccc; 104 padding: 8px; 105 text-align: left; 106 } 107 th { 108 background-color: #f2f2f2; 109 } 110 #title { 111 font-style: initial; 112 font-size: 14px; 113 color: #333; 114 } 115 </style> 116 <body> 117 <HTML_TABLE> 118 <h1>es2abc-benchmark</h1> 119 <div id='title'> Selected parameters: </div> 120 """ 121 122HTML_TABLE_DEFAULT = """ 123 <table border="1"> 124 <tr> 125 <th>Case</th> 126 <th>Number of runs</th> 127 <th>Time</th> 128 <th>Score</th> 129 </tr> 130 """ 131 132HTML_TABLE_COMP = """ 133 <table border="1"> 134 <tr> 135 <th rowspan="2">Case</td> 136 <th rowspan="2">Number of runs</th> 137 <th colspan="2">es2abc</th> 138 <th colspan="2">hermes</th> 139 </tr> 140 <tr> 141 <th>Time</th> 142 <th>Score</th> 143 <th>Time</th> 144 <th>Score</th> 145 </tr> 146 """ 147 148HTML_SCRIPT = """ 149 </table><script>function redirect(id){window.location.href = window.location.href.replace('test_result', id)}; 150 </script></body></html> 151 """ 152