[test][debugger] refactoring
This commit is contained in:
+4
-13
@@ -13,21 +13,12 @@ import org.jetbrains.kotlin.cli.bc.K2Native
|
|||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.io.StringReader
|
import java.io.StringReader
|
||||||
import java.lang.StringBuilder
|
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.time.temporal.ChronoUnit
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: This constructor looks weird in conjunction with [DistProperties]
|
|
||||||
*/
|
|
||||||
class ToolDriver(
|
class ToolDriver(
|
||||||
private val konancDriver: Path,
|
|
||||||
private val lldb: Path,
|
|
||||||
private val dwarfDump: Path,
|
|
||||||
private val lldbPrettyPrinters: Path,
|
|
||||||
private val useInProcessCompiler: Boolean = false
|
private val useInProcessCompiler: Boolean = false
|
||||||
) {
|
) {
|
||||||
fun compile(source: Path, output: Path, vararg args: String) {
|
fun compile(source: Path, output: Path, vararg args: String) {
|
||||||
@@ -37,7 +28,7 @@ class ToolDriver(
|
|||||||
if (useInProcessCompiler) {
|
if (useInProcessCompiler) {
|
||||||
K2Native.main(allArgs)
|
K2Native.main(allArgs)
|
||||||
} else {
|
} else {
|
||||||
subprocess(konancDriver, *allArgs).thrownIfFailed()
|
subprocess(DistProperties.konanc, *allArgs).thrownIfFailed()
|
||||||
}
|
}
|
||||||
check(Files.exists(output)) {
|
check(Files.exists(output)) {
|
||||||
"Compiler has not produced an output at $output"
|
"Compiler has not produced an output at $output"
|
||||||
@@ -45,15 +36,15 @@ class ToolDriver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun runLldb(program: Path, commands: List<String>): String {
|
fun runLldb(program: Path, commands: List<String>): String {
|
||||||
val args = listOf("-b", "-o", "command script import \"$lldbPrettyPrinters\"") +
|
val args = listOf("-b", "-o", "command script import \"${DistProperties.lldbPrettyPrinters}\"") +
|
||||||
commands.flatMap { listOf("-o", it) }
|
commands.flatMap { listOf("-o", it) }
|
||||||
return subprocess(lldb, program.toString(), "-b", *args.toTypedArray())
|
return subprocess(DistProperties.lldb, program.toString(), "-b", *args.toTypedArray())
|
||||||
.thrownIfFailed()
|
.thrownIfFailed()
|
||||||
.stdout
|
.stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
fun runDwarfDump(program: Path, processor:List<DwarfTag>.()->Unit) {
|
fun runDwarfDump(program: Path, processor:List<DwarfTag>.()->Unit) {
|
||||||
val out = subprocess(dwarfDump, "${program}.dSYM/Contents/Resources/DWARF/${program.fileName}").takeIf { it.process.exitValue() == 0 }?.stdout ?: error("${program}.dSYM/Contents/Resources/DWARF/${program.fileName}")
|
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}")
|
||||||
DwarfUtilParser().parse(StringReader(out)).tags.toList().processor()
|
DwarfUtilParser().parse(StringReader(out)).tags.toList().processor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-6
@@ -78,7 +78,7 @@ fun lldbTest(@Language("kotlin") programText: String, lldbSession: String) {
|
|||||||
val source = tmpdir.resolve("main.kt")
|
val source = tmpdir.resolve("main.kt")
|
||||||
val output = tmpdir.resolve("program.kexe")
|
val output = tmpdir.resolve("program.kexe")
|
||||||
|
|
||||||
val driver = ToolDriver(DistProperties.konanc, DistProperties.lldb, DistProperties.dwarfDump, DistProperties.lldbPrettyPrinters)
|
val driver = ToolDriver()
|
||||||
Files.write(source, programText.trimIndent().toByteArray())
|
Files.write(source, programText.trimIndent().toByteArray())
|
||||||
driver.compile(source, output, "-g")
|
driver.compile(source, output, "-g")
|
||||||
val result = driver.runLldb(output, lldbSessionSpec.commands)
|
val result = driver.runLldb(output, lldbSessionSpec.commands)
|
||||||
@@ -106,11 +106,7 @@ fun dwarfDumpTest(@Language("kotlin") programText: String, flags: List<String>,
|
|||||||
val source = resolve("main.kt")
|
val source = resolve("main.kt")
|
||||||
val output = resolve("program.kexe")
|
val output = resolve("program.kexe")
|
||||||
|
|
||||||
val driver = ToolDriver(
|
val driver = ToolDriver()
|
||||||
DistProperties.konanc,
|
|
||||||
DistProperties.lldb,
|
|
||||||
DistProperties.dwarfDump,
|
|
||||||
DistProperties.lldbPrettyPrinters)
|
|
||||||
Files.write(source, programText.trimIndent().toByteArray())
|
Files.write(source, programText.trimIndent().toByteArray())
|
||||||
driver.compile(source, output, "-g", *flags.toTypedArray())
|
driver.compile(source, output, "-g", *flags.toTypedArray())
|
||||||
driver.runDwarfDump(output, test)
|
driver.runDwarfDump(output, test)
|
||||||
|
|||||||
Reference in New Issue
Block a user