[PL][tests] Adapt tests for K/N to the conditions when static cache is used w/o lazy IR

This commit is contained in:
Dmitriy Dolovov
2023-06-19 14:10:09 +02:00
committed by Space Team
parent 5f3dad14a2
commit 2e43fa7cd0
9 changed files with 53 additions and 34 deletions
+18 -8
View File
@@ -24,19 +24,29 @@ sealed interface FailurePattern
private typealias Block<T> = () -> T private typealias Block<T> = () -> T
enum class TestMode(val isJs: Boolean = false, val isNative: Boolean = false, val hasCachesEnabled: Boolean = false) { data class TestMode(
JS_NO_IC(isJs = true), val isJs: Boolean = false,
JS_WITH_IC(isJs = true), val isNative: Boolean = false,
NATIVE_CACHE_NO(isNative = true), val staticCache: Scope = Scope.NOWHERE,
NATIVE_CACHE_STATIC_ONLY_DIST(isNative = true, hasCachesEnabled = true), val lazyIr: Scope = Scope.NOWHERE
NATIVE_CACHE_STATIC_EVERYWHERE(isNative = true, hasCachesEnabled = true); ) {
enum class Scope {
NOWHERE, DISTRIBUTION, EVERYWHERE;
val notUsed: Boolean get() = this == NOWHERE
val onlyDistribution: Boolean get() = this == DISTRIBUTION
val usedEverywhere: Boolean get() = this == EVERYWHERE
}
init { init {
check(isJs xor isNative) check(isJs xor isNative)
check(isNative || !hasCachesEnabled) check(isNative || staticCache.notUsed)
check(isNative || lazyIr.notUsed)
} }
} }
enum class LazyIrMode { NO, }
fun abiTest(init: TestBuilder.() -> Unit): String { fun abiTest(init: TestBuilder.() -> Unit): String {
val builder = TestBuilderImpl() val builder = TestBuilderImpl()
builder.init() builder.init()
@@ -49,7 +59,7 @@ fun abiTest(init: TestBuilder.() -> Unit): String {
private const val OK_STATUS = "OK" private const val OK_STATUS = "OK"
private class TestBuilderImpl : TestBuilder { private class TestBuilderImpl : TestBuilder {
override val testMode = TestMode.__UNKNOWN__ override val testMode = __UNKNOWN_TEST_MODE__
private val tests = mutableListOf<Test>() private val tests = mutableListOf<Test>()
+1 -2
View File
@@ -1,6 +1,5 @@
import abitestutils.abiTest import abitestutils.abiTest
import abitestutils.TestBuilder import abitestutils.TestBuilder
import abitestutils.TestMode.NATIVE_CACHE_STATIC_EVERYWHERE
fun box() = abiTest { fun box() = abiTest {
success("PublicTopLevelClass") { PublicTopLevelClass_valueParameter(null) } success("PublicTopLevelClass") { PublicTopLevelClass_valueParameter(null) }
@@ -104,7 +103,7 @@ private inline fun TestBuilder.unlinkedConstructorSymbol(signature: String, noin
private inline fun TestBuilder.unlinkedSymbol(signature: String, functionName: String, noinline block: () -> Unit) { private inline fun TestBuilder.unlinkedSymbol(signature: String, functionName: String, noinline block: () -> Unit) {
// Need to slightly adjust the expected IR linkage error message. Reason: When Lazy IR is used the type of the // Need to slightly adjust the expected IR linkage error message. Reason: When Lazy IR is used the type of the
// symbol is determined more accurately. // symbol is determined more accurately.
val symbolKind = if ("InnerClass" in functionName && testMode == NATIVE_CACHE_STATIC_EVERYWHERE) val symbolKind = if ("InnerClass" in functionName && testMode.lazyIr.usedEverywhere)
"inner class" "inner class"
else else
"class" "class"
@@ -1,6 +1,5 @@
import abitestutils.abiTest import abitestutils.abiTest
import abitestutils.TestBuilder import abitestutils.TestBuilder
import abitestutils.TestMode.NATIVE_CACHE_STATIC_EVERYWHERE
fun box() = abiTest { fun box() = abiTest {
val c = Container() val c = Container()
@@ -61,7 +60,7 @@ private inline fun TestBuilder.unlinkedSymbol(signature: String, noinline block:
} }
private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, noinline block: () -> Unit) { private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, noinline block: () -> Unit) {
if (testMode == NATIVE_CACHE_STATIC_EVERYWHERE) { if (testMode.lazyIr.usedEverywhere) {
val functionName = signature.removePrefix("/").substringAfterLast(".") val functionName = signature.removePrefix("/").substringAfterLast(".")
expectFailure(linkage("Function '$functionName' can not be called: Private function declared in module <lib1> can not be accessed in module <main>"), block) expectFailure(linkage("Function '$functionName' can not be called: Private function declared in module <lib1> can not be accessed in module <main>"), block)
} else } else
@@ -1,6 +1,5 @@
import abitestutils.abiTest import abitestutils.abiTest
import abitestutils.TestBuilder import abitestutils.TestBuilder
import abitestutils.TestMode.NATIVE_CACHE_STATIC_EVERYWHERE
fun box() = abiTest { fun box() = abiTest {
val c = Container() val c = Container()
@@ -124,7 +123,7 @@ private inline fun TestBuilder.unlinkedSymbol(signature: String, noinline block:
} }
private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, noinline block: () -> Unit) { private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, noinline block: () -> Unit) {
if (testMode == NATIVE_CACHE_STATIC_EVERYWHERE) { if (testMode.lazyIr.usedEverywhere) {
val accessorName = signature.removePrefix("/").split('.').takeLast(2).joinToString(".") val accessorName = signature.removePrefix("/").split('.').takeLast(2).joinToString(".")
expectFailure(linkage("Property accessor '$accessorName' can not be called: Private property accessor declared in module <lib1> can not be accessed in module <main>"), block) expectFailure(linkage("Property accessor '$accessorName' can not be called: Private property accessor declared in module <lib1> can not be accessed in module <main>"), block)
} else } else
+2 -3
View File
@@ -1,5 +1,4 @@
import abitestutils.abiTest import abitestutils.abiTest
import abitestutils.TestMode.NATIVE_CACHE_STATIC_EVERYWHERE
fun box() = abiTest { fun box() = abiTest {
/** /**
@@ -18,9 +17,9 @@ fun box() = abiTest {
* The [adjustForLazyIr] function is used to adjust tested error messages depending on whether lazy IR is used or not. * The [adjustForLazyIr] function is used to adjust tested error messages depending on whether lazy IR is used or not.
*/ */
fun adjustForLazyIr(declaration: String) = fun adjustForLazyIr(declaration: String) =
if (testMode == NATIVE_CACHE_STATIC_EVERYWHERE) "Expression" else declaration if (testMode.lazyIr.usedEverywhere) "Expression" else declaration
fun adjustNoClassFoundForLazyIr(signature: String) = fun adjustNoClassFoundForLazyIr(signature: String) =
if (testMode == NATIVE_CACHE_STATIC_EVERYWHERE) "Expression uses unlinked class symbol '$signature'" else "No class found for symbol '$signature'" if (testMode.lazyIr.usedEverywhere) "Expression uses unlinked class symbol '$signature'" else "No class found for symbol '$signature'"
expectFailure(linkage("Function 'getClassToEnumFoo' can not be called: ${adjustForLazyIr("Function")} uses unlinked class symbol '/ClassToEnum.Foo'")) { getClassToEnumFoo() } expectFailure(linkage("Function 'getClassToEnumFoo' can not be called: ${adjustForLazyIr("Function")} uses unlinked class symbol '/ClassToEnum.Foo'")) { getClassToEnumFoo() }
expectFailure(linkage("Function 'getClassToEnumFooInline' can not be called: ${adjustForLazyIr("Function")} uses unlinked class symbol '/ClassToEnum.Foo'")) { getClassToEnumFooInline() } expectFailure(linkage("Function 'getClassToEnumFooInline' can not be called: ${adjustForLazyIr("Function")} uses unlinked class symbol '/ClassToEnum.Foo'")) { getClassToEnumFooInline() }
@@ -8,7 +8,7 @@ private fun TestBuilder.pe(className: String) = linkage("Property accessor 'bar.
fun box() = abiTest { fun box() = abiTest {
// For now it's not working with caches, because of incorrect lazy-IR usage. // For now it's not working with caches, because of incorrect lazy-IR usage.
// Check KT-54019 for details. // Check KT-54019 for details.
if (testMode.hasCachesEnabled) { if (!testMode.lazyIr.usedEverywhere) {
expectSuccess("OK") { "OK" } expectSuccess("OK") { "OK" }
return@abiTest return@abiTest
} }
@@ -18,7 +18,7 @@ object PartialLinkageTestUtils {
val testDir: File val testDir: File
val buildDir: File val buildDir: File
val stdlibFile: File val stdlibFile: File
val testModeName: String val testModeConstructorParameters: Map<String, String>
// Customize the source code of a module before compiling it to a KLIB. // Customize the source code of a module before compiling it to a KLIB.
fun customizeModuleSources(moduleName: String, moduleSourceDir: File) = Unit fun customizeModuleSources(moduleName: String, moduleSourceDir: File) = Unit
@@ -99,7 +99,14 @@ object PartialLinkageTestUtils {
KtUsefulTestCase.assertExists(utilsDir) KtUsefulTestCase.assertExists(utilsDir)
copySources(from = utilsDir, to = moduleBuildDirs.sourceDir) { contents -> copySources(from = utilsDir, to = moduleBuildDirs.sourceDir) { contents ->
contents.replace(TEST_MODE_PLACEHOLDER, testModeName) contents.replace(
TEST_MODE_PLACEHOLDER,
buildString {
append("TestMode(")
testModeConstructorParameters.entries.joinTo(this) { it.key + " = " + it.value }
append(")")
}
)
} }
} }
@@ -203,5 +210,5 @@ object PartialLinkageTestUtils {
const val MAIN_MODULE_NAME = "main" const val MAIN_MODULE_NAME = "main"
private const val PL_UTILS_DIR = "__utils__" private const val PL_UTILS_DIR = "__utils__"
private const val TEST_MODE_PLACEHOLDER = "TestMode.__UNKNOWN__" private const val TEST_MODE_PLACEHOLDER = "__UNKNOWN_TEST_MODE__"
} }
@@ -61,11 +61,11 @@ abstract class AbstractJsPartialLinkageWithICTestCase : AbstractJsPartialLinkage
abstract class AbstractFirJsPartialLinkageNoICTestCase : AbstractJsPartialLinkageTestCase(CompilerType.K2_NO_IC) abstract class AbstractFirJsPartialLinkageNoICTestCase : AbstractJsPartialLinkageTestCase(CompilerType.K2_NO_IC)
abstract class AbstractJsPartialLinkageTestCase(val compilerType: CompilerType) { abstract class AbstractJsPartialLinkageTestCase(val compilerType: CompilerType) {
enum class CompilerType(val testModeName: String, val es6Mode: Boolean) { enum class CompilerType(val es6Mode: Boolean) {
K1_NO_IC("JS_NO_IC", false), K1_NO_IC(false),
K1_NO_IC_WITH_ES6("JS_NO_IC", true), K1_NO_IC_WITH_ES6(true),
K1_WITH_IC("JS_WITH_IC", false), K1_WITH_IC(false),
K2_NO_IC("JS_NO_IC", false) K2_NO_IC(false)
} }
private val zipAccessor = ZipFileSystemCacheableAccessor(2) private val zipAccessor = ZipFileSystemCacheableAccessor(2)
@@ -96,7 +96,7 @@ abstract class AbstractJsPartialLinkageTestCase(val compilerType: CompilerType)
override val testDir: File = File(testPath).absoluteFile override val testDir: File = File(testPath).absoluteFile
override val buildDir: File get() = this@AbstractJsPartialLinkageTestCase.buildDir override val buildDir: File get() = this@AbstractJsPartialLinkageTestCase.buildDir
override val stdlibFile: File get() = File("libraries/stdlib/js-ir/build/classes/kotlin/js/main").absoluteFile override val stdlibFile: File get() = File("libraries/stdlib/js-ir/build/classes/kotlin/js/main").absoluteFile
override val testModeName get() = this@AbstractJsPartialLinkageTestCase.compilerType.testModeName override val testModeConstructorParameters = mapOf("isJs" to "true")
override fun buildKlib( override fun buildKlib(
moduleName: String, moduleName: String,
@@ -34,14 +34,20 @@ abstract class AbstractNativePartialLinkageTest : AbstractNativeSimpleTest() {
override val buildDir get() = this@AbstractNativePartialLinkageTest.buildDir override val buildDir get() = this@AbstractNativePartialLinkageTest.buildDir
override val stdlibFile get() = this@AbstractNativePartialLinkageTest.stdlibFile override val stdlibFile get() = this@AbstractNativePartialLinkageTest.stdlibFile
override val testModeName = with(testRunSettings.get<CacheMode>()) { override val testModeConstructorParameters = buildMap {
val cacheModeAlias = when { this["isNative"] = "true"
!useStaticCacheForDistributionLibraries -> CacheMode.Alias.NO
!useStaticCacheForUserLibraries -> CacheMode.Alias.STATIC_ONLY_DIST
else -> CacheMode.Alias.STATIC_EVERYWHERE
}
"NATIVE_CACHE_${cacheModeAlias}" val cacheMode = testRunSettings.get<CacheMode>()
when {
cacheMode.useStaticCacheForUserLibraries -> {
this["staticCache"] = "TestMode.Scope.EVERYWHERE"
this["lazyIr"] = "TestMode.Scope.NOWHERE" // by default LazyIR is disabled
}
cacheMode.useStaticCacheForDistributionLibraries -> {
this["staticCache"] = "TestMode.Scope.DISTRIBUTION"
this["lazyIr"] = "TestMode.Scope.NOWHERE" // by default LazyIR is disabled
}
}
} }
override fun customizeModuleSources(moduleName: String, moduleSourceDir: File) { override fun customizeModuleSources(moduleName: String, moduleSourceDir: File) {