[Native][Tests] Add tests for -Xbinary=cInterfaceMode=none

This commit is contained in:
Sergey Bogolepov
2024-02-16 11:17:10 +02:00
committed by Space Team
parent dd25130464
commit 4f9c1860b1
18 changed files with 338 additions and 16 deletions
@@ -469,18 +469,25 @@ fun main() {
)
// C Export
testGroup("native/native.tests/tests-gen", "native/native.tests/testData") {
val cinterfaceModes = mapOf(
"InterfaceV1" to cinterfaceMode("V1"),
"InterfaceNone" to cinterfaceMode("NONE")
)
binaryLibraryKinds.forEach { binaryKind ->
frontendFlags.forEach { frontend ->
val frontendKey = if (frontend.key == "Classic") "" else frontend.key
val suiteTestClassName = "${frontendKey}CExport${binaryKind.key}TestGenerated"
testClass<AbstractNativeCExportTest>(
suiteTestClassName,
annotations = listOf(
binaryKind.value,
*frontend.value
)
) {
model("CExport/InterfaceV1", pattern = "^([^_](.+))$", recursive = false)
cinterfaceModes.forEach { cinterfaceMode ->
val frontendKey = if (frontend.key == "Classic") "" else frontend.key
val suiteTestClassName = "${frontendKey}CExport${binaryKind.key}${cinterfaceMode.key}TestGenerated"
testClass<AbstractNativeCExportTest>(
suiteTestClassName,
annotations = listOf(
binaryKind.value,
cinterfaceMode.value,
*frontend.value
)
) {
model("CExport/${cinterfaceMode.key}", pattern = "^([^_](.+))$", recursive = false)
}
}
}
}
@@ -566,3 +573,8 @@ private fun binaryLibraryKind(kind: String = "DYNAMIC") = annotation(
"property" to ClassLevelProperty.BINARY_LIBRARY_KIND,
"propertyValue" to kind
)
private fun cinterfaceMode(mode: String = "V1") = annotation(
EnforcedProperty::class.java,
"property" to ClassLevelProperty.C_INTERFACE_MODE,
"propertyValue" to mode
)
@@ -122,7 +122,10 @@ abstract class AbstractNativeCExportTest() : AbstractNativeSimpleTest() {
id = TestCaseId.Named(moduleName),
kind = TestKind.STANDALONE_NO_TR,
modules = setOf(module),
freeCompilerArgs = TestCompilerArgs(listOf()),
freeCompilerArgs = TestCompilerArgs(listOf(
"-opt-in", "kotlin.experimental.ExperimentalNativeApi",
"-opt-in", "kotlinx.cinterop.ExperimentalForeignApi",
)),
nominalPackageName = PackageName(moduleName),
checks = TestRunChecks(
executionTimeoutCheck = TestRunCheck.ExecutionTimeout.ShouldNotExceed(testRunSettings.get<Timeouts>().executionTimeout),
@@ -73,6 +73,7 @@ internal enum class ClassLevelProperty(val shortName: String) {
PIPELINE_TYPE("pipelineType"),
SHARED_TEST_EXECUTION("sharedTestExecution"),
BINARY_LIBRARY_KIND("binaryLibraryKind"),
C_INTERFACE_MODE("cInterfaceMode"),
;
internal val propertyName = fullPropertyName(shortName)
@@ -210,6 +210,7 @@ internal object NativeTestSupport {
output += computeUsedPartialLinkageConfig(enclosingTestClass)
output += computeCompilerOutputInterceptor(enforcedProperties)
output += computeBinaryLibraryKind(enforcedProperties)
output += computeCInterfaceMode(enforcedProperties)
return nativeTargets
}
@@ -508,6 +509,10 @@ internal object NativeTestSupport {
private fun computeBinaryLibraryKind(enforcedProperties: EnforcedProperties): BinaryLibraryKind =
ClassLevelProperty.BINARY_LIBRARY_KIND.readValue(enforcedProperties, BinaryLibraryKind.values(), BinaryLibraryKind.STATIC)
private fun computeCInterfaceMode(enforcedProperties: EnforcedProperties): CInterfaceMode =
ClassLevelProperty.C_INTERFACE_MODE.readValue(enforcedProperties, CInterfaceMode.values(), CInterfaceMode.NONE)
/*************** Test class settings (simplified) ***************/
private fun ExtensionContext.getOrCreateSimpleTestClassSettings(): SimpleTestClassSettings =
@@ -351,6 +351,7 @@ internal class BinaryLibraryCompilation(
dependencies = CategorizedDependencies(dependencies),
expectedArtifact = expectedArtifact
) {
private val cinterfaceMode = settings.get<CInterfaceMode>().compilerFlag
override val binaryOptions get() = BinaryOptions.RuntimeAssertionsMode.defaultForTesting(optimizationMode, freeCompilerArgs.assertionsMode)
override fun applySpecificArgs(argsBuilder: ArgsBuilder) = with(argsBuilder) {
@@ -360,7 +361,8 @@ internal class BinaryLibraryCompilation(
}
add(
"-produce", libraryKind,
"-output", expectedArtifact.libraryFile.absolutePath
"-output", expectedArtifact.libraryFile.absolutePath,
cinterfaceMode
)
super.applySpecificArgs(argsBuilder)
}
@@ -299,3 +299,8 @@ internal enum class CompilerOutputInterceptor {
internal enum class BinaryLibraryKind {
STATIC, DYNAMIC
}
internal enum class CInterfaceMode(val compilerFlag: String) {
V1("-Xbinary=cInterfaceMode=v1"),
NONE("-Xbinary=cInterfaceMode=none")
}