[Wasm] Run wasm test using all available VMs: V8 & SpiderMonkey for now
Also, add a new directive, `WASM_FAILS_IN`, to specify VMs where a test is expected to fail for now. #KT-56166 Fixed
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
// WASM_FAILS_IN: SM
|
||||||
// FILE: defaultValues.js
|
// FILE: defaultValues.js
|
||||||
function foo(x1 = "d1", x2 = "d2", x3 = "d3", x4 = "d4", x5 = "d5") {
|
function foo(x1 = "d1", x2 = "d2", x3 = "d3", x4 = "d4", x5 = "d5") {
|
||||||
return `${x1} ${x2} ${x3} ${x4} ${x5}`;
|
return `${x1} ${x2} ${x3} ${x4} ${x5}`;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
|
// WASM_FAILS_IN: SM
|
||||||
// FILE: externals.js
|
// FILE: externals.js
|
||||||
|
|
||||||
const primitives1 = [3.14, "Test string 1", true, Symbol("symbol"), 131283889534859707199254740992n];
|
const primitives1 = [3.14, "Test string 1", true, Symbol("symbol"), 131283889534859707199254740992n];
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// WASM_FAILS_IN: SM
|
||||||
// FILE: externals.js
|
// FILE: externals.js
|
||||||
function createObject() {
|
function createObject() {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Char issues
|
// Char issues
|
||||||
// IGNORE_BACKEND: JS_IR
|
// IGNORE_BACKEND: JS_IR
|
||||||
|
// WASM_FAILS_IN: SM
|
||||||
|
|
||||||
// MODULE: main
|
// MODULE: main
|
||||||
// FILE: externals.js
|
// FILE: externals.js
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// IGNORE_BACKEND: JS_IR, JS
|
// IGNORE_BACKEND: JS_IR, JS
|
||||||
|
// WASM_FAILS_IN: SM
|
||||||
// MODULE: main
|
// MODULE: main
|
||||||
// FILE: externals.kt
|
// FILE: externals.kt
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// IGNORE_BACKEND: JS_IR, JS
|
// IGNORE_BACKEND: JS_IR, JS
|
||||||
|
// WASM_FAILS_IN: SM
|
||||||
|
|
||||||
inline fun checkNPE(body: () -> Unit) {
|
inline fun checkNPE(body: () -> Unit) {
|
||||||
var throwed = false
|
var throwed = false
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// IGNORE_BACKEND: JS_IR, JS
|
// IGNORE_BACKEND: JS_IR, JS
|
||||||
|
// WASM_FAILS_IN: SM
|
||||||
|
|
||||||
@JsFun("(x) => { if (x !== 'abc') throw 'error' }")
|
@JsFun("(x) => { if (x !== 'abc') throw 'error' }")
|
||||||
external fun notNullString(x: String)
|
external fun notNullString(x: String)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// WASM_FAILS_IN: SM
|
||||||
// FILE: externals.js
|
// FILE: externals.js
|
||||||
|
|
||||||
// -- Strings --
|
// -- Strings --
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// IGNORE_BACKEND_K2: JS_IR
|
// IGNORE_BACKEND_K2: JS_IR
|
||||||
|
// WASM_FAILS_IN: SM
|
||||||
|
|
||||||
// Partial copy of js/js.translator/testData/box/native/vararg.kt
|
// Partial copy of js/js.translator/testData/box/native/vararg.kt
|
||||||
// With some additions for concrete number types, strings and function references
|
// With some additions for concrete number types, strings and function references
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
|||||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||||
import org.jetbrains.kotlin.js.config.JsConfig
|
import org.jetbrains.kotlin.js.config.JsConfig
|
||||||
import org.jetbrains.kotlin.js.facade.TranslationUnit
|
import org.jetbrains.kotlin.js.facade.TranslationUnit
|
||||||
import org.jetbrains.kotlin.js.testOld.engines.ExternalTool
|
import org.jetbrains.kotlin.js.testOld.engines.WasmVM
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
@@ -200,7 +200,7 @@ abstract class BasicWasmBoxTest(
|
|||||||
|
|
||||||
val testJs = if (debugMode >= DebugMode.DEBUG) testJsVerbose else testJsQuiet
|
val testJs = if (debugMode >= DebugMode.DEBUG) testJsVerbose else testJsQuiet
|
||||||
|
|
||||||
fun writeToFilesAndRunD8Test(name: String, res: WasmCompilerResult) {
|
fun writeToFilesAndRunTest(name: String, res: WasmCompilerResult) {
|
||||||
val dir = File(outputDirBase, name)
|
val dir = File(outputDirBase, name)
|
||||||
dir.mkdirs()
|
dir.mkdirs()
|
||||||
|
|
||||||
@@ -249,19 +249,45 @@ abstract class BasicWasmBoxTest(
|
|||||||
File(dir, mjsFile.name).writeText(mjsFile.readText())
|
File(dir, mjsFile.name).writeText(mjsFile.readText())
|
||||||
}
|
}
|
||||||
|
|
||||||
ExternalTool(System.getProperty("javascript.engine.path.V8"))
|
val failsIn = InTextDirectivesUtils.findListWithPrefixes(file.readText(), "// WASM_FAILS_IN: ")
|
||||||
.run(
|
|
||||||
"--experimental-wasm-gc",
|
val exceptions = listOf(WasmVM.V8, WasmVM.SpiderMonkey).mapNotNull map@{ vm ->
|
||||||
*jsFilesBefore.map { File(it).absolutePath }.toTypedArray(),
|
try {
|
||||||
"--module",
|
if (debugMode >= DebugMode.DEBUG) {
|
||||||
"./${entryMjs}",
|
println(" ------ Run in ${vm.name}" + if (vm.shortName in failsIn) " (expected to fail)" else "")
|
||||||
*jsFilesAfter.map { File(it).absolutePath }.toTypedArray(),
|
}
|
||||||
workingDirectory = dir
|
vm.run(
|
||||||
)
|
"./${entryMjs}",
|
||||||
|
jsFilesBefore.map { File(it).absolutePath },
|
||||||
|
jsFilesAfter.map { File(it).absolutePath },
|
||||||
|
workingDirectory = dir
|
||||||
|
)
|
||||||
|
if (vm.shortName in failsIn) {
|
||||||
|
return@map AssertionError("The test expected to fail in ${vm.name}. Please update the testdata.")
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
if (vm.shortName !in failsIn) {
|
||||||
|
return@map e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
when (exceptions.size) {
|
||||||
|
0 -> {} // Everything OK
|
||||||
|
1 -> {
|
||||||
|
throw exceptions.single()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
throw AssertionError("Failed with several exceptions. Look at suppressed exceptions below.").apply {
|
||||||
|
exceptions.forEach { addSuppressed(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeToFilesAndRunD8Test("d8", compilerResult)
|
writeToFilesAndRunTest("dev", compilerResult)
|
||||||
writeToFilesAndRunD8Test("d8-dce", compilerResultWithDCE)
|
writeToFilesAndRunTest("dce", compilerResultWithDCE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,46 @@ import java.io.InputStreamReader
|
|||||||
import java.lang.Boolean.getBoolean
|
import java.lang.Boolean.getBoolean
|
||||||
import kotlin.test.fail
|
import kotlin.test.fail
|
||||||
|
|
||||||
|
private val toolLogsEnabled: Boolean = getBoolean("kotlin.js.test.verbose")
|
||||||
|
|
||||||
val toolLogsEnabled: Boolean = getBoolean("kotlin.js.test.verbose")
|
internal sealed class WasmVM(val shortName: String) {
|
||||||
|
val name: String = javaClass.simpleName
|
||||||
|
protected val tool = ExternalTool(System.getProperty("javascript.engine.path.$name"))
|
||||||
|
|
||||||
class ExternalTool(val path: String) {
|
abstract fun run(entryMjs: String, jsFilesBefore: List<String>, jsFilesAfter: List<String>, workingDirectory: File?)
|
||||||
|
|
||||||
|
object V8 : WasmVM("V8") {
|
||||||
|
override fun run(entryMjs: String, jsFilesBefore: List<String>, jsFilesAfter: List<String>, workingDirectory: File?) {
|
||||||
|
tool.run(
|
||||||
|
"--experimental-wasm-gc",
|
||||||
|
*jsFilesBefore.toTypedArray(),
|
||||||
|
"--module",
|
||||||
|
entryMjs,
|
||||||
|
*jsFilesAfter.toTypedArray(),
|
||||||
|
workingDirectory = workingDirectory
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object SpiderMonkey : WasmVM("SM") {
|
||||||
|
override fun run(entryMjs: String, jsFilesBefore: List<String>, jsFilesAfter: List<String>, workingDirectory: File?) {
|
||||||
|
tool.run(
|
||||||
|
"--wasm-verbose",
|
||||||
|
"--wasm-gc",
|
||||||
|
"--wasm-function-references",
|
||||||
|
*jsFilesBefore.flatMap { listOf("-f", it) }.toTypedArray(),
|
||||||
|
"--module=$entryMjs",
|
||||||
|
*jsFilesAfter.flatMap { listOf("-f", it) }.toTypedArray(),
|
||||||
|
workingDirectory = workingDirectory
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class ExternalTool(val path: String) {
|
||||||
fun run(vararg arguments: String, workingDirectory: File? = null) {
|
fun run(vararg arguments: String, workingDirectory: File? = null) {
|
||||||
val command = arrayOf(path, *arguments)
|
val command = arrayOf(path, *arguments)
|
||||||
val processBuilder = ProcessBuilder(*command)
|
val processBuilder = ProcessBuilder(*command).redirectErrorStream(true)
|
||||||
.redirectErrorStream(true)
|
|
||||||
|
|
||||||
if (workingDirectory != null) {
|
if (workingDirectory != null) {
|
||||||
processBuilder.directory(workingDirectory)
|
processBuilder.directory(workingDirectory)
|
||||||
@@ -51,13 +83,3 @@ class ExternalTool(val path: String) {
|
|||||||
|
|
||||||
private fun escapeShellArgument(arg: String): String =
|
private fun escapeShellArgument(arg: String): String =
|
||||||
"'${arg.replace("'", "'\\''")}'"
|
"'${arg.replace("'", "'\\''")}'"
|
||||||
|
|
||||||
class SpiderMonkeyEngine(
|
|
||||||
jsShellPath: String = System.getProperty("javascript.engine.path.SpiderMonkey")
|
|
||||||
) {
|
|
||||||
private val jsShell = ExternalTool(jsShellPath)
|
|
||||||
|
|
||||||
fun runFile(file: String) {
|
|
||||||
jsShell.run("--wasm-gc", file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// WASM_FAILS_IN: SM
|
||||||
// EXPECTED_REACHABLE_NODES: 1283
|
// EXPECTED_REACHABLE_NODES: 1283
|
||||||
// FILE: castToNativeClassChecked.kt
|
// FILE: castToNativeClassChecked.kt
|
||||||
external abstract class S() {
|
external abstract class S() {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// WASM_FAILS_IN: SM
|
||||||
// EXPECTED_REACHABLE_NODES: 1282
|
// EXPECTED_REACHABLE_NODES: 1282
|
||||||
// FILE: castToNativeInterface.kt
|
// FILE: castToNativeInterface.kt
|
||||||
external interface I {
|
external interface I {
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// WASM_FAILS_IN: SM
|
||||||
// EXPECTED_REACHABLE_NODES: 1284
|
// EXPECTED_REACHABLE_NODES: 1284
|
||||||
// FILE: castToTypeParamBoundedByNativeInterface.kt
|
// FILE: castToTypeParamBoundedByNativeInterface.kt
|
||||||
external interface I {
|
external interface I {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// WASM_FAILS_IN: SM
|
||||||
// EXPECTED_REACHABLE_NODES: 1285
|
// EXPECTED_REACHABLE_NODES: 1285
|
||||||
package foo
|
package foo
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// WASM_FAILS_IN: SM
|
||||||
// EXPECTED_REACHABLE_NODES: 1284
|
// EXPECTED_REACHABLE_NODES: 1284
|
||||||
package foo
|
package foo
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user