Commit f3e781c4 authored by Noric Couderc's avatar Noric Couderc

Implemented test for serialization / deserialization of benchmarks

The test writes benchmarks to memory and then reads them
parent b4f65ff8
import org.junit.Assert
import org.junit.Test
import se.lth.cs.TraceLoader
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.ObjectOutputStream
import java.io.StringReader
import java.util.stream.Collectors
......@@ -158,4 +161,35 @@ class TraceLoaderTest {
app.methodHistogram().toSortedMap().toString())
}
}
@Test
fun testSerializeDeserialize() {
val text = ",id,location,target_type,method,step\n" +
// Same id, different location
"1,1,loc1,java.util.ArrayList,boolean add(E),1\n" +
"1,1,loc1,java.util.ArrayList,boolean add(E),2\n" +
"1,1,loc2,java.util.ArrayList,boolean add(E),1\n" +
"1,1,loc2,java.util.ArrayList,boolean add(E),2\n"
val reader = StringReader(text)
val apps = TraceLoader().readCsv(reader, false)
// We serialize the data to memory...
val inMemoryBinaryStream = ByteArrayOutputStream()
val objectOutputStream = ObjectOutputStream(inMemoryBinaryStream)
objectOutputStream.writeObject(apps.collect(Collectors.toList()))
val apps2 = TraceLoader().deserialize(
ByteArrayInputStream(inMemoryBinaryStream.toByteArray()))
// We check our data
val expectedHist = sortedMapOf(
Pair("runAdd",2)
)
for (app in apps2) {
// Equality between sortedMaps does not work?
Assert.assertEquals(expectedHist.toString(),
app.methodHistogram().toSortedMap().toString())
}
}
}
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