Skip to content

Commit cd6a1a7

Browse files
wldehqurbonzoda
authored andcommitted
Test that the configuration options override the annotations
1 parent deb5002 commit cd6a1a7

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package kotlinx.benchmark.integration
2+
3+
import kotlin.test.*
4+
import org.gradle.testkit.runner.BuildResult
5+
6+
class ConfigurationTest : GradleTest() {
7+
8+
private fun testConfiguration(
9+
setupBlock: BenchmarkConfiguration.() -> Unit,
10+
checkBlock: BuildResult.() -> Unit
11+
) {
12+
project("kotlin-multiplatform") {
13+
configuration("config") {
14+
setupBlock()
15+
}
16+
}.run("nativeConfigBenchmark") {
17+
checkBlock()
18+
}
19+
}
20+
21+
@Test
22+
fun testIterationsConfig() {
23+
val expectedIterations = 2
24+
25+
testConfiguration(
26+
setupBlock = {
27+
iterations = expectedIterations
28+
},
29+
checkBlock = {
30+
val actualIterations = output.lines().count { it.startsWith("Iteration #") }
31+
assertEquals(expectedIterations, actualIterations)
32+
}
33+
)
34+
}
35+
36+
@Test
37+
fun testOutputTimeUnitConfig() {
38+
val expectedOutputTimeUnit = "ns"
39+
40+
testConfiguration(
41+
setupBlock = {
42+
outputTimeUnit = expectedOutputTimeUnit
43+
},
44+
checkBlock = {
45+
val actualOutputTimeUnit = output.lines().find { it.contains("ops/$expectedOutputTimeUnit") }
46+
assertNotNull(actualOutputTimeUnit, "Expected output to specify time unit as $expectedOutputTimeUnit but was not found.")
47+
}
48+
)
49+
}
50+
51+
@Test
52+
fun testWarmUpConfig() {
53+
val expectedWarmUps = 2
54+
55+
testConfiguration(
56+
setupBlock = {
57+
warmups = expectedWarmUps
58+
},
59+
checkBlock = {
60+
val actualWarmUps = output.lines().count { it.startsWith("Warm-up #") }
61+
assertEquals(expectedWarmUps, actualWarmUps, "Expected $expectedWarmUps warm-ups but found $actualWarmUps")
62+
}
63+
)
64+
}
65+
66+
@Test
67+
fun testAverageTimeModeConfig() {
68+
val expectedMode = "thrpt"
69+
70+
testConfiguration(
71+
setupBlock = {
72+
mode = expectedMode
73+
},
74+
checkBlock = {
75+
val lines = output.lines()
76+
val summaryIndex = lines.indexOfFirst { it.contains("native summary:") }
77+
val benchmarkLine = lines[summaryIndex + 2]
78+
val actualMode = benchmarkLine.split(Regex("\\s+"))[1]
79+
assertEquals(expectedMode, actualMode, "Expected mode $expectedMode but found $actualMode")
80+
}
81+
)
82+
}
83+
}

0 commit comments

Comments
 (0)