Commit c43c83b0 authored by Noric Couderc's avatar Noric Couderc
Browse files

Implemented mockup class to use in tests

Since we'd like to check the counters work in a deterministic way, we
use a mockup class for getting the counters.
parent 608ae8dc
......@@ -81,7 +81,7 @@ open class PapiRunner(private val numRuns: Int, counters: CounterSpecification)
return specification.toList()
}
fun runSpec(spec : RunSpec): List<Long> {
open fun runSpec(spec : RunSpec): List<Long> {
// println("Running benchmark: " + spec.syntheticBenchmark.benchmarkIdentifier)
val writer = FileWriter("/dev/null")
val samples = mutableListOf<Long>()
......
......@@ -17,12 +17,38 @@ import java.lang.NumberFormatException
import java.nio.file.Paths
class SyntheticBenchmarkFeaturePrinterTest {
val counterSpec = CounterSpecification.fromFile(File("../papi_avail"))
val runner = PapiRunner( 10, counterSpec)
val specString = """
PAPI_L1_DCM
PAPI_CA_ITV
PAPI_TOT_CYC
PAPI_TOT_INS
""".trimIndent()
val specReader = StringReader(specString)
val counterSpec = CounterSpecification.fromReader(specReader)
val methodOutputFormat = "JAVA-STANDARD-FORMAT"
val normalizeFeatures = false
/**
* A mockup class which returns deterministic results when you "run" a spec.
*/
class MockupPapiRunner(numRuns : Int, counters : CounterSpecification) : PapiRunner(numRuns, counters) {
override fun runSpec(spec : RunSpec) : List<Long> {
val seed = spec.syntheticBenchmark.seed
// We map the counters to integers
val counterToInt = mapOf<String, Long>(
Pair("PAPI_CA_ITV", 0),
Pair("PAPI_L1_DCM", 1),
Pair("PAPI_TOT_CYC", 2),
Pair("PAPI_TOT_INS", 3)
)
val n = seed + counterToInt[spec.counter]!!
return listOf(n, n, n)
}
}
val runner = MockupPapiRunner( 10, counterSpec)
@Test
fun testEmptyBenchmark() {
val benchmark =
......@@ -41,6 +67,7 @@ class SyntheticBenchmarkFeaturePrinterTest {
/**
* Checks equality between two sets of records, based on strings.
*/
@Deprecated("We use the deterministic mockup now, so string equality should be ok.")
fun checkEquality(expectedString : String, actualString : String) {
val parser = CSVParser(StringReader(expectedString), CSVFormat.DEFAULT.withHeader())
val parser2 = CSVParser(StringReader(actualString), CSVFormat.DEFAULT.withHeader())
......@@ -86,35 +113,27 @@ class SyntheticBenchmarkFeaturePrinterTest {
csvPrinter.printToCSV(listOf<BCBenchmarkPackage<*>>(benchmark))
val expectedBeginning =
"benchmark_id,feature,feature_type,value\n" +
"Synth:POLYA:0:10:Map:0:HashMap,collection,collection,HashMap\n" +
"Synth:POLYA:0:10:Map:0:HashMap,runContainsValue,software,2\n" +
"Synth:POLYA:0:10:Map:0:HashMap,runClear,software,1\n" +
"Synth:POLYA:0:10:Map:0:HashMap,runPut,software,3\n" +
"Synth:POLYA:0:10:Map:0:HashMap,runRemove2,software,1\n" +
"Synth:POLYA:0:10:Map:0:HashMap,runKeySet,software,1\n" +
"Synth:POLYA:0:10:Map:0:HashMap,runSize,software,1\n" +
"Synth:POLYA:0:10:Map:0:HashMap,runContainsKey,software,1"
val actualBeginning = writer.toString()
checkEquality(expectedBeginning, actualBeginning)
Assertions.assertEquals(
expectedBeginning.lines().filter { it.contains("software")},
actualBeginning.lines().filter { it.contains("software")} )
Assertions.assertEquals(
expectedBeginning.lines().filter { it.contains("collection")},
actualBeginning.lines().filter { it.contains("collection")} )
val expectedCounters =
runner.counterSpec.currentSpec.keys
Assertions.assertTrue(
expectedCounters.all { it -> writer.toString().contains(it) }
)
val expectedText = """
benchmark_id,feature,feature_type,value
Synth:POLYA:0:10:Map:0:HashMap,collection,collection,HashMap
Synth:POLYA:0:10:Map:0:HashMap,runContainsValue,software,2
Synth:POLYA:0:10:Map:0:HashMap,runClear,software,1
Synth:POLYA:0:10:Map:0:HashMap,runPut,software,3
Synth:POLYA:0:10:Map:0:HashMap,runRemove2,software,1
Synth:POLYA:0:10:Map:0:HashMap,runKeySet,software,1
Synth:POLYA:0:10:Map:0:HashMap,runSize,software,1
Synth:POLYA:0:10:Map:0:HashMap,runContainsKey,software,1
Synth:POLYA:0:10:Map:0:HashMap,PAPI_CA_ITV,hardware,0.0
Synth:POLYA:0:10:Map:0:HashMap,PAPI_L1_DCM,hardware,1.0
Synth:POLYA:0:10:Map:0:HashMap,PAPI_TOT_CYC,hardware,2.0
Synth:POLYA:0:10:Map:0:HashMap,PAPI_TOT_INS,hardware,3.0
""".trimIndent()
val actualText = writer.toString()
Assertions.assertEquals(expectedText, actualText)
}
@Test
......
Supports Markdown
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