CommonizerIT: Implement test commonizeInterop using posix APIs

^KT-45497
This commit is contained in:
sebastian.sellmair
2021-03-23 09:58:31 +01:00
committed by Space
parent 7f9fe6b332
commit a0557ad937
9 changed files with 91 additions and 0 deletions
@@ -207,6 +207,27 @@ class CommonizerIT : BaseGradleIT() {
}
}
@Test
fun `test commonizeInterop using posix APIs`() {
with(preparedProject("commonizeInteropUsingPosixApis")) {
build(":commonizeCInterop") {
assertSuccessful()
assertTasksExecuted(":cinteropWithPosixTargetA")
assertTasksExecuted(":cinteropWithPosixTargetB")
assertTasksExecuted(":commonizeNativeDistribution")
assertTasksExecuted(":commonizeCInterop")
}
build(":compileNativeMainKotlinMetadata") {
assertSuccessful()
assertTasksUpToDate(":cinteropWithPosixTargetA")
assertTasksUpToDate(":cinteropWithPosixTargetB")
assertTasksUpToDate(":commonizeNativeDistribution")
assertTasksUpToDate(":commonizeCInterop")
}
}
}
private fun preparedProject(name: String): Project {
return Project(name).apply {
setupWorkingDir()
@@ -0,0 +1,33 @@
plugins {
kotlin("multiplatform")
}
repositories {
mavenLocal()
mavenCentral()
}
kotlin {
val targetA = <targetA>("targetA")
val targetB = <targetB>("targetB")
val commonMain by sourceSets.getting
val nativeMain by sourceSets.creating
val targetAMain by sourceSets.getting
val targetBMain by sourceSets.getting
nativeMain.dependsOn(commonMain)
targetAMain.dependsOn(nativeMain)
targetBMain.dependsOn(nativeMain)
sourceSets.all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
}
targetA.compilations.getByName("main").cinterops.create("withPosix") {
header(file("libs/withPosix.h"))
}
targetB.compilations.getByName("main").cinterops.create("withPosix") {
header(file("libs/withPosix.h"))
}
}
@@ -0,0 +1,3 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.native.enableDependencyPropagation=false
@@ -0,0 +1,2 @@
#include <sys/stat.h>
struct stat getFileStat();
@@ -0,0 +1,12 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
val kotlin_version: String by settings
plugins {
kotlin("multiplatform").version(kotlin_version)
}
}
@@ -0,0 +1,10 @@
import kotlinx.cinterop.useContents
import platform.posix.stat
import withPosix.getFileStat
fun main() {
repeat(10) {
getFileStat().useContents { score(this) }
}
}
expect fun score(stat: stat): Int
@@ -0,0 +1,5 @@
import platform.posix.stat
actual fun score(stat: stat): Int {
return stat.st_blocks.toInt()
}
@@ -0,0 +1,5 @@
import platform.posix.stat
actual fun score(stat: stat): Int {
return stat.rawPtr.toLong().toInt()
}