Commit e3f219c0 authored by Lukas Sommer's avatar Lukas Sommer

Parse port information from report file written during evaluation;

parent 0464ed0b
AXI_MASTER_PORTS 42
AXI_SLAVE_PORTS 25
......@@ -2,11 +2,42 @@ package de.tu_darmstadt.cs.esa.tapasco.reports
import java.nio.file.Path
final case class PortReport(override val file : Path, numSlaves : Int) extends Report(file)
import de.tu_darmstadt.cs.esa.tapasco.util.SequenceMatcher
import scala.io.Source
final case class PortReport(override val file : Path, numMasters : Int, numSlaves : Int) extends Report(file)
object PortReport {
private[this] val logger = de.tu_darmstadt.cs.esa.tapasco.Logging.logger(this.getClass)
def apply(pr : Path) : Option[PortReport] = extract(pr)
private def masterPortMatcher : SequenceMatcher[Int] = new SequenceMatcher[Int](
"""AXI_MASTER_PORTS\s+(\d+)""".r
)(true, ms => ms.head.group(1).toInt)
private def slavePortMatcher : SequenceMatcher[Int] = new SequenceMatcher[Int](
"""AXI_SLAVE_PORTS\s+(\d+)""".r
)(true, ms => ms.head.group(1).toInt)
def apply(pr : Path) : Option[PortReport] = Some(PortReport(pr, 42))
// TODO Actually parse report after it was filled by the TCL script.
private def extract(pr : Path) : Option[PortReport] = try {
val numMasters = masterPortMatcher
val numSlaves = slavePortMatcher
val source = Source.fromFile(pr.toString)
source.getLines foreach { line =>
numMasters.update(line)
numSlaves.update(line)
}
if(numMasters.matched && numSlaves.matched){
Some(PortReport(pr, numMasters.result.get, numSlaves.result.get))
}
else {
None
}
} catch { case e : Exception =>
logger.warn("Could not extract port information from %s: %s".format(pr, e))
None
}
}
package de.tu_darmstadt.cs.esa.tapasco.reports
import java.nio.file.Paths
import org.scalatest.{FlatSpec, Matchers}
class PortReportSpec extends FlatSpec with Matchers {
val reportPath = Paths.get("report-examples").toAbsolutePath
"A missing PortReport file" should "result in None" in {
PortReport(reportPath.resolve("missing.rpt")) shouldBe empty
}
"An invalid PortReport file" should "result in None" in {
PortReport(reportPath.resolve("correct-timing.rpt")) shouldBe empty
}
"A correct PortReport file" should "be parsed to Some(PortReport)" in {
PortReport(reportPath.resolve("correct-port.rpt")) should not be empty
}
"A correct PortReport file" should "be parsed correctly" in {
val pr = PortReport(reportPath.resolve("correct-port.rpt"))
pr should not be empty
pr.get.numMasters shouldBe 42
pr.get.numSlaves shouldBe 25
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment