react-nitro-hermes 0.0.1-alpha.8 → 0.0.1-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/hermes/CMakeLists.txt +874 -0
  2. package/hermes/android/HostObjectJniTest.cpp +178 -0
  3. package/hermes/android/build-logic/build.gradle.kts +31 -0
  4. package/hermes/android/build-logic/settings.gradle.kts +17 -0
  5. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
  6. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
  7. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
  8. package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
  9. package/hermes/android/build.gradle.kts +332 -0
  10. package/hermes/android/cppruntime/build.gradle +72 -0
  11. package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
  12. package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
  13. package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
  14. package/hermes/android/cross-compile/swift-libicu.patch +13 -0
  15. package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
  16. package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
  17. package/hermes/android/gradle/libs.versions.toml +30 -0
  18. package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  19. package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  20. package/hermes/android/gradle.properties +3 -0
  21. package/hermes/android/gradlew +248 -0
  22. package/hermes/android/gradlew.bat +93 -0
  23. package/hermes/android/intltest/build.gradle +147 -0
  24. package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
  25. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
  26. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
  27. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
  28. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
  29. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
  30. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
  31. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
  32. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
  33. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
  34. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
  35. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
  36. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
  37. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
  38. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
  39. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
  40. package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
  41. package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
  42. package/hermes/android/settings.gradle.kts +27 -0
  43. package/hermes/cmake/modules/Hermes.cmake +481 -0
  44. package/hermes/cmake/modules/Lit.cmake +96 -0
  45. package/hermes/doc/Branches.md +38 -0
  46. package/hermes/doc/BuildingAndRunning.md +121 -0
  47. package/hermes/doc/CodingStandards.md +112 -0
  48. package/hermes/doc/CrossCompilation.md +79 -0
  49. package/hermes/doc/Design.md +217 -0
  50. package/hermes/doc/Emscripten.md +156 -0
  51. package/hermes/doc/Features.md +143 -0
  52. package/hermes/doc/GCSafeCoding.md +563 -0
  53. package/hermes/doc/GenGC.md +300 -0
  54. package/hermes/doc/Hades.md +344 -0
  55. package/hermes/doc/HighLevelOptimizations.md +37 -0
  56. package/hermes/doc/IR.md +1306 -0
  57. package/hermes/doc/IntlAPIs.md +196 -0
  58. package/hermes/doc/JIT.md +999 -0
  59. package/hermes/doc/LazyEvalCompilation.md +84 -0
  60. package/hermes/doc/MemoryProfilers.md +316 -0
  61. package/hermes/doc/Modules.md +144 -0
  62. package/hermes/doc/Optimizer.md +83 -0
  63. package/hermes/doc/PerfProfiling.md +29 -0
  64. package/hermes/doc/ProhibitInvoke.md +329 -0
  65. package/hermes/doc/ReactNative.md +40 -0
  66. package/hermes/doc/ReactNativeIntegration.md +94 -0
  67. package/hermes/doc/RegExp.md +24 -0
  68. package/hermes/doc/SpecIncompat.md +85 -0
  69. package/hermes/doc/Strings.md +140 -0
  70. package/hermes/doc/TypedLanguage.md +432 -0
  71. package/hermes/doc/VM.md +174 -0
  72. package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
  73. package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
  74. package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
  75. package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
  76. package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
  77. package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
  78. package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
  79. package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
  80. package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
  81. package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
  82. package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
  83. package/hermes/doc/blog/README.md +25 -0
  84. package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
  85. package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
  86. package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
  87. package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
  88. package/hermes/doc/icu_license.txt +420 -0
  89. package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
  90. package/hermes/doc/img/logo.svg +1 -0
  91. package/hermes/doc/img/object_captured_by_environment.png +0 -0
  92. package/hermes/doc/img/root_categories.png +0 -0
  93. package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
  94. package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
  95. package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
  96. package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
  97. package/hermes/doc/plans/ir-type/memory.md +48 -0
  98. package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
  99. package/hermes/doc/plans/ir-type/progress.md +239 -0
  100. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
  101. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
  102. package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
  103. package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
  104. package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
  105. package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
  106. package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
  107. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
  108. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
  109. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
  110. package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
  111. package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
  112. package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
  113. package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
  114. package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
  115. package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
  116. package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
  117. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
  118. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
  119. package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
  120. package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
  121. package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
  122. package/hermes/doc/typescript-stripping.md +90 -0
  123. package/hermes/external/CMakeLists.txt +20 -0
  124. package/hermes/utils/IntlGen/IntlGen.java +531 -0
  125. package/hermes/utils/bench_with_stats.py +827 -0
  126. package/hermes/utils/build-apple-framework.sh +323 -0
  127. package/hermes/utils/chrome_snapshot_parser.py +210 -0
  128. package/hermes/utils/cmake-dev-build.sh +18 -0
  129. package/hermes/utils/commons.sh +55 -0
  130. package/hermes/utils/dump-cpp-funcs.sh +3 -0
  131. package/hermes/utils/es5objects.js +198 -0
  132. package/hermes/utils/format.sh +145 -0
  133. package/hermes/utils/gen-promise-internal-bc.sh +66 -0
  134. package/hermes/utils/genUnicodeTable.py +2503 -0
  135. package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
  136. package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
  137. package/hermes/utils/jit/README.md +134 -0
  138. package/hermes/utils/jit/jit-diff.sh +160 -0
  139. package/hermes/utils/jit/jit-dump.sh +193 -0
  140. package/hermes/utils/lit-expect-gen/generate.py +217 -0
  141. package/hermes/utils/promise/index.js +15 -0
  142. package/hermes/utils/promise/package.json +13 -0
  143. package/hermes/utils/promise/rollup.config.js +19 -0
  144. package/hermes/utils/promise/yarn.lock +247 -0
  145. package/hermes/utils/scripts/hermes/consts.js +26 -0
  146. package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
  147. package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
  148. package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
  149. package/hermes/utils/scripts/hermes/package.json +6 -0
  150. package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
  151. package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
  152. package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
  153. package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
  154. package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
  155. package/hermes/utils/scripts/hermes/version-utils.js +98 -0
  156. package/hermes/utils/scripts/hermes/yarn.lock +240 -0
  157. package/hermes/utils/summarize_sizes.py +184 -0
  158. package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
  159. package/hermes/utils/test_runner.py +13 -0
  160. package/hermes/utils/testsuite/README.facebook +3 -0
  161. package/hermes/utils/testsuite/README.md +69 -0
  162. package/hermes/utils/testsuite/cli.py +547 -0
  163. package/hermes/utils/testsuite/es_ast.py +337 -0
  164. package/hermes/utils/testsuite/external/LICENSE +28 -0
  165. package/hermes/utils/testsuite/external/README.facebook +8 -0
  166. package/hermes/utils/testsuite/external/__init__.py +0 -0
  167. package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
  168. package/hermes/utils/testsuite/external/parse_test262.py +141 -0
  169. package/hermes/utils/testsuite/hermes.py +522 -0
  170. package/hermes/utils/testsuite/preprocess.py +365 -0
  171. package/hermes/utils/testsuite/progress.py +377 -0
  172. package/hermes/utils/testsuite/skiplist.json +4356 -0
  173. package/hermes/utils/testsuite/skiplist.py +270 -0
  174. package/hermes/utils/testsuite/test_run_defs.py +435 -0
  175. package/hermes/utils/testsuite/typing_defs.py +52 -0
  176. package/hermes/utils/testsuite/utils.py +214 -0
  177. package/hermes/utils/tidy.sh +22 -0
  178. package/hermes/utils/update-fbcode-hermes.sh +53 -0
  179. package/hermes/utils/updateErrorTest.py +193 -0
  180. package/hermes/utils/wasm-compile.sh +65 -0
  181. package/package.json +1 -1
