From 42a8b28337c42aeb28b6b15b33686808095e0162 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Thu, 11 May 2023 19:46:50 +0200 Subject: [PATCH] [Native][tests] Don't track used memory when running in TeamCity --- buildSrc/src/main/kotlin/nativeTest.kt | 11 ++++++++++- .../blackboxtest/support/ConfigurationProperties.kt | 3 ++- .../konan/blackboxtest/support/NativeTestSupport.kt | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/nativeTest.kt b/buildSrc/src/main/kotlin/nativeTest.kt index e3a7318943e..b9436ee7bc4 100644 --- a/buildSrc/src/main/kotlin/nativeTest.kt +++ b/buildSrc/src/main/kotlin/nativeTest.kt @@ -24,7 +24,8 @@ private enum class TestProperty(shortName: String) { GC_SCHEDULER("gcScheduler"), CACHE_MODE("cacheMode"), EXECUTION_TIMEOUT("executionTimeout"), - SANITIZER("sanitizer"); + SANITIZER("sanitizer"), + TEAMCITY("teamcity"); val fullName = "kotlin.internal.native.test.$shortName" } @@ -55,6 +56,11 @@ private class ComputedTestProperties(private val task: Test) { ComputedTestProperty.Lazy(property.fullName, defaultLazyValue()) } + // Do not attempt to read the property from Gradle. Instead, set it based on the lambda return value. + fun computePrivate(property: TestProperty, value: () -> String) { + computedProperties += ComputedTestProperty.Normal(property.fullName, value()) + } + fun lazyClassPath(builder: MutableList.() -> Unit): Lazy = lazy(LazyThreadSafetyMode.NONE) { buildList(builder).takeIf { it.isNotEmpty() }?.joinToString(File.pathSeparator) { it.absolutePath } } @@ -167,6 +173,9 @@ fun Project.nativeTest( compute(CACHE_MODE) compute(EXECUTION_TIMEOUT) compute(SANITIZER) + + // Pass whether tests are running at TeamCity. + computePrivate(TEAMCITY) { kotlinBuildProperties.isTeamcityBuild.toString() } } // Pass the current Gradle task name so test can use it in logging. diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/ConfigurationProperties.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/ConfigurationProperties.kt index b84ef264217..102334dbfd2 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/ConfigurationProperties.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/ConfigurationProperties.kt @@ -12,7 +12,8 @@ import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail internal enum class ProcessLevelProperty(shortName: String) { KOTLIN_NATIVE_HOME("nativeHome"), - COMPILER_CLASSPATH("compilerClasspath"); + COMPILER_CLASSPATH("compilerClasspath"), + TEAMCITY("teamcity"); private val propertyName = fullPropertyName(shortName) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt index 6578fb209fa..e9e990739f5 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt @@ -112,6 +112,9 @@ private object NativeTestSupport { } private fun ExtensionContext.setUpMemoryTracking() { + if (ProcessLevelProperty.TEAMCITY.readValue().toBoolean()) + return // Don't track memory when running at TeamCity. It tracks memory by itself. + TestLogger.initialize() // Initialize special logging (directly to Gradle's console). val gradleTaskName = EnvironmentVariable.GRADLE_TASK_NAME.readValue()