From 189b547e7880616c3a4d5802b73dd067660edfbf Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Fri, 31 Jul 2020 15:54:02 +0200 Subject: [PATCH] [tests][debugger] more complex scenarious supported --- .../native/test/debugger/DistProperties.kt | 1 + .../kotlin/native/test/debugger/Driver.kt | 17 +++++++-- .../kotlin/native/test/debugger/Matchers.kt | 35 +++++++++++++++++-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/DistProperties.kt b/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/DistProperties.kt index 030cb965b1c..ead2acee774 100644 --- a/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/DistProperties.kt +++ b/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/DistProperties.kt @@ -19,6 +19,7 @@ object DistProperties { val lldb: Path = Paths.get("lldb") val devToolsSecurity: Path = Paths.get("DevToolsSecurity") val dwarfDump: Path = Paths.get("dwarfdump") + val swiftc: Path = Paths.get("swiftc") val lldbPrettyPrinters: Path = dist.resolve("tools/konan_lldb.py") private fun requireProp(name: String): String diff --git a/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/Driver.kt b/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/Driver.kt index b4af45ec93f..6366ae74ff0 100644 --- a/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/Driver.kt +++ b/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/Driver.kt @@ -21,9 +21,17 @@ import java.util.concurrent.TimeUnit class ToolDriver( private val useInProcessCompiler: Boolean = false ) { - fun compile(source: Path, output: Path, vararg args: String) { + fun compile(source: Path, output: Path, vararg args: String) = compile(output, *args) { + listOf("-output", output.toString(), source.toString(), *args).toTypedArray() + } + + fun compile(output: Path, srcs:Array, vararg args: String) = compile(output, *args) { + listOf("-output", output.toString(), *srcs.map{it.toString()}.toTypedArray(), *args).toTypedArray() + } + + private fun compile(output: Path, vararg args: String, argsCalculator:() -> Array) { check(!Files.exists(output)) - val allArgs = listOf("-output", output.toString(), source.toString(), *args).toTypedArray() + val allArgs = argsCalculator() if (useInProcessCompiler) { K2Native.main(allArgs) @@ -58,6 +66,11 @@ class ToolDriver( val out = dwarfProcess.takeIf { it.process.exitValue() == 0 }?.stdout ?: error(dwarfProcess.stderr) DwarfUtilParser().parse(StringReader(out)).tags.toList().processor() } + + fun swiftc(output: Path, swiftSrc: Path, vararg args: String) { + val swiftProcess = subprocess(DistProperties.swiftc, "-o", output.toString(), swiftSrc.toString(), *args) + val out = swiftProcess.takeIf { it.process.exitValue() == 0 }?.stdout ?: error(swiftProcess.stderr) + } } data class ProcessOutput( diff --git a/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/Matchers.kt b/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/Matchers.kt index 31b66dc193b..88a0df6bb0e 100644 --- a/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/Matchers.kt +++ b/backend.native/tests/debugger/src/test/kotlin/org/jetbrains/kotlin/native/test/debugger/Matchers.kt @@ -114,7 +114,7 @@ fun dwarfDumpTest(@Language("kotlin") programText: String, flags: List, } } -class ToolDriverHelper(private val driver: ToolDriver, private val root:Path) { +class ToolDriverHelper(private val driver: ToolDriver, val root:Path) { fun String.cinterop(pkg:String, output: String):Path { val def = feedOutput("$output.def") val lib = root.resolve("$output.klib") @@ -127,16 +127,31 @@ class ToolDriverHelper(private val driver: ToolDriver, private val root:Path) { fun String.binary(output: String, vararg flags:String)= feedOutput("$output.kt").compile(root.resolve("$output.kexe"), *flags) - private fun Path.compile(output: Path, vararg flags:String) = output.also{ driver.compile(this, it, *flags) } + private fun Path.compile(output: Path, vararg flags:String) = output.also{ driver.compile(source = this, it, *flags) } fun Path.dwarfDumpLookup(address: Long, parser:List.() -> Unit) = driver.runDwarfDump(this, "-lookup", address.toString(), processor = parser) fun Path.dwarfDumpLookup(name: String, parser:List.() -> Unit) = driver.runDwarfDump(this, "-find", name, processor = parser) - private fun String.feedOutput(output: String) = root.resolve(output).also { + fun String.feedOutput(output: String) = root.resolve(output).also { Files.write(it, this.trimIndent().toByteArray()) } + fun Array.framework(name:String, vararg args:String = emptyArray()):Path = root.resolve("$name.framework").also { + + driver.compile(it, this, "-produce", "framework", *args) + } + + fun swiftc(output: String, swiftSrc: Path, vararg args: String) = root.resolve(output).also { + driver.swiftc(it, swiftSrc, *args, "-Xlinker", "-rpath", "-Xlinker", "@executable_path") + } + + fun String.lldb(program:Path) { + val lldbSessionSpec = LldbSessionSpecification.parse(this) + val result = driver.runLldb(program, lldbSessionSpec.commands) + lldbSessionSpec.match(result) + } + } fun dwarfDumpComplexTest(test:ToolDriverHelper.()->Unit) { @@ -152,6 +167,20 @@ fun dwarfDumpComplexTest(test:ToolDriverHelper.()->Unit) { } } +fun lldbComplexTest(test:ToolDriverHelper.()->Unit) { + if (!haveLldb) { + println("Skipping test: no lldb") + return + } + + + with(Files.createTempDirectory("lldb_test_complex")) { + toFile().deleteOnExit() + val driver = ToolDriverHelper(ToolDriver(), this).test() + } +} + + private val haveDwarfDump: Boolean by lazy { val version = try { subprocess(DistProperties.dwarfDump, "--version")