Skip to content

Commit

Permalink
[Tests] Allow NativeEnvironmentConfigurator to fix targets per test
Browse files Browse the repository at this point in the history
It is necessary to be able to fix a certain Native target for a certain
test, and give this target the preference over the target name that is
passed by the user (or by the CI server) via the
'kotlin.internal.native.test.target' parameter.

To achieve this, a new test directive `WITH_FIXED_TARGET` is introduced.

^KT-71333
  • Loading branch information
ddolovov authored and qodana-bot committed Oct 7, 2024
1 parent 80e41d2 commit 2ae123d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ object ConfigurationDirectives : SimpleDirectivesContainer() {
""".trimIndent()
)

/** See also [WITH_PLATFORM_LIBS], [org.jetbrains.kotlin.test.services.configuration.NativeEnvironmentConfigurator.nativeTarget]. */
val WITH_FIXED_TARGET by stringDirective("Run tests with the fixed Kotlin/Native target.")

val DISABLE_TYPEALIAS_EXPANSION by directive("Disables automatic expansion of aliased types in type resolution")
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NativeEnvironmentConfigurator(testServices: TestServices) : EnvironmentCon
}
}

val nativeTarget: KonanTarget by lazy {
private val defaultNativeTarget: KonanTarget by lazy {
val userDefinedTarget = System.getProperty(TEST_PROPERTY_TEST_TARGET)
if (userDefinedTarget != null) {
HostManager().targets[userDefinedTarget]
Expand All @@ -40,6 +40,16 @@ class NativeEnvironmentConfigurator(testServices: TestServices) : EnvironmentCon
}
}

fun getNativeTarget(module: TestModule): KonanTarget {
val testDefinedTarget = module.directives[ConfigurationDirectives.WITH_FIXED_TARGET].firstOrNull()
return if (testDefinedTarget != null) {
HostManager().targets[testDefinedTarget]
?: testServices.assertions.fail { "Unsupported target name specified in '${ConfigurationDirectives.WITH_FIXED_TARGET}': $testDefinedTarget" }
} else {
defaultNativeTarget
}
}

fun distributionKlibPath(): File = File(nativeHome, "klib")

fun getRuntimePathsForModule(module: TestModule): List<String> {
Expand All @@ -50,6 +60,8 @@ class NativeEnvironmentConfigurator(testServices: TestServices) : EnvironmentCon
}

if (ConfigurationDirectives.WITH_PLATFORM_LIBS in module.directives) {
val nativeTarget = getNativeTarget(module)

// Diagnostic tests are agnostic of native target, so host is enforced to be a target.
distributionKlibPath().resolve("platform").resolve(nativeTarget.name).listFiles()?.forEach {
result += it.absolutePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Fir2IrNativeResultsConverter(testServices: TestServices) : AbstractFir2IrR

val nativeEnvironmentConfigurator = testServices.nativeEnvironmentConfigurator

val nativeTarget = nativeEnvironmentConfigurator.nativeTarget
val nativeTarget = nativeEnvironmentConfigurator.getNativeTarget(module)
val nativeDistributionKlibPath = nativeEnvironmentConfigurator.distributionKlibPath().absolutePath
val logger = testServices.compilerConfigurationProvider.getCompilerConfiguration(module).getLogger(treatWarningsAsErrors = true)

Expand Down

0 comments on commit 2ae123d

Please sign in to comment.