[K/N][Tests] Migrate framework and objcexport tests
^KT-61259
This commit is contained in:
committed by
Space Team
parent
f00a145dd7
commit
025771460c
@@ -1087,11 +1087,6 @@ if (PlatformInfo.isAppleTarget(project)) {
|
||||
it.extraOpts '-Xforeign-exception-mode', "objc-wrap"
|
||||
}
|
||||
|
||||
createInterop("objcGh3343") {
|
||||
it.defFile 'framework/gh3343/objclib.def'
|
||||
it.headers "$projectDir/framework/gh3343/objclib.h"
|
||||
it.linkerOpts "-lobjcgh3343"
|
||||
}
|
||||
createInterop("objcKt43517") {
|
||||
it.defFile 'framework/kt43517/kt43517.def'
|
||||
}
|
||||
@@ -1877,356 +1872,6 @@ Task frameworkTest(String name, Closure<FrameworkTest> configurator) {
|
||||
}
|
||||
}
|
||||
|
||||
Task objcExportTest(
|
||||
Task allTask,
|
||||
String suffix,
|
||||
List<String> frameworkOpts,
|
||||
List<String> swiftOpts,
|
||||
Boolean isStaticFramework,
|
||||
Boolean needLazyHeaderCheck
|
||||
) {
|
||||
needLazyHeaderCheck = needLazyHeaderCheck && !PlatformInfo.isK2(project) // generating lazy headers is NYI in K2
|
||||
final String name = "testObjCExport$suffix"
|
||||
final String frameworkName = "Kt$suffix"
|
||||
final String expectedLazyHeaderName = "expectedLazy${suffix}.h"
|
||||
final Task task = frameworkTest(name) {
|
||||
final String dir = "$testOutputFramework/$name"
|
||||
final File lazyHeader = file("$dir/$target-lazy.h")
|
||||
lazyHeader.delete() // Clean up after previous runs
|
||||
|
||||
doLast {
|
||||
// Check lazy header.
|
||||
if (needLazyHeaderCheck) {
|
||||
final String expectedLazyHeaderDir = file("objcexport/")
|
||||
final File expectedLazyHeader = new File(expectedLazyHeaderDir, expectedLazyHeaderName)
|
||||
|
||||
if (!expectedLazyHeader.exists() || expectedLazyHeader.readLines() != lazyHeader.readLines()) {
|
||||
exec {
|
||||
commandLine 'diff', '-u', expectedLazyHeader, lazyHeader
|
||||
ignoreExitValue = true
|
||||
}
|
||||
|
||||
copy {
|
||||
from(lazyHeader)
|
||||
into(expectedLazyHeaderDir)
|
||||
rename { expectedLazyHeaderName }
|
||||
}
|
||||
|
||||
throw new Error("$expectedLazyHeader file patched;\nRun gradlew ${allTask.path} --continue and don't forget to commit the patch")
|
||||
}
|
||||
}
|
||||
|
||||
// Check bundle ID.
|
||||
final String frameworkPath = "$dir/$target/Kt.framework"
|
||||
final Pattern pattern = ~"<key>CFBundleIdentifier</key>\n\\s*<string>foo.bar</string>"
|
||||
final String plistPath = (target.family == Family.OSX) ?
|
||||
"$frameworkPath/Resources/Info.plist" :
|
||||
"$frameworkPath/Info.plist"
|
||||
final String plistContent = file(plistPath).text
|
||||
if (!pattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected Info.plist content:\n$plistContent")
|
||||
}
|
||||
}
|
||||
|
||||
def libraryName = frameworkName + "Library"
|
||||
def noEnumEntriesLibraryName = frameworkName + "NoEnumEntriesLibrary"
|
||||
File exportedKlibArtifact = null
|
||||
konanArtifacts {
|
||||
library(libraryName, targets: [target.name]) {
|
||||
srcDir "objcexport/library"
|
||||
artifactName "test-$libraryName"
|
||||
delegate.getByTarget(target.name).configure{
|
||||
UtilsKt.dependsOnDist(it)
|
||||
}
|
||||
|
||||
extraOpts "-Xshort-module-name=MyLibrary"
|
||||
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-library"
|
||||
}
|
||||
library(noEnumEntriesLibraryName, targets: [target.name]) {
|
||||
srcDir "objcexport/noEnumEntries"
|
||||
artifactName "test-no-enum-entries-$libraryName"
|
||||
delegate.getByTarget(target.name).configure{
|
||||
UtilsKt.dependsOnDist(it)
|
||||
}
|
||||
|
||||
exportedKlibArtifact = getArtifactByTarget(target.name)
|
||||
extraOpts "-Xshort-module-name=NoEnumEntriesLibrary"
|
||||
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-no-enum-entries-library"
|
||||
extraOpts "-XXLanguage:-EnumEntries"
|
||||
}
|
||||
}
|
||||
codesign = !isStaticFramework
|
||||
framework(frameworkName) {
|
||||
sources = ['objcexport']
|
||||
libraries = [libraryName, noEnumEntriesLibraryName]
|
||||
artifact = 'Kt'
|
||||
isStatic = isStaticFramework
|
||||
if (needLazyHeaderCheck) {
|
||||
opts += "-Xemit-lazy-objc-header=$lazyHeader"
|
||||
}
|
||||
opts += [
|
||||
"-Xexport-kdoc",
|
||||
"-Xbinary=bundleId=foo.bar",
|
||||
"-Xexport-library=$exportedKlibArtifact",
|
||||
"-module-name", "Kt"
|
||||
]
|
||||
opts += frameworkOpts
|
||||
}
|
||||
swiftSources = ['objcexport']
|
||||
swiftExtraOpts = swiftOpts
|
||||
if (isNoopGC) {
|
||||
swiftExtraOpts += ["-D", "NOOP_GC"]
|
||||
}
|
||||
if (isAggressiveGC) {
|
||||
swiftExtraOpts += ["-D", "AGGRESSIVE_GC"]
|
||||
}
|
||||
}
|
||||
allTask.dependsOn(task)
|
||||
return task
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (PlatformInfo.isAppleTarget(project)) {
|
||||
final Task ObjCExportAllTask = tasks.create("testObjCExportAll")
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'',
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
true
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'NoGenerics',
|
||||
["-Xno-objc-generics"],
|
||||
[ '-D', 'NO_GENERICS' ],
|
||||
false,
|
||||
true
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'LegacySuspendUnit',
|
||||
["-Xbinary=unitSuspendFunctionObjCExport=legacy"],
|
||||
[ '-D', 'LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT' ],
|
||||
false,
|
||||
true
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'NoSwiftMemberNameMangling',
|
||||
["-Xbinary=objcExportDisableSwiftMemberNameMangling=true"],
|
||||
[ '-D', 'DISABLE_MEMBER_NAME_MANGLING' ],
|
||||
false,
|
||||
false
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'NoInterfaceMemberNameMangling',
|
||||
["-Xbinary=objcExportIgnoreInterfaceMethodCollisions=true"],
|
||||
[ '-D', 'DISABLE_INTERFACE_METHOD_NAME_MANGLING' ],
|
||||
false,
|
||||
false
|
||||
)
|
||||
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'Static',
|
||||
["-Xbinary=objcExportSuspendFunctionLaunchThreadRestriction=none"],
|
||||
[ '-D', 'ALLOW_SUSPEND_ANY_THREAD' ],
|
||||
true,
|
||||
false
|
||||
)
|
||||
|
||||
|
||||
frameworkTest('testValuesGenericsFramework') {
|
||||
framework('ValuesGenerics') {
|
||||
sources = ['objcexport/values.kt', 'framework/values_generics']
|
||||
}
|
||||
swiftSources = ['framework/values_generics/']
|
||||
}
|
||||
|
||||
frameworkTest("testStdlibFramework") {
|
||||
framework('Stdlib') {
|
||||
sources = ['framework/stdlib']
|
||||
}
|
||||
swiftSources = ['framework/stdlib/']
|
||||
}
|
||||
|
||||
if (cacheTesting != null && cacheTesting.isDynamic) {
|
||||
// testMultipleFrameworks disabled until https://youtrack.jetbrains.com/issue/KT-34262 is fixed.
|
||||
} else frameworkTest("testMultipleFrameworks") {
|
||||
framework('First') {
|
||||
sources = ['framework/multiple/framework1', 'framework/multiple/shared']
|
||||
}
|
||||
framework('Second') {
|
||||
sources = ['framework/multiple/framework2', 'framework/multiple/shared']
|
||||
}
|
||||
swiftSources = ['framework/multiple']
|
||||
}
|
||||
|
||||
frameworkTest("testMultipleFrameworksStatic") {
|
||||
// this test doesn't work with caches.
|
||||
if (cacheTesting != null && !runtimeAssertionsPanic) {
|
||||
// See https://youtrack.jetbrains.com/issue/KT-34261.
|
||||
expectedExitStatus = 134
|
||||
}
|
||||
|
||||
framework('FirstStatic') {
|
||||
artifact = 'First'
|
||||
sources = ['framework/multiple/framework1', 'framework/multiple/shared']
|
||||
isStatic = true
|
||||
opts = ['-Xstatic-framework', "-Xpre-link-caches=enable"]
|
||||
}
|
||||
framework('SecondStatic') {
|
||||
artifact = 'Second'
|
||||
sources = ['framework/multiple/framework2', 'framework/multiple/shared']
|
||||
isStatic = true
|
||||
opts = ['-Xstatic-framework', "-Xpre-link-caches=enable"]
|
||||
}
|
||||
codesign = false
|
||||
swiftSources = ['framework/multiple']
|
||||
}
|
||||
|
||||
frameworkTest("testGh3343Framework") {
|
||||
framework('Gh3343') {
|
||||
sources = ['framework/gh3343']
|
||||
libraries = ['objcGh3343']
|
||||
}
|
||||
swiftSources = ['framework/gh3343/']
|
||||
}
|
||||
|
||||
frameworkTest("testKt42397Framework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework("Kt42397") {
|
||||
sources = ['framework/kt42397']
|
||||
}
|
||||
swiftSources = ['framework/kt42397']
|
||||
}
|
||||
|
||||
frameworkTest("testKt43517Framework") {
|
||||
framework('Kt43517') {
|
||||
sources = ['framework/kt43517']
|
||||
libraries = ['objcKt43517']
|
||||
}
|
||||
swiftSources = ['framework/kt43517/']
|
||||
}
|
||||
|
||||
frameworkTest("testStackTraceFramework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework('Stacktrace') {
|
||||
sources = ['framework/stacktrace']
|
||||
opts = ['-g']
|
||||
}
|
||||
swiftSources = ['framework/stacktrace/']
|
||||
}
|
||||
|
||||
frameworkTest("testStackTraceBridgesFramework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework('StacktraceBridges') {
|
||||
sources = ['framework/stacktraceBridges']
|
||||
opts = ['-g']
|
||||
}
|
||||
swiftSources = ['framework/stacktraceBridges/']
|
||||
}
|
||||
|
||||
|
||||
frameworkTest("testStackTraceByLibbacktraceFramework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework('StacktraceByLibbacktrace') {
|
||||
sources = ['framework/stacktraceByLibbacktrace']
|
||||
opts = ['-g', '-Xbinary=sourceInfoType=libbacktrace']
|
||||
}
|
||||
swiftSources = ['framework/stacktraceByLibbacktrace/']
|
||||
}
|
||||
|
||||
frameworkTest("testAbstractInstantiationFramework") {
|
||||
framework('AbstractInstantiation') {
|
||||
sources = ['framework/abstractInstantiation']
|
||||
}
|
||||
swiftSources = ['framework/abstractInstantiation/']
|
||||
expectedExitStatus = 134
|
||||
}
|
||||
|
||||
frameworkTest("testFrameworkBundleId") {
|
||||
def currentTarget = project.target.name
|
||||
enabled = currentTarget.startsWith("mac")
|
||||
|
||||
framework("Foo") {
|
||||
sources = ["framework/bundle_id/main.kt", "framework/bundle_id/lib.kt"]
|
||||
opts = ["-Xbinary=bundleVersion=FooBundleVersion", "-Xbinary=bundleShortVersionString=FooBundleShortVersionString"]
|
||||
}
|
||||
swiftSources = []
|
||||
|
||||
doLast {
|
||||
def frameworkPath = "$testOutputFramework/testFrameworkBundleId/$target/Foo.framework"
|
||||
def bundleIdPattern = ~"<key>CFBundleIdentifier</key>\n\\s*<string>Foo</string>"
|
||||
def bundleShortVersionStringPattern = ~"<key>CFBundleShortVersionString</key>\n\\s*<string>FooBundleShortVersionString</string>"
|
||||
def bundleVersionPattern = ~"<key>CFBundleVersion</key>\n\\s*<string>FooBundleVersion</string>"
|
||||
def plistContent = file("$frameworkPath/Resources/Info.plist").text
|
||||
if (!bundleIdPattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected CFBundleIdentifier in Info.plist:\n$plistContent")
|
||||
}
|
||||
if (!bundleShortVersionStringPattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected CFBundleShortVersionString in Info.plist:\n$plistContent")
|
||||
}
|
||||
if (!bundleVersionPattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected CFBundleVersion in Info.plist:\n$plistContent")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest("testForwardDeclarationsFramework") {
|
||||
framework('ForwardDeclarations') {
|
||||
sources = ['framework/forwardDeclarations']
|
||||
libraries = ['frameworkForwardDeclarations']
|
||||
}
|
||||
swiftSources = ['framework/forwardDeclarations/']
|
||||
}
|
||||
|
||||
frameworkTest("testFrameworkUsesFoundationModule") {
|
||||
framework("Bar") {
|
||||
sources = ["framework/use_foundation_module/framework.kt"]
|
||||
}
|
||||
swiftSources = []
|
||||
doLast {
|
||||
def frameworkPath = "$testOutputFramework/testFrameworkUsesFoundationModule/$target/Bar.framework"
|
||||
def moduleMapContent = file("$frameworkPath/Modules/module.modulemap").text
|
||||
def useFoundationPattern = ~"use Foundation"
|
||||
if (!useFoundationPattern.matcher(moduleMapContent).find()) {
|
||||
throw new Error("Expected use of Foundation module:\n$moduleMapContent")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest("testKt56233Framework") {
|
||||
framework("Kt56233") {
|
||||
sources = ['framework/kt56233']
|
||||
}
|
||||
swiftSources = ['framework/kt56233']
|
||||
if (isAggressiveGC) {
|
||||
swiftExtraOpts += ["-D", "AGGRESSIVE_GC"]
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest("testKt57791Framework") {
|
||||
framework("Kt57791") {
|
||||
sources = ['framework/kt57791']
|
||||
}
|
||||
swiftSources = ['framework/kt57791']
|
||||
}
|
||||
|
||||
frameworkTest("testPermanentObjectsFramework") {
|
||||
enabled = !isNoopGC // Requires gc to actually happen.
|
||||
framework("PermanentObjects") {
|
||||
sources = ['framework/permanentObjects']
|
||||
opts = ['-opt-in=kotlin.native.internal.InternalForKotlinNative']
|
||||
}
|
||||
swiftSources = ['framework/permanentObjects']
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("override_konan_properties0", KonanDriverTest) {
|
||||
disabled = isAggressiveGC // No need to test with different GC schedulers
|
||||
def overrides = PlatformInfo.isWindows()
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.util.logging.Logger
|
||||
import kotlin.time.Duration
|
||||
|
||||
private fun defaultDeviceId(target: KonanTarget) = when (target.family) {
|
||||
Family.TVOS -> "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-4K"
|
||||
@@ -162,4 +163,4 @@ class XcodeSimulatorExecutor(
|
||||
this.environment.putAll(env)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
import clib.*
|
||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
import forwardDeclarations.*
|
||||
import cnames.structs.ForwardDeclaredStruct
|
||||
import objcnames.classes.ForwardDeclaredClass
|
||||
import objcnames.protocols.ForwardDeclaredProtocolProtocol
|
||||
+2
-2
@@ -2,7 +2,7 @@ import ForwardDeclarations
|
||||
|
||||
private func test1() throws {
|
||||
let ptr = UnsafeMutableRawPointer(bitPattern: 0x1234)
|
||||
try assertEquals(actual: LibKt.sameForwardDeclaredStruct(ptr: ptr), expected: ptr)
|
||||
try assertEquals(actual: ForwardDeclarationsKt.sameForwardDeclaredStruct(ptr: ptr), expected: ptr)
|
||||
|
||||
// We can't actually test this, because Swift can't import neither types nor functions due to
|
||||
// "interface/protocol '...' is incomplete":
|
||||
@@ -16,7 +16,7 @@ private func test1() throws {
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class TestTests : SimpleTestProvider {
|
||||
class ForwardDeclarationsTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
language = Objective-C
|
||||
headers = Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h
|
||||
headerFilter = **/objclib.h Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h
|
||||
headerFilter = gh3343.h Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
import kotlinx.cinterop.*
|
||||
import objclib.*
|
||||
import gh3343.*
|
||||
import kotlin.native.ref.*
|
||||
|
||||
fun run(): List<Any?> {
|
||||
+2
-2
@@ -2,7 +2,7 @@ import Foundation
|
||||
import Gh3343
|
||||
|
||||
func testGh3343() throws {
|
||||
let list = KtlibKt.run()
|
||||
let list = Gh3343Kt.run()
|
||||
try assertEquals(actual: list[0] as? String, expected: "42")
|
||||
try assertEquals(actual: list[1] as? Int, expected: 2)
|
||||
try assertEquals(actual: list[2] as? Int, expected: 117)
|
||||
@@ -11,7 +11,7 @@ func testGh3343() throws {
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class UselibTests : TestProvider {
|
||||
class Gh3343Tests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
+2
-2
@@ -7,7 +7,7 @@ class Results {
|
||||
|
||||
func runTestKt42397(pointer: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? {
|
||||
autoreleasepool {
|
||||
KnlibraryKt.enableMemoryChecker()
|
||||
Kt42397Kt.enableMemoryChecker()
|
||||
let results = pointer.bindMemory(to: Results.self, capacity: 1).pointee
|
||||
results.aFoo = A().foo()
|
||||
results.bFoo = B.Companion().foo()
|
||||
@@ -31,7 +31,7 @@ func testKt42397() throws {
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class TestTests : SimpleTestProvider {
|
||||
class Kt42397Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
import kt43517.*
|
||||
|
||||
fun produceEnum(): E =
|
||||
+1
-1
@@ -40,7 +40,7 @@ func kt56233() {
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class TestTests : SimpleTestProvider {
|
||||
class Kt56233Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
+2
-2
@@ -6,10 +6,10 @@ class FooImpl : Foo {
|
||||
}
|
||||
|
||||
func testKt57791() throws {
|
||||
try assertTrue(KnlibraryKt.foobar(foo: FooImpl()))
|
||||
try assertTrue(Kt57791Kt.foobar(foo: FooImpl()))
|
||||
}
|
||||
|
||||
class TestTests : TestProvider {
|
||||
class Kt57791Tests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user