Skip to content

Commit f371d6f

Browse files
author
Abduqodiri Qurbonzoda
committed
Refactor illegal target tests
1 parent 4ffd132 commit f371d6f

File tree

9 files changed

+95
-152
lines changed

9 files changed

+95
-152
lines changed

integration/src/main/kotlin/kotlinx/benchmark/integration/KotlinConfiguration.kt

Lines changed: 0 additions & 56 deletions
This file was deleted.

integration/src/main/kotlin/kotlinx/benchmark/integration/ProjectBuilder.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,18 @@ package kotlinx.benchmark.integration
33
class ProjectBuilder {
44
private val configurations = mutableMapOf<String, BenchmarkConfiguration>()
55
private val targets = mutableMapOf<String, BenchmarkTarget>()
6-
private val kotlinConfig = KotlinConfiguration()
76

87
fun configuration(name: String, configuration: BenchmarkConfiguration.() -> Unit = {}) {
98
configurations[name] = BenchmarkConfiguration().apply(configuration)
109
}
11-
1210
fun register(name: String, configuration: BenchmarkTarget.() -> Unit = {}) {
1311
targets[name] = BenchmarkTarget().apply(configuration)
1412
}
1513

16-
fun kotlin(configuration: KotlinConfiguration.() -> Unit) {
17-
kotlinConfig.apply(configuration)
18-
}
19-
2014
fun build(original: String): String {
2115

2216
val script =
2317
"""
24-
kotlin {
25-
${kotlinConfig.lines().joinToString("\n ")}
26-
}
2718
benchmark {
2819
configurations {
2920
${configurations.flatMap { it.value.lines(it.key) }.joinToString("\n ")}

integration/src/test/kotlin/kotlinx/benchmark/integration/InvalidTargetingTest.kt

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,42 @@ import kotlin.test.*
55
class InvalidTargetingTest : GradleTest() {
66

77
@Test
8-
fun testInvalidTargetForKotlinWASM() {
9-
val runner = project("kotlin-multiplatform") {
10-
configuration("invalidWasm") {
11-
iterations = 1
12-
iterationTime = 100
13-
iterationTimeUnit = "ms"
14-
reportFormat = "json"
15-
}
16-
register("wasmTest")
17-
kotlin {
18-
wasm("wasmTest") {
19-
nodejs()
20-
}
21-
}
22-
}
23-
24-
runner.runAndFail("invalidWasmBenchmark") {
25-
assertOutputContains("Kotlin/WASM does not support targeting NodeJS for benchmarks.")
8+
fun testWasmNodeJs() {
9+
val runner = project("invalid-target/wasm-nodejs", true)
10+
runner.runAndFail("wasmJsBenchmark") {
11+
assertOutputContains("kotlinx-benchmark supports only d8() environment for Kotlin/Wasm.")
2612
}
2713
}
2814

2915
@Test
30-
fun testInvalidTargetForKotlinJS() {
31-
val runner = project("kotlin-multiplatform") {
32-
configuration("invalidJS") {
33-
iterations = 1
34-
iterationTime = 100
35-
iterationTimeUnit = "ms"
36-
reportFormat = "json"
37-
}
38-
register("jsTest")
39-
kotlin {
40-
js("jsTest", KotlinConfiguration.IR) {
41-
d8()
42-
}
43-
}
44-
}
45-
46-
runner.runAndFail("invalidJsBenchmark") {
47-
assertOutputContains("Kotlin/JS does not support targeting D8 for benchmarks.")
16+
fun testWasmBrowser() {
17+
val runner = project("invalid-target/wasm-browser", true)
18+
runner.runAndFail("wasmJsBenchmark") {
19+
assertOutputContains("kotlinx-benchmark supports only d8() environment for Kotlin/Wasm.")
4820
}
4921
}
5022

5123
@Test
52-
fun testLegacyJsBackend() {
53-
val runner = project("kotlin-multiplatform") {
54-
configuration("legacyJS") {
55-
iterations = 1
56-
iterationTime = 100
57-
iterationTimeUnit = "ms"
58-
reportFormat = "json"
59-
}
60-
register("legacyJsTest")
61-
kotlin {
62-
js("legacyJsTest", KotlinConfiguration.LEGACY) {
63-
nodejs()
64-
}
65-
}
24+
fun testJsD8() {
25+
val runner = project("invalid-target/js-d8", true)
26+
runner.runAndFail("jsBenchmark") {
27+
assertOutputContains("kotlinx-benchmark supports only nodejs() environment for Kotlin/JS.")
6628
}
29+
}
6730

68-
runner.runAndFail("legacyJsBenchmark") {
31+
@Test
32+
fun testJsLegacyBackend() {
33+
val runner = project("invalid-target/js-legacy", true)
34+
runner.runAndFail("jsBenchmark") {
6935
assertOutputContains("Legacy Kotlin/JS backend is not supported. Please migrate to the Kotlin/JS IR compiler backend.")
7036
}
7137
}
7238

7339
@Test
74-
fun testBrowserEnvironmentForKotlinJS() {
75-
val runner = project("kotlin-multiplatform") {
76-
configuration("invalidBrowserJS") {
77-
iterations = 1
78-
iterationTime = 100
79-
iterationTimeUnit = "ms"
80-
reportFormat = "json"
81-
}
82-
register("jsBrowserTest")
83-
kotlin {
84-
js("jsBrowserTest", KotlinConfiguration.IR) {
85-
browser()
86-
}
87-
}
88-
}
89-
90-
runner.runAndFail("invalidBrowserJsBenchmark") {
91-
assertOutputContains("The browser() environment is not supported for Kotlin/JS benchmarks. Please use nodejs().")
40+
fun testJsBrowser() {
41+
val runner = project("invalid-target/js-browser", true)
42+
runner.runAndFail("jsBenchmark") {
43+
assertOutputContains("kotlinx-benchmark supports only nodejs() environment for Kotlin/JS.")
9244
}
9345
}
9446
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kotlin {
2+
js(IR) {
3+
browser()
4+
}
5+
}
6+
7+
benchmark {
8+
targets {
9+
register("js")
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kotlin {
2+
js(IR) {
3+
d8()
4+
}
5+
}
6+
7+
benchmark {
8+
targets {
9+
register("js")
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kotlin {
2+
js(LEGACY) {
3+
nodejs()
4+
}
5+
}
6+
7+
benchmark {
8+
targets {
9+
register("js")
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kotlin {
2+
wasm("wasmJs") {
3+
browser()
4+
}
5+
}
6+
7+
benchmark {
8+
targets {
9+
register("wasmJs")
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kotlin {
2+
wasm("wasmJs") {
3+
nodejs()
4+
}
5+
}
6+
7+
benchmark {
8+
targets {
9+
register("wasmJs")
10+
}
11+
}

plugin/main/src/kotlinx/benchmark/gradle/JsEngineExecTasks.kt

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,29 @@ fun Project.createJsEngineBenchmarkExecTask(
1717
compilation: KotlinJsIrCompilation
1818
) {
1919
val taskName = "${target.name}${config.capitalizedName()}${BenchmarksPlugin.BENCHMARK_EXEC_SUFFIX}"
20+
2021
val compilationTarget = compilation.target
22+
check(compilationTarget is KotlinJsIrTarget)
2123

22-
if (compilationTarget is KotlinJsSubTargetContainerDsl) {
23-
compilationTarget.whenNodejsConfigured {
24-
val execTask = createNodeJsExec(config, target, compilation, taskName)
25-
tasks.getByName(config.prefixName(RUN_BENCHMARKS_TASKNAME)).dependsOn(execTask)
24+
when (compilationTarget.platformType) {
25+
KotlinPlatformType.wasm -> {
26+
if (compilationTarget.isD8Configured) {
27+
val execTask = createD8Exec(config, target, compilation, taskName)
28+
tasks.getByName(config.prefixName(RUN_BENCHMARKS_TASKNAME)).dependsOn(execTask)
29+
} else {
30+
throw GradleException("kotlinx-benchmark supports only d8() environment for Kotlin/Wasm.")
31+
}
2632
}
27-
compilationTarget.whenBrowserConfigured {
28-
throw GradleException("The browser() environment is not supported for Kotlin/JS benchmarks. Please use nodejs().")
33+
KotlinPlatformType.js -> {
34+
if (compilationTarget.isNodejsConfigured) {
35+
val execTask = createNodeJsExec(config, target, compilation, taskName)
36+
tasks.getByName(config.prefixName(RUN_BENCHMARKS_TASKNAME)).dependsOn(execTask)
37+
} else {
38+
throw GradleException("kotlinx-benchmark supports only nodejs() environment for Kotlin/JS.")
39+
}
2940
}
30-
}
31-
32-
if (compilationTarget is KotlinWasmSubTargetContainerDsl) {
33-
compilationTarget.whenD8Configured {
34-
val execTask = createD8Exec(config, target, compilation, taskName)
35-
tasks.getByName(config.prefixName(RUN_BENCHMARKS_TASKNAME)).dependsOn(execTask)
41+
else -> {
42+
throw GradleException("Unsupported platforms type ${compilationTarget.platformType}")
3643
}
3744
}
3845
}
@@ -70,9 +77,6 @@ private fun Project.createNodeJsExec(
7077
compilation: KotlinJsIrCompilation,
7178
taskName: String
7279
): TaskProvider<NodeJsExec> = NodeJsExec.create(compilation, taskName) {
73-
if (compilation.target.platformType == KotlinPlatformType.wasm) {
74-
throw GradleException("Kotlin/WASM does not support targeting NodeJS for benchmarks.")
75-
}
7680
dependsOn(compilation.runtimeDependencyFiles)
7781
group = BenchmarksPlugin.BENCHMARKS_TASK_GROUP
7882
description = "Executes benchmark for '${target.name}' with NodeJS"
@@ -94,9 +98,6 @@ private fun Project.createD8Exec(
9498
compilation: KotlinJsIrCompilation,
9599
taskName: String
96100
): TaskProvider<D8Exec> = D8Exec.create(compilation, taskName) {
97-
if (compilation.target.platformType == KotlinPlatformType.js) {
98-
throw GradleException("Kotlin/JS does not support targeting D8 for benchmarks.")
99-
}
100101
dependsOn(compilation.runtimeDependencyFiles)
101102
group = BenchmarksPlugin.BENCHMARKS_TASK_GROUP
102103
description = "Executes benchmark for '${target.name}' with D8"

0 commit comments

Comments
 (0)