1
1
import org.gradle.api.tasks.testing.*
2
2
import org.gradle.kotlin.dsl.*
3
+ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
4
+ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
3
5
import org.jetbrains.kotlin.gradle.plugin.mpp.*
4
6
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
5
7
import org.jetbrains.kotlin.gradle.tasks.*
@@ -59,6 +61,8 @@ kotlin {
59
61
}
60
62
}
61
63
}
64
+ setupBenchmarkSourceSets(sourceSets)
65
+
62
66
/*
63
67
* Configure two test runs for Native:
64
68
* 1) Main thread
@@ -84,13 +88,45 @@ kotlin {
84
88
jvm {
85
89
// For animal sniffer
86
90
withJava()
87
- compilations.create(" benchmark" ) { associateWith(this @jvm.compilations.getByName(" main" )) }
88
91
}
89
92
}
90
93
91
- benchmark {
92
- targets {
93
- register(" jvmBenchmark" )
94
+ private fun KotlinMultiplatformExtension.setupBenchmarkSourceSets (ss : NamedDomainObjectContainer <KotlinSourceSet >) {
95
+ // Forgive me, Father, for I have sinned.
96
+ // Really, that is needed to have benchmark sourcesets be the part of the project, not a separate project
97
+ val benchmarkMain by ss.creating {
98
+ dependencies {
99
+ implementation(" org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version(" benchmarks" )} " )
100
+ }
101
+ // For each source set we have to manually set path to the sources, otherwise lookup will fail
102
+ kotlin.srcDir(" benchmarks/main/kotlin" )
103
+ }
104
+
105
+ @Suppress(" UnusedVariable" )
106
+ val jvmBenchmark by ss.creating {
107
+ // For each source set we have to manually set path to the sources, otherwise lookup will fail
108
+ kotlin.srcDir(" benchmarks/jvm/kotlin" )
109
+ }
110
+
111
+ targets.matching {
112
+ it.name != " metadata"
113
+ // Doesn't work, don't want to figure it out for now
114
+ && ! it.name.contains(" wasm" )
115
+ && ! it.name.contains(" js" )
116
+ }.all {
117
+ compilations.create(" benchmark" ) {
118
+ associateWith(this @all.compilations.getByName(" main" ))
119
+ defaultSourceSet {
120
+ dependencies {
121
+ implementation(" org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version(" benchmarks" )} " )
122
+ }
123
+ dependsOn(benchmarkMain)
124
+ }
125
+ }
126
+ }
127
+
128
+ targets.matching { it.name != " metadata" }.all {
129
+ benchmark.targets.register(" ${name} Benchmark" )
94
130
}
95
131
}
96
132
@@ -131,10 +167,12 @@ val allMetadataJar by tasks.getting(Jar::class) { setupManifest(this) }
131
167
132
168
fun setupManifest (jar : Jar ) {
133
169
jar.manifest {
134
- attributes(mapOf (
135
- " Premain-Class" to " kotlinx.coroutines.debug.internal.AgentPremain" ,
136
- " Can-Retransform-Classes" to " true" ,
137
- ))
170
+ attributes(
171
+ mapOf (
172
+ " Premain-Class" to " kotlinx.coroutines.debug.internal.AgentPremain" ,
173
+ " Can-Retransform-Classes" to " true" ,
174
+ )
175
+ )
138
176
}
139
177
}
140
178
@@ -187,9 +225,11 @@ fun Test.configureJvmForLincheck(segmentSize: Int = 1) {
187
225
minHeapSize = " 1g"
188
226
maxHeapSize = " 4g" // we may need more space for building an interleaving tree in the model checking mode
189
227
// https://github.com/JetBrains/lincheck#java-9
190
- jvmArgs = listOf (" --add-opens" , " java.base/jdk.internal.misc=ALL-UNNAMED" , // required for transformation
228
+ jvmArgs = listOf (
229
+ " --add-opens" , " java.base/jdk.internal.misc=ALL-UNNAMED" , // required for transformation
191
230
" --add-exports" , " java.base/sun.security.action=ALL-UNNAMED" ,
192
- " --add-exports" , " java.base/jdk.internal.util=ALL-UNNAMED" ) // in the model checking mode
231
+ " --add-exports" , " java.base/jdk.internal.util=ALL-UNNAMED"
232
+ ) // in the model checking mode
193
233
// Adjust internal algorithmic parameters to increase the testing quality instead of performance.
194
234
systemProperty(" kotlinx.coroutines.semaphore.segmentSize" , segmentSize)
195
235
systemProperty(" kotlinx.coroutines.semaphore.maxSpinCycles" , 1 ) // better for the model checking mode
@@ -215,6 +255,9 @@ kover {
215
255
// lincheck has NPE error on `ManagedStrategyStateHolder` class
216
256
excludedClasses.addAll(" org.jetbrains.kotlinx.lincheck.*" )
217
257
}
258
+ sources {
259
+ excludedSourceSets.addAll(" benchmark" )
260
+ }
218
261
}
219
262
220
263
reports {
0 commit comments