diff --git a/build.gradle.kts b/build.gradle.kts index 6e30e682be6..760c1bb13c5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -814,6 +814,7 @@ tasks { dependsOn(":kotlin-atomicfu-compiler-plugin:nativeTest") dependsOn(":native:analysis-api-klib-reader:check") dependsOn(":native:native.tests:test") + dependsOn(":native:native.tests:stress:check") dependsOn(":native:objcexport-header-generator:check") dependsOn(":native:swift:swift-export-standalone:test") } diff --git a/native/native.tests/build.gradle.kts b/native/native.tests/build.gradle.kts index 753b71da926..d523fbd4163 100644 --- a/native/native.tests/build.gradle.kts +++ b/native/native.tests/build.gradle.kts @@ -4,20 +4,22 @@ plugins { } dependencies { - testImplementation(kotlinStdlib()) - testImplementation(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false } - testImplementation(intellijCore()) - testImplementation(commonDependency("commons-lang:commons-lang")) - testImplementation(commonDependency("org.jetbrains.teamcity:serviceMessages")) - testImplementation(project(":kotlin-compiler-runner-unshaded")) - testImplementation(projectTests(":compiler:tests-common")) - testImplementation(projectTests(":compiler:tests-common-new")) - testImplementation(projectTests(":compiler:test-infrastructure")) + // Reexport these dependencies to every user of nativeTest() + testApi(kotlinStdlib()) + testApi(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false } + testApi(intellijCore()) + testApi(commonDependency("commons-lang:commons-lang")) + testApi(commonDependency("org.jetbrains.teamcity:serviceMessages")) + testApi(project(":kotlin-compiler-runner-unshaded")) + testApi(projectTests(":compiler:tests-common")) + testApi(projectTests(":compiler:tests-common-new")) + testApi(projectTests(":compiler:test-infrastructure")) + testApi(project(":native:kotlin-native-utils")) + testApi(project(":native:executors")) + testImplementation(projectTests(":generators:test-generator")) testImplementation(project(":compiler:ir.serialization.native")) testImplementation(project(":compiler:fir:native")) - testImplementation(project(":native:kotlin-native-utils")) - testApi(project(":native:executors")) // Reexport this dependency to every user of nativeTest() testImplementation(project(":kotlin-util-klib-abi")) testImplementation(project(":native:swift:swift-export-standalone")) testImplementation(projectTests(":kotlin-util-klib-abi")) diff --git a/native/native.tests/stress/build.gradle.kts b/native/native.tests/stress/build.gradle.kts new file mode 100644 index 00000000000..54968456b91 --- /dev/null +++ b/native/native.tests/stress/build.gradle.kts @@ -0,0 +1,28 @@ +plugins { + kotlin("jvm") +} + +dependencies { + testImplementation(platform(libs.junit.bom)) + testImplementation(libs.junit.jupiter.api) + testRuntimeOnly(libs.junit.jupiter.engine) + + testImplementation(projectTests(":native:native.tests")) +} + +sourceSets { + "main" { none() } + "test" { + projectDefault() + generatedTestDir() + } +} + +testsJar {} + +nativeTest( + "test", + null, + requirePlatformLibs = true, + allowParallelExecution = false, // Stress tests are resource-intensive tests and they must be run in isolation. +) \ No newline at end of file diff --git a/native/native.tests/testData/standalone/kt63423_dispose_on_main_stress.kt b/native/native.tests/stress/testData/kt63423_dispose_on_main_stress.kt similarity index 99% rename from native/native.tests/testData/standalone/kt63423_dispose_on_main_stress.kt rename to native/native.tests/stress/testData/kt63423_dispose_on_main_stress.kt index 43fa8ad7f3a..11a778ef4ab 100644 --- a/native/native.tests/testData/standalone/kt63423_dispose_on_main_stress.kt +++ b/native/native.tests/stress/testData/kt63423_dispose_on_main_stress.kt @@ -2,6 +2,7 @@ * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ +// KIND: STANDALONE_NO_TR // Test depends on macOS-specific AppKit // DISABLE_NATIVE: isAppleTarget=false // DISABLE_NATIVE: targetFamily=IOS diff --git a/native/native.tests/stress/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStressTestGenerated.java b/native/native.tests/stress/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStressTestGenerated.java new file mode 100644 index 00000000000..7e3df6b161f --- /dev/null +++ b/native/native.tests/stress/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStressTestGenerated.java @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.konan.test.blackbox.support.group.UseStandardTestCaseGroupProvider; +import org.junit.jupiter.api.Tag; +import org.jetbrains.kotlin.konan.test.blackbox.support.group.FirPipeline; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/stress/testData") +@TestDataPath("$PROJECT_ROOT") +@UseStandardTestCaseGroupProvider() +@Tag("frontend-fir") +@FirPipeline() +public class FirNativeStressTestGenerated extends AbstractNativeBlackBoxTest { + @Test + public void testAllFilesPresentInTestData() { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/stress/testData"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("kt63423_dispose_on_main_stress.kt") + public void testKt63423_dispose_on_main_stress() { + runTest("native/native.tests/stress/testData/kt63423_dispose_on_main_stress.kt"); + } +} diff --git a/native/native.tests/stress/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStressTestGenerated.java b/native/native.tests/stress/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStressTestGenerated.java new file mode 100644 index 00000000000..e73cece5b4e --- /dev/null +++ b/native/native.tests/stress/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStressTestGenerated.java @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.konan.test.blackbox.support.group.UseStandardTestCaseGroupProvider; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/stress/testData") +@TestDataPath("$PROJECT_ROOT") +@UseStandardTestCaseGroupProvider() +public class NativeStressTestGenerated extends AbstractNativeBlackBoxTest { + @Test + public void testAllFilesPresentInTestData() { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/stress/testData"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("kt63423_dispose_on_main_stress.kt") + public void testKt63423_dispose_on_main_stress() { + runTest("native/native.tests/stress/testData/kt63423_dispose_on_main_stress.kt"); + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStandaloneTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStandaloneTestGenerated.java index 9553ec0325a..3bc38bd52ac 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStandaloneTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStandaloneTestGenerated.java @@ -46,12 +46,6 @@ public class FirNativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest runTest("native/native.tests/testData/standalone/kt56048.kt"); } - @Test - @TestMetadata("kt63423_dispose_on_main_stress.kt") - public void testKt63423_dispose_on_main_stress() { - runTest("native/native.tests/testData/standalone/kt63423_dispose_on_main_stress.kt"); - } - @Nested @TestMetadata("native/native.tests/testData/standalone/console") @TestDataPath("$PROJECT_ROOT") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStandaloneTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStandaloneTestGenerated.java index c3f878a99db..2a1f9cb6050 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStandaloneTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStandaloneTestGenerated.java @@ -43,12 +43,6 @@ public class NativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest { runTest("native/native.tests/testData/standalone/kt56048.kt"); } - @Test - @TestMetadata("kt63423_dispose_on_main_stress.kt") - public void testKt63423_dispose_on_main_stress() { - runTest("native/native.tests/testData/standalone/kt63423_dispose_on_main_stress.kt"); - } - @Nested @TestMetadata("native/native.tests/testData/standalone/console") @TestDataPath("$PROJECT_ROOT") diff --git a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt index 7c0b2447d5b..83d658b8012 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt @@ -526,6 +526,26 @@ fun main() { model("SwiftExport", pattern = "^([^_](.+))$", recursive = false) } } + // Stress tests + testGroup("native/native.tests/stress/tests-gen", "native/native.tests/stress/testData") { + testClass( + suiteTestClassName = "NativeStressTestGenerated", + annotations = listOf( + provider(), + ) + ) { + model("") + } + testClass( + suiteTestClassName = "FirNativeStressTestGenerated", + annotations = listOf( + provider(), + *frontendFir(), + ) + ) { + model("") + } + } } } diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt index e2e77455b9a..95b4cdfe0d9 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt @@ -90,6 +90,7 @@ private fun Test.ComputedTestProperties(init: ComputedTestProperties.() -> Unit) * along with Kotlin/Native stdlib KLIB and Kotlin/Native platform KLIBs (the latter only if [requirePlatformLibs] is `true`). * @param compilerPluginDependencies The [Configuration]s that provide compiler plugins to be enabled for the Kotlin/Native compiler * for the duration of test execution. + * @param allowParallelExecution if false, force junit to execute test sequentially */ fun Project.nativeTest( taskName: String, @@ -98,6 +99,7 @@ fun Project.nativeTest( customCompilerDependencies: List = emptyList(), customTestDependencies: List = emptyList(), compilerPluginDependencies: List = emptyList(), + allowParallelExecution: Boolean = true, body: Test.() -> Unit = {}, ) = projectTest( taskName, @@ -123,7 +125,7 @@ fun Project.nativeTest( // additional stack frames more compared to the old one because of another launcher, etc. and it turns out this is not enough. jvmArgs("-Xss2m") - val availableCpuCores: Int = Runtime.getRuntime().availableProcessors() + val availableCpuCores: Int = if (allowParallelExecution) Runtime.getRuntime().availableProcessors() else 1 if (!kotlinBuildProperties.isTeamcityBuild && minOf(kotlinBuildProperties.junit5NumberOfThreadsForParallelExecution ?: 16, availableCpuCores) > 4 ) { @@ -211,6 +213,10 @@ fun Project.nativeTest( tag?.let { includeTags(it) } } + if (!allowParallelExecution) { + systemProperty("junit.jupiter.execution.parallel.enabled", "false") + } + doFirst { logger.info( buildString { diff --git a/settings.gradle b/settings.gradle index 6ec8e362625..c9c7d381cc3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -650,7 +650,8 @@ if (buildProperties.inJpsBuildIdeaSync) { ":kotlin-test", ":kotlin-test:kotlin-test-js-it", - ":native:native.tests" + ":native:native.tests", + ":native:native.tests:stress" project(':kotlin-stdlib-common').projectDir = "$rootDir/libraries/stdlib/common" as File project(':kotlin-stdlib').projectDir = "$rootDir/libraries/stdlib" as File @@ -668,7 +669,6 @@ if (buildProperties.inJpsBuildIdeaSync) { project(':kotlin-test').projectDir = "$rootDir/libraries/kotlin.test" as File project(':kotlin-test:kotlin-test-js-it').projectDir = "$rootDir/libraries/kotlin.test/js/it" as File - project(':native:native.tests').projectDir = "$rootDir/native/native.tests" as File } include ":compiler:android-tests"