[tests][debugger] more complex scenarious supported

This commit is contained in:
Vasily Levchenko
2020-07-31 15:54:02 +02:00
parent ddc9428d4f
commit 189b547e78
3 changed files with 48 additions and 5 deletions
@@ -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
@@ -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<Path>, 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<String>) {
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(
@@ -114,7 +114,7 @@ fun dwarfDumpTest(@Language("kotlin") programText: String, flags: List<String>,
}
}
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<DwarfTag>.() -> Unit) = driver.runDwarfDump(this, "-lookup", address.toString(), processor = parser)
fun Path.dwarfDumpLookup(name: String, parser:List<DwarfTag>.() -> 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<Path>.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")