Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ailrst committed Dec 10, 2024
1 parent a890ebb commit 0ea390c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/util/PerformanceTimer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ case class PerformanceTimer(timerName: String = "") {
val delta = elapsed()
lastCheckpoint = System.currentTimeMillis()
checkpoints.append((name, s"${file.value}:${line.value}", delta))
Logger.info(s"PerformanceTimer $timerName [$name]: ${delta}ms")
Logger.debug(s"PerformanceTimer $timerName [$name]: ${delta}ms")
delta
}
private def elapsed() : Long = {
Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/DataStructureAnalysisTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ir.*
import org.scalatest.funsuite.AnyFunSuite
import ir.dsl.*
import specification.{Specification, SpecGlobal}
import util.{BASILConfig, BASILResult, BoogieGeneratorConfig, ILLoadingConfig, IRContext, RunUtils, StaticAnalysisConfig, StaticAnalysisContext, writeToFile}
import util.{BASILConfig, BASILResult, BoogieGeneratorConfig, ILLoadingConfig, IRContext, RunUtils, StaticAnalysisConfig, StaticAnalysisContext, writeToFile, Logger, LogLevel}

/**
* This is the test suite for testing DSA functionality
Expand All @@ -20,6 +20,7 @@ import util.{BASILConfig, BASILResult, BoogieGeneratorConfig, ILLoadingConfig, I
class DataStructureAnalysisTest extends AnyFunSuite {

def runAnalysis(program: Program): StaticAnalysisContext = {
Logger.setLevel(LogLevel.WARN)
cilvisitor.visit_prog(transforms.ReplaceReturns(), program)
transforms.addReturnBlocks(program)
cilvisitor.visit_prog(transforms.ConvertSingleReturn(), program)
Expand Down
8 changes: 5 additions & 3 deletions src/test/scala/IndirectCallTests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ir.{Block, Command, DirectCall, GoTo, Procedure, Program, Statement}
import org.scalatest.funsuite.*
import util.{BASILConfig, BASILResult, BoogieGeneratorConfig, ILLoadingConfig, LogLevel, Logger, PerformanceTimer, RunUtils, StaticAnalysisConfig}
import util.{BASILConfig, BASILResult, BoogieGeneratorConfig, ILLoadingConfig, LogLevel, Logger, PerformanceTimer, RunUtils, StaticAnalysisConfig, MemoryRegionsMode}

import scala.collection.mutable.ArrayBuffer
import test_util.BASILTest
Expand Down Expand Up @@ -43,7 +43,9 @@ class IndirectCallTests extends AnyFunSuite, BASILTest {
val testSuffix = if conf.useBAPFrontend then ":BAP" else ":GTIRB"

Logger.debug(s"$name/$variation$testSuffix")
val basilResult = runBASIL(inputPath, RELFPath, Some(specPath), BPLPath, Some(StaticAnalysisConfig()))
val basilResult = runBASIL(inputPath, RELFPath, Some(specPath), BPLPath, Some(StaticAnalysisConfig(
memoryRegions = MemoryRegionsMode.MRA,
)))
Logger.debug(s"$name/$variation$testSuffix DONE")

val boogieResult = runBoogie(directoryPath, BPLPath, conf.boogieFlags)
Expand Down Expand Up @@ -416,4 +418,4 @@ class IndirectCallTests extends AnyFunSuite, BASILTest {
runTest("switch2", "clang", GTIRBConfig, resolvedCalls)
}

}
}
6 changes: 4 additions & 2 deletions src/test/scala/PointsToTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ir.Endian.LittleEndian
import org.scalatest.*
import org.scalatest.funsuite.*
import specification.*
import util.{RunUtils, StaticAnalysisConfig, StaticAnalysis, StaticAnalysisContext, IRContext}
import util.{RunUtils, StaticAnalysisConfig, StaticAnalysis, StaticAnalysisContext, IRContext, MemoryRegionsMode}

import java.io.IOException
import java.nio.file.*
Expand All @@ -20,7 +20,9 @@ class PointsToTest extends AnyFunSuite with OneInstancePerTest {
globalOffsets: Map[BigInt, BigInt] = Map.empty): StaticAnalysisContext = {

val ctx = IRContext(List.empty, externalFunctions, globals, funcEntries, globalOffsets, Specification(Set(), Set(), Map(), List(), List(), List(), Set()), program)
StaticAnalysis.analyse(ctx, StaticAnalysisConfig(), 1)
StaticAnalysis.analyse(ctx, StaticAnalysisConfig(
memoryRegions = MemoryRegionsMode.MRA,
), 1)
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/test/scala/SystemTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ class DSAMemoryRegionSystemTestsGTIRB extends SystemTests {
runTests("incorrect", TestConfig(staticAnalysisConfig = Some(StaticAnalysisConfig(memoryRegions = MemoryRegionsMode.DSA)), useBAPFrontend = false, expectVerify = false))
}

class MRAMemoryRegionSystemTestsBAP extends SystemTests {
runTests("correct", TestConfig(staticAnalysisConfig = Some(StaticAnalysisConfig(memoryRegions = MemoryRegionsMode.MRA)), useBAPFrontend = true, expectVerify = true))
runTests("incorrect", TestConfig(staticAnalysisConfig = Some(StaticAnalysisConfig(memoryRegions = MemoryRegionsMode.MRA)), useBAPFrontend = true, expectVerify = false))
}

class MRAMemoryRegionSystemTestsGTIRB extends SystemTests {
runTests("correct", TestConfig(staticAnalysisConfig = Some(StaticAnalysisConfig(memoryRegions = MemoryRegionsMode.MRA)), useBAPFrontend = false, expectVerify = true))
runTests("incorrect", TestConfig(staticAnalysisConfig = Some(StaticAnalysisConfig(memoryRegions = MemoryRegionsMode.MRA)), useBAPFrontend = false, expectVerify = false))
}

class MemoryRegionTestsDSA extends SystemTests {
// stack_pointer currently times out because Boogie is bad at handling abstract map accesses
runTests("memory_regions", TestConfig(staticAnalysisConfig = Some(StaticAnalysisConfig(memoryRegions = MemoryRegionsMode.DSA)), useBAPFrontend = true, expectVerify = true))
Expand All @@ -245,4 +255,4 @@ class ProcedureSummaryTests extends SystemTests {
class UnimplementedTests extends SystemTests {
runTests("unimplemented", TestConfig(useBAPFrontend = false, expectVerify = true))
runTests("unimplemented", TestConfig(useBAPFrontend = true, expectVerify = false))
}
}
4 changes: 2 additions & 2 deletions src/test/scala/TimeStaticAnalysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ExecutionContext.Implicits.global
import ir.cilvisitor.*
import scala.sys.process.*

val ANALYSE_TIMEOUT: Duration = 60000.millis
val ANALYSE_TIMEOUT: Duration = 240000.millis

class TimeStaticAnalysis extends AnyFunSuite {

Expand Down Expand Up @@ -115,7 +115,7 @@ class TimeStaticAnalysis extends AnyFunSuite {
}
}
// give up after \timeout_thresh consecutive timeouts
val timeout_thresh = 3
val timeout_thresh = 1
var timeouts = 0
val result: List[(String, ProgStats, List[(String, String, Long)])] = sorted
.map(v => {
Expand Down
1 change: 0 additions & 1 deletion src/test/scala/ir/InterpreterTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import util.ILLoadingConfig
class InterpreterTests extends AnyFunSuite with BeforeAndAfter {

var i: Interpreter = Interpreter()
Logger.setLevel(LogLevel.DEBUG)

def getProgram(name: String): (Program, Set[SpecGlobal]) = {

Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/test_util/BASILTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package test_util

import org.scalatest.funsuite.AnyFunSuite
import ir.{Block, Procedure, Program}
import util.{BASILConfig, BASILResult, BoogieGeneratorConfig, ILLoadingConfig, Logger, RunUtils, StaticAnalysisConfig}
import util.{BASILConfig, BASILResult, BoogieGeneratorConfig, ILLoadingConfig, Logger, RunUtils, StaticAnalysisConfig, LogLevel}

import scala.sys.process.*
import scala.io.Source
Expand All @@ -18,6 +18,7 @@ case class TestConfig(boogieFlags: Seq[String] = Seq("/timeLimit:10", "/useArray

trait BASILTest {
def runBASIL(inputPath: String, RELFPath: String, specPath: Option[String], BPLPath: String, staticAnalysisConf: Option[StaticAnalysisConfig]): BASILResult = {
Logger.setLevel(LogLevel.WARN)
val specFile = if (specPath.isDefined && File(specPath.get).exists) {
specPath
} else {
Expand Down

0 comments on commit 0ea390c

Please sign in to comment.