Commit 1b179423 authored by Noric Couderc's avatar Noric Couderc

Added test for synthetic benchmark runs

Theres a test for running a benchmark based on a trace
and one from trace benchmarks loaded from a CSV data
parent 51a04972
......@@ -2,12 +2,17 @@ import org.junit.Assert;
import org.junit.Test;
import se.lth.cs.SyntheticBenchmarkGeneration.ListSyntheticBenchmarkGenerator;
import se.lth.cs.SyntheticBenchmarkRunner;
import se.lth.cs.TraceLoader;
import se.lth.cs.TrainingSetValue;
import se.lth.cs.bcgen.BCBenchmarkPackage;
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SyntheticBenchmarkRunnerTest {
@Test
......@@ -24,4 +29,48 @@ public class SyntheticBenchmarkRunnerTest {
Assert.assertEquals(3, histogram.keySet().size());
Assert.assertTrue( histogram.values().stream().min(Long::compareTo).orElse(0l) >= threshold);
}
@Test
public void testRunningTrace() throws InvocationTargetException, IllegalAccessException {
List<String> commands = new ArrayList<>();
commands.add("runAdd");
commands.add("runAdd");
commands.add("runAdd");
commands.add("runAdd");
commands.add("runAdd");
// We would like to generate one benchmark for each collection that we
// know of, and give them all to the benchmarks
BCBenchmarkPackage<List<Object>> benchmark = BCBenchmarkPackage.LIST(
"Trace1", commands, new ArrayList<>());
SyntheticBenchmarkRunner runner = new SyntheticBenchmarkRunner();
List<TrainingSetValue> results = runner.runBenchmarks(List.of(benchmark));
TrainingSetValue v = results.get(0);
Assert.assertTrue(v.getAverage() > 0);
// Sanity check
Assert.assertTrue(Math.sqrt(v.getVariance()) < v.getAverage());
}
@Test
public void testBenchmarkTraceLoaded() throws IllegalAccessException, InstantiationException, ClassNotFoundException {
TraceLoader tl = new TraceLoader();
String text = ",id,location,target_type,method,step\n" +
// Same id, different location
"1,1,loc1,java.util.LinkedList,boolean add(E),1\n" +
"2,1,loc1,java.util.LinkedList,boolean add(E),2\n" +
"3,2,loc2,java.util.ArrayList,boolean add(E),1\n" +
"4,2,loc2,java.util.ArrayList,boolean add(E),2\n" +
"5,3,loc3,java.util.HashSet,boolean add(E),1\n" +
"6,3,loc3,java.util.HashSet,boolean add(E),2\n";
Stream<BCBenchmarkPackage<?>> benchmarks = tl.readCsv(
new StringReader(text), false);
SyntheticBenchmarkRunner runner = new SyntheticBenchmarkRunner();
List<TrainingSetValue> results = runner.runBenchmarks(benchmarks.collect(Collectors.toList()));
Assert.assertEquals(3, results.size());
Assert.assertEquals("java.util.LinkedList", results.get(0).getBestDataStructure());
Assert.assertEquals("java.util.ArrayList", results.get(1).getBestDataStructure());
Assert.assertEquals("java.util.HashSet", results.get(2).getBestDataStructure());
}
}
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