@@ -0,0 +1,547 @@
1
+ #!/usr/bin/env python3
2
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ #
4
+ # This source code is licensed under the MIT license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ import argparse
8
+ import asyncio
9
+ import importlib.resources
10
+ import os
11
+ import shutil
12
+ import sys
13
+ import tempfile
14
+ import time
15
+ from asyncio import Semaphore
16
+ from collections import defaultdict
17
+ from typing import Awaitable, Dict, List, Optional
18
+
19
+ from . import utils
20
+ from .hermes import ExtraCompileVMArgs
21
+ from .progress import (
22
+ ProgressBar,
23
+ SimpleProgressBar,
24
+ TerminalController,
25
+ TestCaseResult,
26
+ TestingProgressDisplay,
27
+ )
28
+ from .skiplist import SkipCategory, SkippedPathsOrFeatures
29
+ from .test_run_defs import get_suite, StrictMode, TestRunArgs
30
+ from .typing_defs import PathT
31
+ from .utils import Color, TestResultCode
32
+
33
+ N_DEFAULT_CPU = 10
34
+ DEFAULT_TIMEOUT = 200
35
+ try:
36
+ RESOURCE_ROOT = importlib.resources.files(__package__)
37
+ except TypeError:
38
+ from pathlib import Path
39
+
40
+ # With Python 3.9.6 on MacOS, importlib.resources.files raises a TypeError,
41
+ # simply set it to the directory of current file as a fallback (it's unclear
42
+ # whether this will always work).
43
+ RESOURCE_ROOT = Path(os.path.dirname(__file__))
44
+
45
+
46
+ def strip_nargs(value: str):
47
+ """
48
+ Strip the leading/trailing whitespaces in values passed to nargs.
49
+
50
+ Adding leading/trailing whitespaces is a common workaround to pass argument
51
+ values with '-' in it (otherwise, argparse will treat it as another flag).
52
+ """
53
+ return value.strip()
54
+
55
+
56
+ def create_parser():
57
+ # Common argument for running all testsuite
58
+ desp = """
59
+ Run Hermes testsuite. Supported testsuites are:
60
+ - test262
61
+ - mjsunit
62
+ - esprima
63
+ - CVEs
64
+ - flow
65
+ """
66
+ parser = argparse.ArgumentParser(description=desp)
67
+ parser.add_argument(
68
+ "-b",
69
+ "--binary-dir",
70
+ dest="binary_directory",
71
+ default=RESOURCE_ROOT,
72
+ help="Path to hermes built binary directory, default to the package root",
73
+ )
74
+ parser.add_argument(
75
+ "--bytecode-compat-check",
76
+ dest="bytecode_compat_check",
77
+ default=False,
78
+ action="store_true",
79
+ help="""When this flag is provided, specified binary directory expects
80
+ an additional b_hermes binary. The hermes binary will be used to compile
81
+ the test file to bytecode, while b_hermes is used to run the bytecode.
82
+ This has no effect in shermes mode and lazy mode.""",
83
+ )
84
+ parser.add_argument(
85
+ "-j",
86
+ "--jobs",
87
+ dest="n_jobs",
88
+ default=os.cpu_count() or N_DEFAULT_CPU,
89
+ type=int,
90
+ help="Number of tests to run simultaneously, default is number of logical CPUs",
91
+ )
92
+ parser.add_argument(
93
+ "--test-skiplist",
94
+ dest="test_skiplist",
95
+ action="store_true",
96
+ help="Run tests in the skiplist and remove them from the list if passed",
97
+ )
98
+ parser.add_argument(
99
+ "--test-intl",
100
+ dest="test_intl",
101
+ action="store_true",
102
+ help="Run supported Intl tests",
103
+ )
104
+ parser.add_argument(
105
+ "-v",
106
+ "--verbose",
107
+ dest="verbose",
108
+ default=False,
109
+ action="store_true",
110
+ help="Show intermediate output",
111
+ )
112
+ parser.add_argument(
113
+ "--work-dir",
114
+ dest="work_dir",
115
+ default=None,
116
+ type=str,
117
+ help="Specifies work directory where the test files will be generated. "
118
+ "The work directory will be deleted if it is not empty",
119
+ )
120
+ group = parser.add_mutually_exclusive_group()
121
+ group.add_argument(
122
+ "--lazy", dest="lazy", action="store_true", help="Force lazy evaluation"
123
+ )
124
+ group.add_argument(
125
+ "--shermes", dest="shermes", action="store_true", help="Test with shermes"
126
+ )
127
+ parser.add_argument(
128
+ "--opt", dest="opt", action="store_true", help="Enable compiler optimizations"
129
+ )
130
+ parser.add_argument(
131
+ "--compile-args",
132
+ dest="extra_compile_args",
133
+ nargs="+",
134
+ default=[],
135
+ type=strip_nargs,
136
+ help="Extra compiler arguments, separated by whitespace",
137
+ )
138
+ parser.add_argument(
139
+ "--vm-args",
140
+ dest="extra_vm_args",
141
+ nargs="+",
142
+ default=[],
143
+ type=strip_nargs,
144
+ help="Extra VM arguments, separated by whitespace",
145
+ )
146
+ parser.add_argument(
147
+ "-d",
148
+ "--dump-source",
149
+ dest="dump_source",
150
+ action="store_true",
151
+ help="Instead of running any tests, print the preprocessed source of "
152
+ "test case to standard output, including any generated use-strict "
153
+ "directives or stubbed pragmas. When this flag is provided, only one "
154
+ "path is expected.",
155
+ )
156
+ parser.add_argument(
157
+ "--timeout",
158
+ dest="timeout",
159
+ default=DEFAULT_TIMEOUT,
160
+ type=int,
161
+ help="Timeout for compiling and running each test.",
162
+ )
163
+ parser.add_argument(
164
+ "--show-slowest-tests",
165
+ dest="show_slowest_tests",
166
+ default=0,
167
+ type=int,
168
+ help="Print the N slowest tests at the end of the run. 0 disables (default).",
169
+ )
170
+ parser.add_argument(
171
+ "paths", type=str, nargs="+", help="Paths to testsuite, can be dir or file"
172
+ )
173
+
174
+ return parser
175
+
176
+
177
+ def validate_args(args: argparse.Namespace):
178
+ """
179
+ Validate provided arguments. For -b flag, check whether necessary Hermes
180
+ executables do exist.
181
+ """
182
+
183
+ if args.dump_source:
184
+ if len(args.paths) != 1:
185
+ print("Argument error: Only one path is expected with --dump-source.")
186
+ sys.exit(1)
187
+
188
+ utils.check_hermes_exe(
189
+ args.binary_directory, args.shermes, args.bytecode_compat_check
190
+ )
191
+
192
+
193
+ def print_stats(stats: dict) -> None:
194
+ """Print the result stats."""
195
+ total = sum(stats.values())
196
+ failed = (
197
+ stats[TestResultCode.COMPILE_FAILED]
198
+ + stats[TestResultCode.COMPILE_TIMEOUT]
199
+ + stats[TestResultCode.EXECUTE_FAILED]
200
+ + stats[TestResultCode.EXECUTE_TIMEOUT]
201
+ + stats[TestResultCode.TEST_FAILED]
202
+ )
203
+ executed = (
204
+ sum(stats.values())
205
+ - stats[TestResultCode.TEST_SKIPPED]
206
+ - stats[TestResultCode.TEST_PERMANENTLY_SKIPPED]
207
+ )
208
+
209
+ if executed > 0:
210
+ passRate = "{0:.2%}".format(stats[TestResultCode.TEST_PASSED] / executed)
211
+ else:
212
+ passRate = "--"
213
+
214
+ if (executed - stats[TestResultCode.TEST_PASSED]) > 0:
215
+ resultStr = "{}FAIL{}".format(Color.RED, Color.RESET)
216
+ else:
217
+ resultStr = "{}PASS{}".format(Color.GREEN, Color.RESET)
218
+
219
+ # Turn off formatting so that the table looks nice in source code.
220
+ # fmt: off
221
+ print("-----------------------------------")
222
+ print("| Results | {} |".format(resultStr))
223
+ print("|----------------------+----------|")
224
+ print("| Total | {:>8} |".format(total))
225
+ print("| Passes | {:>8} |".format(stats[TestResultCode.TEST_PASSED]))
226
+ print("| Failures | {:>8} |".format(failed))
227
+ print("| Skipped | {:>8} |".format(stats[TestResultCode.TEST_SKIPPED]))
228
+ print("| Permanently Skipped | {:>8} |".format(stats[TestResultCode.TEST_PERMANENTLY_SKIPPED]))
229
+ print("| Pass Rate | {:>8} |".format(passRate))
230
+ print("-----------------------------------")
231
+ print("| Failures | |")
232
+ print("|----------------------+----------|")
233
+ print("| Compile fail | {:>8} |".format(stats[TestResultCode.COMPILE_FAILED]))
234
+ print("| Compile timeout | {:>8} |".format(stats[TestResultCode.COMPILE_TIMEOUT]))
235
+ print("| Execute fail | {:>8} |".format(stats[TestResultCode.EXECUTE_FAILED]))
236
+ print("| Execute timeout | {:>8} |".format(stats[TestResultCode.EXECUTE_TIMEOUT]))
237
+ print("| Other | {:>8} |".format(stats[TestResultCode.TEST_FAILED]))
238
+ print("-----------------------------------")
239
+ # fmt: on
240
+
241
+
242
+ def print_failed_tests(tests: dict) -> None:
243
+ def print_test_list(cat: TestResultCode, header: str):
244
+ if len(tests[cat]) > 0:
245
+ print("-----------------------------------")
246
+ print(header)
247
+ for test in tests[cat]:
248
+ print(test)
249
+ print("-----------------------------------")
250
+
251
+ if len(tests) == 0:
252
+ return
253
+ print("\nDetails:")
254
+ print_test_list(TestResultCode.COMPILE_FAILED, "Compile failed:")
255
+ print_test_list(TestResultCode.COMPILE_TIMEOUT, "Compile timeout:")
256
+ print_test_list(TestResultCode.EXECUTE_FAILED, "Execute failed:")
257
+ print_test_list(TestResultCode.EXECUTE_TIMEOUT, "Execute timeout:")
258
+ print_test_list(TestResultCode.TEST_FAILED, "Other test failure:")
259
+
260
+
261
+ def print_slowest_tests(results: List[TestCaseResult], n: int = 30) -> None:
262
+ """Print the top N slowest tests by subprocess wall-clock time."""
263
+ if not results:
264
+ return
265
+ slowest = sorted(results, key=lambda r: r.duration, reverse=True)[:n]
266
+ if slowest[0].duration == 0.0:
267
+ return
268
+ print(f"\nSlowest {min(n, len(slowest))} tests:")
269
+ print("-----------------------------------")
270
+ for r in slowest:
271
+ print(f"{r.duration:>7.2f}s {r.test_name}")
272
+ print("-----------------------------------")
273
+
274
+
275
+ def print_skipped_passed_tests(tests: Dict[str, str]) -> None:
276
+ print("\nPassed tests in skiplist:")
277
+ print("-----------------------------------")
278
+ for test_name in tests:
279
+ print(test_name)
280
+ print("-----------------------------------")
281
+
282
+
283
+ def remove_tests_from_skiplist(
284
+ tests: Dict[str, str], skipped_paths_features: SkippedPathsOrFeatures
285
+ ) -> None:
286
+ """Remove passed tests from the skiplist config."""
287
+
288
+ ans = input("\nRemove these passed tests from skiplist? [y]es/[n]o: ").lower()
289
+ if ans == "y" or ans == "yes":
290
+ # Original full test names have form of "<suite> :: relative/path",
291
+ # we need to convert them to form of "<suite>/relative/path" to match
292
+ # paths in skiplist.
293
+ tests_with_rel_paths = {
294
+ test_name.replace(" :: ", os.sep): suite_dir
295
+ for test_name, suite_dir in tests.items()
296
+ }
297
+
298
+ skipped_paths_features.remove_tests(tests_with_rel_paths)
299
+ skipped_paths_features.persist()
300
+
301
+
302
+ async def run(
303
+ tests_paths: List[PathT],
304
+ binary_directory: PathT,
305
+ skipped_paths_features: SkippedPathsOrFeatures,
306
+ work_dir: PathT,
307
+ n_jobs: int,
308
+ test_skiplist: bool,
309
+ test_intl: bool,
310
+ bytecode_compat_check: bool,
311
+ lazy: bool,
312
+ shermes: bool,
313
+ opt: bool,
314
+ extra_compile_vm_args: ExtraCompileVMArgs,
315
+ timeout: int,
316
+ verbose: bool,
317
+ show_slowest_tests: int = 0,
318
+ ) -> int:
319
+ """
320
+ Run all tests with async subprocess and wait for results in completion order
321
+ of test jobs. Each subprocess invokes hermes binary on a given test file, so
322
+ to restrict resource contention, we use asyncio.Semaphore to control the
323
+ maximum number of alive tasks (configured by n_jobs).
324
+
325
+ We first collect all tasks for given tests_paths, then wrap each of them
326
+ in a new task guarded by Semaphore, and pass them to asyncio.as_completed().
327
+ Each task can be awaited in it to get earliest next result. And once a
328
+ task is done, its Semaphore counter is released and a new task can
329
+ continue to run.
330
+
331
+ After all tasks are done, print the test stats and relative paths of all
332
+ failing tests (if there are).
333
+ """
334
+
335
+ # Get the common path of all file/directory paths to be used when creating
336
+ # temporary files.
337
+ tests_home = os.path.commonpath(tests_paths)
338
+ tests_files = utils.list_all_files(tests_paths)
339
+
340
+ header = f"-- Testing: {len(tests_files)} tests, max {n_jobs} concurrent tasks --"
341
+ try:
342
+ term = TerminalController()
343
+ pb = ProgressBar(term, header)
344
+ except ValueError:
345
+ print(header)
346
+ pb = SimpleProgressBar("Testing: ")
347
+ pd = TestingProgressDisplay(len(tests_files), pb, verbose)
348
+ current_n_tasks = Semaphore(n_jobs)
349
+
350
+ start_time = time.time()
351
+ tasks = []
352
+ stats = defaultdict(int)
353
+ # Record skipped tests and its suite path (as dict value).
354
+ # we need the suite path because some paths in the skiplist config are
355
+ # directories, we need to get their absolute paths to get all files under
356
+ # them.
357
+ skipped_tests = {}
358
+ for test_file in tests_files:
359
+ suite = get_suite(test_file)
360
+ assert suite, f"Test suite root directory is not found for {test_file}"
361
+ full_test_name = suite.get_full_test_name(test_file)
362
+
363
+ # Check if this file should be skipped w.r.t. the test_skiplist flag.
364
+ skip_categories = [
365
+ SkipCategory.SKIP_LIST,
366
+ SkipCategory.PERMANENT_SKIP_LIST,
367
+ SkipCategory.MANUAL_SKIP_LIST,
368
+ SkipCategory.PLATFORM_SKIP_LIST,
369
+ ]
370
+ if lazy:
371
+ skip_categories.append(SkipCategory.LAZY_SKIP_LIST)
372
+ if test_result := skipped_paths_features.try_skip(
373
+ test_file,
374
+ skip_categories,
375
+ full_test_name,
376
+ ):
377
+ if not test_skiplist:
378
+ pd.update(test_result)
379
+ stats[test_result.code] += 1
380
+ continue
381
+ else:
382
+ skipped_tests[full_test_name] = suite.directory
383
+ # We check for intl tests separately since we don't run them frequently.
384
+ if test_result := skipped_paths_features.try_skip(
385
+ test_file, [SkipCategory.INTL_TESTS], full_test_name
386
+ ):
387
+ if not test_intl:
388
+ pd.update(test_result)
389
+ stats[test_result.code] += 1
390
+ continue
391
+ else:
392
+ skipped_tests[full_test_name] = suite.directory
393
+
394
+ test_run_args = TestRunArgs(
395
+ test_file,
396
+ tests_home,
397
+ work_dir,
398
+ binary_directory,
399
+ skipped_paths_features,
400
+ test_skiplist,
401
+ bytecode_compat_check,
402
+ lazy,
403
+ shermes,
404
+ opt,
405
+ extra_compile_vm_args,
406
+ timeout,
407
+ )
408
+ tasks.append(suite.run_test(test_run_args))
409
+
410
+ # Control maximum running tasks.
411
+ async def wrap_task(fut: Awaitable) -> TestCaseResult:
412
+ # Acquire the Semaphore and decrement it by one. If the counter is
413
+ # already zero, wait until one running task is done, which will release
414
+ # the Semaphore and increment the counter.
415
+ async with current_n_tasks:
416
+ return await fut
417
+
418
+ failed_cases = defaultdict(list)
419
+ # Similar to skipped_tests, but only store those passed.
420
+ skipped_passed = {}
421
+ all_results: List[TestCaseResult] = []
422
+ for task in asyncio.as_completed([wrap_task(fut) for fut in tasks]):
423
+ result = await task
424
+ stats[result.code] += 1
425
+ pd.update(result)
426
+ if result.code.is_failure:
427
+ failed_cases[result.code].append(result.test_name)
428
+ # Collect non-skipped results for slowest-tests report.
429
+ if result.code not in (
430
+ TestResultCode.TEST_SKIPPED,
431
+ TestResultCode.TEST_PERMANENTLY_SKIPPED,
432
+ ):
433
+ all_results.append(result)
434
+ # Some tests might be skipped due to unsupported features, we should consider
435
+ # them as "passed" as well since they will be skipped anyway.
436
+ if (
437
+ result.code == TestResultCode.TEST_PASSED
438
+ or result.code == TestResultCode.TEST_SKIPPED
439
+ ):
440
+ if test_suite_dir := skipped_tests.get(result.test_name):
441
+ skipped_passed[result.test_name] = test_suite_dir
442
+
443
+ pd.finish()
444
+ elapsed = time.time() - start_time
445
+ print(f"Testing time: {elapsed:.2f}")
446
+
447
+ # Print result
448
+ print_stats(stats)
449
+ if show_slowest_tests > 0:
450
+ print_slowest_tests(all_results, min(show_slowest_tests, len(all_results)))
451
+ print_failed_tests(failed_cases)
452
+ # The "intl_tests" list is simply a folder and we don't want to unfold
453
+ # it. All intl tests that we can't pass are included in "skip_list". So
454
+ # we will only remove them if both "--test-skiplist" and "--test-intl"
455
+ # are provided.
456
+ if len(skipped_passed) > 0 and test_skiplist:
457
+ print_skipped_passed_tests(skipped_passed)
458
+ remove_tests_from_skiplist(skipped_passed, skipped_paths_features)
459
+
460
+ return 1 if len(failed_cases) > 0 else 0
461
+
462
+
463
+ def print_preprocessed_source(path: PathT) -> None:
464
+ """
465
+ Print the preprocessed source to STDOUT. For test262/mjsunit, it may include
466
+ harness code and macros are replaced by actual code. For CVEs/flow/esprima,
467
+ the exact source code is returned.
468
+ """
469
+
470
+ from .preprocess import generate_source
471
+
472
+ suite = get_suite(path)
473
+ if not suite:
474
+ print("Not a test from valid test suite.")
475
+ return
476
+ with open(path, "rb") as f:
477
+ source = f.read().decode("utf-8")
478
+ test_case = generate_source(source, suite.directory, suite.get_full_test_name(path))
479
+ # This is specifically for test262, and we only insert the directive if
480
+ # it's in strict only mode (when testing we would have to test both strict
481
+ # and non-strict mode if none of them is specified).
482
+ if StrictMode.STRICT in test_case.strict_mode:
483
+ print("'use strict';")
484
+ print(test_case.source)
485
+
486
+
487
+ async def main() -> int:
488
+ parser = create_parser()
489
+ args = parser.parse_args()
490
+ validate_args(args)
491
+
492
+ # If user wants to dump the preprocessed source for debugging, handle it
493
+ # separately for readability.
494
+ if args.dump_source:
495
+ print_preprocessed_source(args.paths[0])
496
+ return 0
497
+
498
+ work_dir: Optional[str] = args.work_dir
499
+ # Hold the reference to the temporary directory (if we do create one), so
500
+ # it won't be deleted until we run all tests.
501
+ tmp_work_dir = None
502
+ if work_dir is None:
503
+ tmp_work_dir = tempfile.TemporaryDirectory(suffix="hermes_workdir")
504
+ work_dir = tmp_work_dir.name
505
+ else:
506
+ # Remove the directory if it exists.
507
+ if os.path.exists(work_dir):
508
+ shutil.rmtree(work_dir)
509
+ os.makedirs(work_dir, exist_ok=False)
510
+
511
+ with importlib.resources.as_file(
512
+ RESOURCE_ROOT / "skiplist.json"
513
+ ) as skip_list_cfg_path:
514
+ skipped_paths_features = SkippedPathsOrFeatures(os.fspath(skip_list_cfg_path))
515
+
516
+ # Consumes all extra flags.
517
+ extra_compile_vm_args = ExtraCompileVMArgs(
518
+ compile_args=args.extra_compile_args, vm_args=args.extra_vm_args
519
+ )
520
+
521
+ exit_code = await run(
522
+ args.paths,
523
+ args.binary_directory,
524
+ skipped_paths_features,
525
+ work_dir,
526
+ args.n_jobs,
527
+ args.test_skiplist,
528
+ args.test_intl,
529
+ args.bytecode_compat_check,
530
+ args.lazy,
531
+ args.shermes,
532
+ args.opt,
533
+ extra_compile_vm_args,
534
+ args.timeout,
535
+ args.verbose,
536
+ args.show_slowest_tests,
537
+ )
538
+
539
+ # Explicitly clean up the temporary directory if we created one.
540
+ if tmp_work_dir:
541
+ tmp_work_dir.cleanup()
542
+
543
+ return exit_code
544
+
545
+
546
+ if __name__ == "__main__":
547
+ sys.exit(asyncio.run(main()))