[Native][tests] Clean-up in c-interop tests
This commit is contained in:
committed by
Space Team
parent
502cbe8b17
commit
cf9aa6a360
+1
-39
@@ -5,46 +5,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.konan.blackboxtest
|
package org.jetbrains.kotlin.konan.blackboxtest
|
||||||
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.*
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.*
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact.*
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.*
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
|
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
abstract class AbstractNativeCInteropBaseTest : AbstractNativeSimpleTest() {
|
abstract class AbstractNativeCInteropBaseTest : AbstractNativeSimpleTest() {
|
||||||
internal val targets: KotlinNativeTargets get() = testRunSettings.get<KotlinNativeTargets>()
|
internal val kotlinNativeClassLoader: KotlinNativeClassLoader get() = testRunSettings.get()
|
||||||
internal val kotlinNativeClassLoader: KotlinNativeClassLoader get() = testRunSettings.get<KotlinNativeClassLoader>()
|
|
||||||
|
|
||||||
internal fun TestCase.cinteropToLibrary(): TestCompilationResult<out KLIB> {
|
|
||||||
modules.singleOrNull()
|
|
||||||
val compilation = CInteropCompilation(
|
|
||||||
classLoader = testRunSettings.get(),
|
|
||||||
targets = targets,
|
|
||||||
freeCompilerArgs = freeCompilerArgs,
|
|
||||||
defFile = modules.singleOrNull()!!.files.singleOrNull()!!.location,
|
|
||||||
expectedArtifact = toLibraryArtifact()
|
|
||||||
)
|
|
||||||
return compilation.result
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun TestCase.toLibraryArtifact() = KLIB(buildDir.resolve(modules.singleOrNull()!!.name + ".klib"))
|
|
||||||
|
|
||||||
internal fun generateCInteropTestCaseWithSingleDef(defFile: File, extraArgs: List<String>): TestCase {
|
|
||||||
val moduleName: String = defFile.name
|
|
||||||
val module = TestModule.Exclusive(moduleName, emptySet(), emptySet(), emptySet())
|
|
||||||
module.files += TestFile.createCommitted(defFile, module)
|
|
||||||
|
|
||||||
return TestCase(
|
|
||||||
id = TestCaseId.Named(moduleName),
|
|
||||||
kind = TestKind.STANDALONE,
|
|
||||||
modules = setOf(module),
|
|
||||||
freeCompilerArgs = TestCompilerArgs(extraArgs),
|
|
||||||
nominalPackageName = PackageName.EMPTY,
|
|
||||||
checks = TestRunChecks.Default(testRunSettings.get<Timeouts>().executionTimeout),
|
|
||||||
extras = TestCase.WithTestRunnerExtras(TestRunnerType.DEFAULT)
|
|
||||||
).apply {
|
|
||||||
initialize(null, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-7
@@ -34,19 +34,16 @@ abstract class AbstractNativeCInteropKT39120Test : AbstractNativeCInteropBaseTes
|
|||||||
val golden1File = testPathFull.resolve("pod1.contents.gold.txt")
|
val golden1File = testPathFull.resolve("pod1.contents.gold.txt")
|
||||||
val golden2File = testPathFull.resolve("pod2.contents.gold.txt")
|
val golden2File = testPathFull.resolve("pod2.contents.gold.txt")
|
||||||
|
|
||||||
val includeFrameworkArgs = listOf("-compiler-option", "-F${testDataDir.canonicalPath}")
|
val includeFrameworkArgs = TestCompilerArgs("-compiler-option", "-F${testDataDir.canonicalPath}")
|
||||||
|
val klib1: KLIB = cinteropToLibrary(targets, def1File, buildDir, includeFrameworkArgs).assertSuccess().resultingArtifact
|
||||||
val test1Case: TestCase = generateCInteropTestCaseWithSingleDef(def1File, includeFrameworkArgs)
|
|
||||||
val klib1: KLIB = test1Case.cinteropToLibrary().assertSuccess().resultingArtifact
|
|
||||||
val contents1 = klib1.getContents(kotlinNativeClassLoader.classLoader)
|
val contents1 = klib1.getContents(kotlinNativeClassLoader.classLoader)
|
||||||
|
|
||||||
val expectedFiltered1Output = golden1File.readText()
|
val expectedFiltered1Output = golden1File.readText()
|
||||||
val actualFiltered1Output = filterContentsOutput(contents1, " pod.Version|POD|class Pod")
|
val actualFiltered1Output = filterContentsOutput(contents1, " pod.Version|POD|class Pod")
|
||||||
assertEquals(StringUtilRt.convertLineSeparators(expectedFiltered1Output), StringUtilRt.convertLineSeparators(actualFiltered1Output))
|
assertEquals(StringUtilRt.convertLineSeparators(expectedFiltered1Output), StringUtilRt.convertLineSeparators(actualFiltered1Output))
|
||||||
|
|
||||||
val cinterop2ExtraArgs = listOf("-l", klib1.klibFile.canonicalPath, "-compiler-option", "-fmodules")
|
val cinterop2ExtraArgs = TestCompilerArgs("-l", klib1.klibFile.canonicalPath, "-compiler-option", "-fmodules")
|
||||||
val test2Case: TestCase = generateCInteropTestCaseWithSingleDef(def2File, includeFrameworkArgs + cinterop2ExtraArgs)
|
val klib2: KLIB = cinteropToLibrary(targets, def2File, buildDir, includeFrameworkArgs + cinterop2ExtraArgs).assertSuccess().resultingArtifact
|
||||||
val klib2: KLIB = test2Case.cinteropToLibrary().assertSuccess().resultingArtifact
|
|
||||||
val contents2 = klib2.getContents(kotlinNativeClassLoader.classLoader)
|
val contents2 = klib2.getContents(kotlinNativeClassLoader.classLoader)
|
||||||
|
|
||||||
val expectedFiltered2Output = golden2File.readText()
|
val expectedFiltered2Output = golden2File.readText()
|
||||||
|
|||||||
+4
-5
@@ -72,14 +72,13 @@ abstract class AbstractNativeCInteropTest : AbstractNativeCInteropBaseTest() {
|
|||||||
getBuiltinsGoldenFile(testPathFull)
|
getBuiltinsGoldenFile(testPathFull)
|
||||||
else
|
else
|
||||||
getGoldenFile(testPathFull)
|
getGoldenFile(testPathFull)
|
||||||
val fmodulesArgs = if (fmodules) listOf("-compiler-option", "-fmodules") else listOf()
|
val fmodulesArgs = if (fmodules) TestCompilerArgs("-compiler-option", "-fmodules") else TestCompilerArgs.EMPTY
|
||||||
val includeArgs = if (testDataDir.name.startsWith("framework"))
|
val includeArgs = if (testDataDir.name.startsWith("framework"))
|
||||||
listOf("-compiler-option", "-F${testDataDir.canonicalPath}")
|
TestCompilerArgs("-compiler-option", "-F${testDataDir.canonicalPath}")
|
||||||
else
|
else
|
||||||
listOf("-compiler-option", "-I${includeFolder.canonicalPath}")
|
TestCompilerArgs("-compiler-option", "-I${includeFolder.canonicalPath}")
|
||||||
|
|
||||||
val testCase: TestCase = generateCInteropTestCaseWithSingleDef(defFile, includeArgs + fmodulesArgs)
|
val testCompilationResult = cinteropToLibrary(targets, defFile, buildDir, includeArgs + fmodulesArgs)
|
||||||
val testCompilationResult = testCase.cinteropToLibrary()
|
|
||||||
// If we are running fmodules-specific test without -fmodules then we want to be sure that cinterop fails the way we want it to.
|
// If we are running fmodules-specific test without -fmodules then we want to be sure that cinterop fails the way we want it to.
|
||||||
if (!fmodules && testPath.endsWith("FModules/")) {
|
if (!fmodules && testPath.endsWith("FModules/")) {
|
||||||
val loggedData = (testCompilationResult as TestCompilationResult.CompilationToolFailure).loggedData
|
val loggedData = (testCompilationResult as TestCompilationResult.CompilationToolFailure).loggedData
|
||||||
|
|||||||
+2
-2
@@ -171,7 +171,7 @@ class LinkerOutputTestKT55578 : AbstractNativeLinkerOutputTest() {
|
|||||||
|
|
||||||
private fun compileKlib(defFile: File, sourceFile: File? = null, extraArgs: List<String> = emptyList()): KLIB {
|
private fun compileKlib(defFile: File, sourceFile: File? = null, extraArgs: List<String> = emptyList()): KLIB {
|
||||||
val sourceArguments = sourceFile?.let { listOf("-Xcompile-source", sourceFile.absolutePath) } ?: emptyList()
|
val sourceArguments = sourceFile?.let { listOf("-Xcompile-source", sourceFile.absolutePath) } ?: emptyList()
|
||||||
val libraryTestCase: TestCase = generateCInteropTestCaseWithSingleDef(defFile, extraArgs + sourceArguments)
|
return cinteropToLibrary(targets, defFile, buildDir, TestCompilerArgs(extraArgs + sourceArguments))
|
||||||
return libraryTestCase.cinteropToLibrary().assertSuccess().resultingArtifact
|
.assertSuccess().resultingArtifact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-7
@@ -106,6 +106,9 @@ internal fun TestCompilationArtifact.KLIB.asLibraryDependency() =
|
|||||||
internal fun TestCompilationArtifact.KLIB.asIncludedLibraryDependency() =
|
internal fun TestCompilationArtifact.KLIB.asIncludedLibraryDependency() =
|
||||||
ExistingDependency(this, TestCompilationDependencyType.IncludedLibrary)
|
ExistingDependency(this, TestCompilationDependencyType.IncludedLibrary)
|
||||||
|
|
||||||
|
internal fun TestCompilationArtifact.KLIBStaticCache.asStaticCacheDependency() =
|
||||||
|
ExistingDependency(this, TestCompilationDependencyType.LibraryStaticCache)
|
||||||
|
|
||||||
internal fun AbstractNativeSimpleTest.compileToLibrary(sourcesDir: File, vararg dependencies: TestCompilationArtifact.KLIB) =
|
internal fun AbstractNativeSimpleTest.compileToLibrary(sourcesDir: File, vararg dependencies: TestCompilationArtifact.KLIB) =
|
||||||
compileToLibrary(sourcesDir, buildDir, *dependencies)
|
compileToLibrary(sourcesDir, buildDir, *dependencies)
|
||||||
|
|
||||||
@@ -176,16 +179,20 @@ internal fun AbstractNativeSimpleTest.compileToExecutable(testCase: TestCase, va
|
|||||||
internal fun AbstractNativeSimpleTest.compileToStaticCache(
|
internal fun AbstractNativeSimpleTest.compileToStaticCache(
|
||||||
klib: TestCompilationArtifact.KLIB,
|
klib: TestCompilationArtifact.KLIB,
|
||||||
cacheDir: File,
|
cacheDir: File,
|
||||||
): TestCompilationResult<out TestCompilationArtifact.KLIBStaticCache> {
|
vararg dependencies: TestCompilationArtifact.KLIBStaticCache
|
||||||
|
): TestCompilationArtifact.KLIBStaticCache {
|
||||||
val compilation = StaticCacheCompilation(
|
val compilation = StaticCacheCompilation(
|
||||||
settings = testRunSettings,
|
settings = testRunSettings,
|
||||||
freeCompilerArgs = TestCompilerArgs.EMPTY,
|
freeCompilerArgs = TestCompilerArgs.EMPTY,
|
||||||
StaticCacheCompilation.Options.Regular,
|
StaticCacheCompilation.Options.Regular,
|
||||||
pipelineType = testRunSettings.get(),
|
pipelineType = testRunSettings.get(),
|
||||||
dependencies = listOf(klib.asLibraryDependency()),
|
dependencies = buildList {
|
||||||
|
this += klib.asLibraryDependency()
|
||||||
|
dependencies.mapTo(this) { it.asStaticCacheDependency() }
|
||||||
|
},
|
||||||
expectedArtifact = TestCompilationArtifact.KLIBStaticCache(cacheDir, klib)
|
expectedArtifact = TestCompilationArtifact.KLIBStaticCache(cacheDir, klib)
|
||||||
)
|
)
|
||||||
return compilation.result
|
return compilation.result.assertSuccess().resultingArtifact
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun AbstractNativeSimpleTest.generateTestCaseWithSingleModule(
|
internal fun AbstractNativeSimpleTest.generateTestCaseWithSingleModule(
|
||||||
@@ -258,7 +265,7 @@ internal fun AbstractNativeSimpleTest.generateCInteropTestCaseFromSingleDefFile(
|
|||||||
|
|
||||||
private fun AbstractNativeSimpleTest.compileToLibrary(
|
private fun AbstractNativeSimpleTest.compileToLibrary(
|
||||||
testCase: TestCase,
|
testCase: TestCase,
|
||||||
dir: File,
|
outputDir: File,
|
||||||
dependencies: List<TestCompilationDependency<*>>
|
dependencies: List<TestCompilationDependency<*>>
|
||||||
): TestCompilationResult.Success<out TestCompilationArtifact.KLIB> {
|
): TestCompilationResult.Success<out TestCompilationArtifact.KLIB> {
|
||||||
val compilation = LibraryCompilation(
|
val compilation = LibraryCompilation(
|
||||||
@@ -266,7 +273,7 @@ private fun AbstractNativeSimpleTest.compileToLibrary(
|
|||||||
freeCompilerArgs = testCase.freeCompilerArgs,
|
freeCompilerArgs = testCase.freeCompilerArgs,
|
||||||
sourceModules = testCase.modules,
|
sourceModules = testCase.modules,
|
||||||
dependencies = dependencies,
|
dependencies = dependencies,
|
||||||
expectedArtifact = getLibraryArtifact(testCase, dir)
|
expectedArtifact = getLibraryArtifact(testCase, outputDir)
|
||||||
)
|
)
|
||||||
return compilation.result.assertSuccess()
|
return compilation.result.assertSuccess()
|
||||||
}
|
}
|
||||||
@@ -286,8 +293,8 @@ private fun AbstractNativeSimpleTest.compileToExecutable(
|
|||||||
return compilation.result
|
return compilation.result
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun getLibraryArtifact(testCase: TestCase, dir: File) =
|
internal fun getLibraryArtifact(testCase: TestCase, outputDir: File) =
|
||||||
TestCompilationArtifact.KLIB(dir.resolve(testCase.modules.first().name + ".klib"))
|
TestCompilationArtifact.KLIB(outputDir.resolve(testCase.modules.first().name + ".klib"))
|
||||||
|
|
||||||
private fun AbstractNativeSimpleTest.getExecutableArtifact() =
|
private fun AbstractNativeSimpleTest.getExecutableArtifact() =
|
||||||
TestCompilationArtifact.Executable(buildDir.resolve("app." + testRunSettings.get<KotlinNativeTargets>().testTarget.family.exeSuffix))
|
TestCompilationArtifact.Executable(buildDir.resolve("app." + testRunSettings.get<KotlinNativeTargets>().testTarget.family.exeSuffix))
|
||||||
|
|||||||
+5
@@ -161,10 +161,15 @@ internal enum class MutedOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class TestCompilerArgs(val compilerArgs: List<String>) {
|
internal class TestCompilerArgs(val compilerArgs: List<String>) {
|
||||||
|
constructor(vararg compilerArgs: String) : this(compilerArgs.asList())
|
||||||
|
|
||||||
private val uniqueCompilerArgs = compilerArgs.toSet()
|
private val uniqueCompilerArgs = compilerArgs.toSet()
|
||||||
override fun hashCode() = uniqueCompilerArgs.hashCode()
|
override fun hashCode() = uniqueCompilerArgs.hashCode()
|
||||||
override fun equals(other: Any?) = (other as? TestCompilerArgs)?.uniqueCompilerArgs == uniqueCompilerArgs
|
override fun equals(other: Any?) = (other as? TestCompilerArgs)?.uniqueCompilerArgs == uniqueCompilerArgs
|
||||||
|
|
||||||
|
operator fun plus(otherCompilerArgs: TestCompilerArgs): TestCompilerArgs = this + otherCompilerArgs.compilerArgs
|
||||||
|
operator fun plus(otherCompilerArgs: List<String>): TestCompilerArgs = TestCompilerArgs(compilerArgs + otherCompilerArgs)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val EMPTY = TestCompilerArgs(emptyList())
|
val EMPTY = TestCompilerArgs(emptyList())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user