[WASM] BasicWasmBoxTest refactoring
This commit is contained in:
@@ -75,7 +75,7 @@ abstract class BasicWasmBoxTest(
|
|||||||
val outputWasmNoDceFile = File("$outputFileNoDceBase.wasm")
|
val outputWasmNoDceFile = File("$outputFileNoDceBase.wasm")
|
||||||
val outputJsNoDceFile = File("$outputFileNoDceBase.js")
|
val outputJsNoDceFile = File("$outputFileNoDceBase.js")
|
||||||
val outputBrowserNoDceDir = File("$outputFileNoDceBase.browser")
|
val outputBrowserNoDceDir = File("$outputFileNoDceBase.browser")
|
||||||
val languageVersionSettings = inputFiles.mapNotNull { it.languageVersionSettings }.firstOrNull()
|
val languageVersionSettings = inputFiles.firstNotNullOfOrNull { it.languageVersionSettings }
|
||||||
|
|
||||||
val kotlinFiles = mutableListOf<String>()
|
val kotlinFiles = mutableListOf<String>()
|
||||||
val jsFilesBefore = mutableListOf<String>()
|
val jsFilesBefore = mutableListOf<String>()
|
||||||
@@ -142,9 +142,7 @@ abstract class BasicWasmBoxTest(
|
|||||||
compileAndRun(
|
compileAndRun(
|
||||||
phaseConfig = phaseConfig,
|
phaseConfig = phaseConfig,
|
||||||
sourceModule = sourceModule,
|
sourceModule = sourceModule,
|
||||||
config = config,
|
|
||||||
testPackage = testPackage,
|
testPackage = testPackage,
|
||||||
testFunction = TEST_FUNCTION,
|
|
||||||
dceEnabled = false,
|
dceEnabled = false,
|
||||||
outputWatFile = outputWatNoDceFile,
|
outputWatFile = outputWatNoDceFile,
|
||||||
outputWasmFile = outputWasmNoDceFile,
|
outputWasmFile = outputWasmNoDceFile,
|
||||||
@@ -158,9 +156,7 @@ abstract class BasicWasmBoxTest(
|
|||||||
compileAndRun(
|
compileAndRun(
|
||||||
phaseConfig = phaseConfig,
|
phaseConfig = phaseConfig,
|
||||||
sourceModule = sourceModule,
|
sourceModule = sourceModule,
|
||||||
config = config,
|
|
||||||
testPackage = testPackage,
|
testPackage = testPackage,
|
||||||
testFunction = TEST_FUNCTION,
|
|
||||||
dceEnabled = true,
|
dceEnabled = true,
|
||||||
outputBrowserDir = outputBrowserDir,
|
outputBrowserDir = outputBrowserDir,
|
||||||
debugMode = debugMode,
|
debugMode = debugMode,
|
||||||
@@ -185,9 +181,7 @@ abstract class BasicWasmBoxTest(
|
|||||||
private fun compileAndRun(
|
private fun compileAndRun(
|
||||||
phaseConfig: PhaseConfig,
|
phaseConfig: PhaseConfig,
|
||||||
sourceModule: ModulesStructure,
|
sourceModule: ModulesStructure,
|
||||||
config: JsConfig,
|
|
||||||
testPackage: String?,
|
testPackage: String?,
|
||||||
testFunction: String,
|
|
||||||
dceEnabled: Boolean,
|
dceEnabled: Boolean,
|
||||||
outputWatFile: File,
|
outputWatFile: File,
|
||||||
outputWasmFile: File,
|
outputWasmFile: File,
|
||||||
@@ -201,7 +195,7 @@ abstract class BasicWasmBoxTest(
|
|||||||
depsDescriptors = sourceModule,
|
depsDescriptors = sourceModule,
|
||||||
phaseConfig = phaseConfig,
|
phaseConfig = phaseConfig,
|
||||||
irFactory = IrFactoryImpl,
|
irFactory = IrFactoryImpl,
|
||||||
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
|
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, TEST_FUNCTION))),
|
||||||
propertyLazyInitialization = true,
|
propertyLazyInitialization = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -219,8 +213,8 @@ abstract class BasicWasmBoxTest(
|
|||||||
const wasmBinary = read(String.raw`${outputWasmFile.absoluteFile}`, 'binary');
|
const wasmBinary = read(String.raw`${outputWasmFile.absoluteFile}`, 'binary');
|
||||||
const wasmModule = new WebAssembly.Module(wasmBinary);
|
const wasmModule = new WebAssembly.Module(wasmBinary);
|
||||||
wasmInstance = new WebAssembly.Instance(wasmModule, { js_code });
|
wasmInstance = new WebAssembly.Instance(wasmModule, { js_code });
|
||||||
const ${sanitizeName(config.moduleId)} = wasmInstance.exports;
|
const ${sanitizeName(TEST_MODULE)} = wasmInstance.exports;
|
||||||
${createJsRun(wasmInstance = "wasmInstance", testFunction = testFunction, dceEnabled = dceEnabled)}
|
${createJsRun(wasmInstance = "wasmInstance", dceEnabled = dceEnabled)}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
outputJsFile.write(compilerResult.js + "\n" + testRunner)
|
outputJsFile.write(compilerResult.js + "\n" + testRunner)
|
||||||
|
|
||||||
@@ -239,12 +233,12 @@ abstract class BasicWasmBoxTest(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createJsRun(wasmInstance: String, testFunction: String, dceEnabled: Boolean) = """
|
private fun createJsRun(wasmInstance: String, dceEnabled: Boolean) = """
|
||||||
let actualResult
|
let actualResult
|
||||||
try {
|
try {
|
||||||
$wasmInstance.exports.__init();
|
$wasmInstance.exports.__init();
|
||||||
$wasmInstance.exports.startUnitTests?.();
|
$wasmInstance.exports.startUnitTests?.();
|
||||||
actualResult = $wasmInstance.exports.$testFunction();
|
actualResult = $wasmInstance.exports.$TEST_FUNCTION();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log('Failed with exception!')
|
console.log('Failed with exception!')
|
||||||
console.log('Message: ' + e.message)
|
console.log('Message: ' + e.message)
|
||||||
@@ -262,7 +256,7 @@ abstract class BasicWasmBoxTest(
|
|||||||
const response = await fetch("index.wasm");
|
const response = await fetch("index.wasm");
|
||||||
const wasmBinary = await response.arrayBuffer();
|
const wasmBinary = await response.arrayBuffer();
|
||||||
wasmInstance = (await WebAssembly.instantiate(wasmBinary, { js_code })).instance;
|
wasmInstance = (await WebAssembly.instantiate(wasmBinary, { js_code })).instance;
|
||||||
${createJsRun(wasmInstance = "wasmInstance", testFunction = "box", dceEnabled = dceEnabled)}
|
${createJsRun(wasmInstance = "wasmInstance", dceEnabled = dceEnabled)}
|
||||||
console.log("Test passed!");
|
console.log("Test passed!");
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user