[Native][tests] Support FIR for KLIB evolution tests
This commit is contained in:
committed by
Space Team
parent
3506e0c20f
commit
17c5f5d5a2
@@ -75,6 +75,12 @@ fun main() {
|
||||
) {
|
||||
model("binaryCompatibility/klibEvolution", recursive = false)
|
||||
}
|
||||
testClass<AbstractNativeKlibEvolutionTest>(
|
||||
suiteTestClassName = "FirNativeKlibEvolutionTestGenerated",
|
||||
annotations = listOf(provider<FirPipeline>())
|
||||
) {
|
||||
model("binaryCompatibility/klibEvolution", recursive = false)
|
||||
}
|
||||
}
|
||||
|
||||
// CInterop tests.
|
||||
|
||||
+61
-34
@@ -21,7 +21,9 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeTarg
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.SimpleTestDirectories
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Timeouts
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
|
||||
import org.jetbrains.kotlin.test.Directives
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
import org.junit.jupiter.api.Assumptions
|
||||
import org.junit.jupiter.api.Tag
|
||||
import java.io.File
|
||||
import kotlin.math.max
|
||||
@@ -31,12 +33,24 @@ import org.jetbrains.kotlin.compatibility.binary.TestModule as TModule
|
||||
@Tag("klib-evolution")
|
||||
abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() {
|
||||
|
||||
protected fun runTest(@TestDataFile testPath: String): Unit = AbstractKlibBinaryCompatibilityTest.doTest(
|
||||
filePath = testPath,
|
||||
expectedResult = "OK",
|
||||
produceKlib = ::buildKlib,
|
||||
produceAndRunProgram = ::buildAndExecuteBinary
|
||||
)
|
||||
// TODO: unmute after fixing KT-57711
|
||||
private fun isIgnoredTest(filePath: String): Boolean {
|
||||
if (!this::class.java.simpleName.startsWith("Fir"))
|
||||
return false
|
||||
|
||||
val fileName = filePath.substringAfterLast('/')
|
||||
return fileName == "addOrRemoveConst.kt" || fileName == "changeConstInitialization.kt"
|
||||
}
|
||||
|
||||
protected fun runTest(@TestDataFile testPath: String) {
|
||||
Assumptions.assumeFalse(isIgnoredTest(testPath))
|
||||
AbstractKlibBinaryCompatibilityTest.doTest(
|
||||
filePath = testPath,
|
||||
expectedResult = "OK",
|
||||
produceKlib = ::buildKlib,
|
||||
produceAndRunProgram = ::buildAndExecuteBinary
|
||||
)
|
||||
}
|
||||
|
||||
private fun buildKlib(
|
||||
testModule: TModule,
|
||||
@@ -49,7 +63,7 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() {
|
||||
)
|
||||
val klibFile = module.klibFile
|
||||
|
||||
val testCase = mkTestCase(module, COMPILER_ARGS_FOR_KLIB)
|
||||
val testCase = makeTestCase(module.name, module.module, COMPILER_ARGS_FOR_KLIB)
|
||||
|
||||
val compilation = LibraryCompilation(
|
||||
settings = testRunSettings,
|
||||
@@ -68,46 +82,58 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() {
|
||||
mainTestModule: TModule,
|
||||
expectedResult: String
|
||||
) {
|
||||
val binaryVersion = moduleVersions.values.maxOrNull() ?: 2
|
||||
|
||||
buildKlib(mainTestModule, binaryVersion)
|
||||
val latestVersion = moduleVersions.values.maxOrNull() ?: 2
|
||||
|
||||
val (binarySourceDir, binaryOutputDir) = listOf(BINARY_SOURCE_DIR_NAME, BINARY_OUTPUT_DIR_NAME).map {
|
||||
buildDir.resolve(LAUNCHER_MODULE_NAME).resolve(it).apply { mkdirs() }
|
||||
}
|
||||
|
||||
val launcherModule = LightDependencyWithVersion(LAUNCHER_MODULE_NAME, binaryVersion).apply {
|
||||
module.files += TestFile.createUncommitted(
|
||||
location = binarySourceDir.resolve(LAUNCHER_FILE_NAME),
|
||||
module = module,
|
||||
text = generateBoxFunctionLauncher("box", expectedResult)
|
||||
)
|
||||
}
|
||||
val launcherDependencies = collectDependencies(mainTestModule.name, binaryVersion)
|
||||
val launcherText = generateBoxFunctionLauncher("box", expectedResult)
|
||||
val launcherFile = binarySourceDir.resolve(LAUNCHER_FILE_NAME)
|
||||
TFile(mainTestModule, launcherFile.name, launcherText, Directives())
|
||||
|
||||
buildKlib(mainTestModule, latestVersion)
|
||||
|
||||
val executableFile = binaryOutputDir.resolve(
|
||||
"app." + testRunSettings.get<KotlinNativeTargets>().testTarget.family.exeSuffix
|
||||
)
|
||||
val executableArtifact = TestCompilationArtifact.Executable(executableFile)
|
||||
|
||||
val cachedDependencies = if (staticCacheRequiredForEveryLibrary) {
|
||||
val cachedDependencies: List<ExistingDependency<KLIBStaticCache>> = if (staticCacheRequiredForEveryLibrary) {
|
||||
latestDependencies.map { (module, deps) ->
|
||||
buildCacheForKlib(module, deps)
|
||||
val testModule = module.module
|
||||
|
||||
val staticCacheCompilationOptions = if (testModule.name == mainTestModule.name)
|
||||
StaticCacheCompilation.Options.ForIncludedLibraryWithTests(executableArtifact, DEFAULT_EXTRAS)
|
||||
else
|
||||
StaticCacheCompilation.Options.Regular
|
||||
|
||||
buildCacheForKlib(module, staticCacheCompilationOptions, deps)
|
||||
module.klibFile.toStaticCacheArtifact().toDependency()
|
||||
}
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
val testCase = mkTestCase(launcherModule, COMPILER_ARGS_FOR_STATIC_CACHE_AND_EXECUTABLE)
|
||||
val mainModuleDependencies: List<ExistingDependency<KLIB>> = collectDependencies(mainTestModule.name, latestVersion).map { module ->
|
||||
val klibArtifact = module.klibFile.toKlib()
|
||||
|
||||
val testModule = module.module
|
||||
if (testModule.name == mainTestModule.name)
|
||||
klibArtifact.toIncludedDependency()
|
||||
else
|
||||
klibArtifact.toDependency()
|
||||
}
|
||||
|
||||
val testCase = makeTestCase(LAUNCHER_MODULE_NAME, module = null, COMPILER_ARGS_FOR_STATIC_CACHE_AND_EXECUTABLE)
|
||||
|
||||
val compilation = ExecutableCompilation(
|
||||
settings = testRunSettings,
|
||||
freeCompilerArgs = testCase.freeCompilerArgs,
|
||||
sourceModules = testCase.modules,
|
||||
extras = testCase.extras,
|
||||
dependencies = launcherDependencies.map {
|
||||
it.klibFile.toKlib().toDependency()
|
||||
} + cachedDependencies,
|
||||
expectedArtifact = TestCompilationArtifact.Executable(executableFile)
|
||||
dependencies = mainModuleDependencies + cachedDependencies,
|
||||
expectedArtifact = executableArtifact
|
||||
)
|
||||
|
||||
val compilationResult = compilation.trigger()
|
||||
@@ -118,6 +144,7 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() {
|
||||
|
||||
private fun buildCacheForKlib(
|
||||
module: LightDependencyWithVersion,
|
||||
staticCacheCompilationOptions: StaticCacheCompilation.Options,
|
||||
moduleDependencies: Collection<LightDependencyWithVersion>
|
||||
) {
|
||||
val klib = module.klibFile
|
||||
@@ -125,7 +152,7 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() {
|
||||
val compilation = StaticCacheCompilation(
|
||||
settings = testRunSettings,
|
||||
freeCompilerArgs = COMPILER_ARGS_FOR_STATIC_CACHE_AND_EXECUTABLE,
|
||||
options = StaticCacheCompilation.Options.Regular,
|
||||
options = staticCacheCompilationOptions,
|
||||
pipelineType = testRunSettings.get(),
|
||||
dependencies = moduleDependencies.map {
|
||||
it.klibFile.toStaticCacheArtifact().toDependency()
|
||||
@@ -240,13 +267,14 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() {
|
||||
return extra
|
||||
}
|
||||
|
||||
private fun mkTestCase(
|
||||
extra: LightDependencyWithVersion,
|
||||
private fun makeTestCase(
|
||||
id: String,
|
||||
module: TestModule.Exclusive?,
|
||||
compilerArgs: TestCompilerArgs
|
||||
): TestCase = TestCase(
|
||||
id = TestCaseId.Named(extra.name),
|
||||
id = TestCaseId.Named(id),
|
||||
kind = TestKind.STANDALONE,
|
||||
modules = setOf(extra.module),
|
||||
modules = setOfNotNull(module),
|
||||
freeCompilerArgs = compilerArgs,
|
||||
nominalPackageName = PackageName.EMPTY,
|
||||
checks = TestRunChecks.Default(testRunSettings.get<Timeouts>().executionTimeout),
|
||||
@@ -282,10 +310,9 @@ private fun File.toStaticCacheArtifact() = KLIBStaticCache(
|
||||
klib = KLIB(this)
|
||||
)
|
||||
|
||||
private fun KLIB.toDependency() =
|
||||
ExistingDependency(this, TestCompilationDependencyType.Library)
|
||||
private fun KLIBStaticCache.toDependency() =
|
||||
ExistingDependency(this, TestCompilationDependencyType.LibraryStaticCache)
|
||||
private fun KLIB.toDependency() = ExistingDependency(this, TestCompilationDependencyType.Library)
|
||||
private fun KLIB.toIncludedDependency() = ExistingDependency(this, TestCompilationDependencyType.IncludedLibrary)
|
||||
private fun KLIBStaticCache.toDependency() = ExistingDependency(this, TestCompilationDependencyType.LibraryStaticCache)
|
||||
|
||||
private fun <T : TestCompilationArtifact> BasicCompilation<T>.trigger(): TestCompilationResult.Success<out T> =
|
||||
result.assertSuccess()
|
||||
|
||||
Reference in New Issue
Block a user