[test][dwarfdump] infrostructure to complex test cases.

some time we need more complex tests then just one file compilation, e.g test with libraries different flags and so on. Presented infrostructure allows to evaluate cinterop, konanc and dwarfdump complex scenarious
This commit is contained in:
Vasily Levchenko
2020-07-21 16:32:51 +02:00
parent e4eb223ff9
commit a4bb7d9730
3 changed files with 53 additions and 3 deletions
@@ -13,7 +13,9 @@ import java.nio.file.Paths
object DistProperties {
private val dist: Path = Paths.get(requireProp("kotlin.native.home"))
private val konancDriver = if (HostManager.host.family == Family.MINGW) "konanc.bat" else "konanc"
private val cinteropDriver = if (HostManager.host.family == Family.MINGW) "cinterop.bat" else "cinterop"
val konanc: Path = dist.resolve("bin/$konancDriver")
val cinterop: Path = dist.resolve("bin/$cinteropDriver")
val lldb: Path = Paths.get("lldb")
val devToolsSecurity: Path = Paths.get("DevToolsSecurity")
val dwarfDump: Path = Paths.get("dwarfdump")
@@ -35,6 +35,16 @@ class ToolDriver(
}
}
fun cinterop(defFile:Path, output: Path, pkg: String, vararg args: String) {
val allArgs = listOf("-o", output.toString(), "-def", defFile.toString(), "-pkg", pkg, *args).toTypedArray()
//TODO: do we need in process cinterop?
subprocess(DistProperties.cinterop, *allArgs).thrownIfFailed()
check(Files.exists(output)) {
"Compiler has not produced an output at $output"
}
}
fun runLldb(program: Path, commands: List<String>): String {
val args = listOf("-b", "-o", "command script import \"${DistProperties.lldbPrettyPrinters}\"") +
commands.flatMap { listOf("-o", it) }
@@ -43,8 +53,8 @@ class ToolDriver(
.stdout
}
fun runDwarfDump(program: Path, processor:List<DwarfTag>.()->Unit) {
val out = subprocess(DistProperties.dwarfDump, "${program}.dSYM/Contents/Resources/DWARF/${program.fileName}").takeIf { it.process.exitValue() == 0 }?.stdout ?: error("${program}.dSYM/Contents/Resources/DWARF/${program.fileName}")
fun runDwarfDump(program: Path, vararg args:String = emptyArray(), processor:List<DwarfTag>.()->Unit) {
val out = subprocess(DistProperties.dwarfDump, "${program}.dSYM/Contents/Resources/DWARF/${program.fileName}", *args).takeIf { it.process.exitValue() == 0 }?.stdout ?: error("${program}.dSYM/Contents/Resources/DWARF/${program.fileName}")
DwarfUtilParser().parse(StringReader(out)).tags.toList().processor()
}
}
@@ -9,6 +9,7 @@ import org.intellij.lang.annotations.Language
import org.junit.Assert.fail
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
/**
* An integration test for debug info.
@@ -109,7 +110,44 @@ fun dwarfDumpTest(@Language("kotlin") programText: String, flags: List<String>,
val driver = ToolDriver()
Files.write(source, programText.trimIndent().toByteArray())
driver.compile(source, output, "-g", *flags.toTypedArray())
driver.runDwarfDump(output, test)
driver.runDwarfDump(output, processor = test)
}
}
class ToolDriverHelper(private val driver: ToolDriver, private val root:Path) {
fun String.cinterop(pkg:String, output: String):Path {
val def = feedOutput("$output.def")
val lib = root.resolve("$output.klib")
driver.cinterop(def, lib, pkg)
return lib
}
fun String.library(output: String, vararg flags:String) = feedOutput("$output.kt").compile(root.resolve("$output.klib"), "-p", "library", *flags)
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) }
fun Path.dwarfDumpLookup(address: Long, parser:List<DwarfTag>.() -> Unit) = driver.runDwarfDump(this, "-lookup", address.toString(), processor = parser)
private fun String.feedOutput(output: String) = root.resolve(output).also {
Files.write(it, this.trimIndent().toByteArray())
}
}
fun dwarfDumpComplexTest(test:ToolDriverHelper.()->Unit) {
if (!haveDwarfDump) {
println("Skipping test: no dwarfdump")
return
}
with(Files.createTempDirectory("dwarfdump_test_complex")) {
toFile().deleteOnExit()
val driver = ToolDriverHelper(ToolDriver(), this).test()
}
}