Commit 90550a07 authored by Noric Couderc's avatar Noric Couderc
Browse files

Added test to check benchmark is only ran once / iteration.

We add some fields to BCBenchmarkPackage and a test to make sure we
don't run a benchmark more than 1 time per iteration.
parent bdd29671
......@@ -33,7 +33,9 @@ public class BCBenchmarkPackage<T> implements Serializable {
protected int trace_size;
protected int datastructure_size;
public MethodSelectionType getMethodSelectionType() {
public int numberRuns = 0;
public MethodSelectionType getMethodSelectionType() {
return method_selection_type;
}
......@@ -314,6 +316,8 @@ public class BCBenchmarkPackage<T> implements Serializable {
public void
reset(int size) {
numberRuns = 0;
for (BCBenchStep step : this.bench_steps) {
step.reset();
}
......@@ -337,6 +341,8 @@ public class BCBenchmarkPackage<T> implements Serializable {
* Must be run after a reset (which should not be included in the timing!)
*/
public void runBenchmark(Blackhole blackhole) {
numberRuns++;
assert(dataStructureSizeIsCorrect());
for (BCBenchStep step : this.bench_steps) {
step.runBenchmark(blackhole);
......
......@@ -87,9 +87,6 @@ open class PapiRunner(val numRuns: Int, counters: CounterSpecification) : PapiBe
evset.stop()
val resultDataStructure = app.getDatastructure()
// We reset the benchmark
app.reset(0)
// Write the result somewhere to prevent dead code elimination
writer.write(accumulator)
writer.write(resultDataStructure.toString())
......
import kotlin.Triple;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import papi.EventSet;
import papi.Papi;
import papi.PapiException;
......@@ -14,8 +15,6 @@ import se.lth.cs.papicounters.PapiBenchmarkAnalyzer;
import java.io.File;
import java.util.*;
import java.util.function.IntPredicate;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
......@@ -172,4 +171,16 @@ public class PapiRunnerTest {
Assertions.assertEquals(runner.getNumRuns(), r.getNumRuns());
}
}
@ParameterizedTest(name = "Test we only run each benchmark once per iteration (seed = {0})")
@ValueSource(ints = {10, 20, 30, 40, 50, 60, 70, 80, 90 })
public void testRunBenchOnce(int seed) {
BCBenchmarkPackage<List<Object>> bench = BCBenchmarkPackage.LIST(seed, 100, 0, new ArrayList<>());
List<PapiBenchmarkAnalyzer.BenchmarkRunData> results = runner.runApplications(listOf(bench));
for (PapiBenchmarkAnalyzer.BenchmarkRunData r : results) {
Assertions.assertEquals(1, r.getBenchmark().numberRuns);
}
}
}
......@@ -192,4 +192,16 @@ class TracingCollectionRunnerTest {
Assertions.assertEquals(expectedCounters, cycles.flatMap { it.keys }.toSet())
}
@ParameterizedTest(name = "Test we only run the benchmark once when getting the counters (seed = {0})")
@ValueSource(ints = [100, 101, 102, 103, 104, 105, 106])
fun testBenchmarkRunsOnce(seed : Long) {
val bench = BCBenchmarkPackage.SET(seed, 100, 0, HashSet<Int>())
val results = runner!!.runApplications(listOf(bench))
for (r in results) {
Assertions.assertEquals(1, r.benchmark.numberRuns)
}
}
}
\ No newline at end of file
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