Commit 30e34099 authored by Noric Couderc's avatar Noric Couderc
Browse files

Added tests for depencencies

We test the libraries that we use work as we expect them.

I guess these tests might probably be in the dependencies repos
themselves but I just don't know how to do that.
parent 1a6e9485
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import papi.Constants
import papi.EventSet
import papi.Papi
import papi.PapiException
class PapiEventTest { class PapiEventTest {
@Test
fun papiEventTest() {
Papi.init()
val eventSet = EventSet.create(Constants.PAPI_TOT_CYC)
eventSet.start()
val results = eventSet.stop()
Assertions.assertTrue(results.all { it > 0 })
}
@Test
fun papiEventSetReset() {
Papi.init()
val eventSet = EventSet.create(Constants.PAPI_TOT_CYC)
eventSet.start()
val results = eventSet.stop()!!
Assertions.assertTrue(results.all { it > 0 })
eventSet.reset()
val results2 = LongArray(results.size)
eventSet.read(results2)
Assertions.assertTrue(results2.all { it == 0L })
}
@Test
fun papiEventResetLimit() {
Papi.init()
for (i in 1 until 100) {
val eventSet = EventSet.create(Constants.PAPI_TOT_CYC)
eventSet.reset()
eventSet.start()
eventSet.stop()
}
}
@Test
fun papiDoubleStart() {
Papi.init()
val eventSet = EventSet.create(Constants.PAPI_TOT_CYC)
eventSet.start()
val eventSet2 = EventSet.create(Constants.PAPI_TOT_CYC)
Assertions.assertThrows(PapiException::class.java) {
eventSet2.start()
}
// Don't forget to stop the events!
eventSet.stop()
eventSet2.stop()
}
} }
\ No newline at end of file
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import papi.Papi
import se.lth.cs.smartmodules.tracer.Tracer
import se.lth.util.ArrayListTracer
import java.io.ByteArrayOutputStream
import java.io.PrintStream
// Test the Tracer class because I don't understand what it does.
class TracerTest { class TracerTest {
@Test
fun testTraceOnce() {
Papi.init()
Tracer.reset()
val coll = ArrayListTracer<Int>("NO LOCATION")
coll.add(1)
coll.add(2)
val stream = ByteArrayOutputStream()
Tracer.printRecords(0, PrintStream(stream))
// We don't want just the header, we want data!
Assertions.assertNotEquals(1, stream.toString().lines().size)
}
@Test
fun testTraceTwice() {
Papi.init()
Tracer.reset()
val coll = ArrayListTracer<Int>("NO LOCATION")
coll.add(1)
coll.add(2)
val stream = ByteArrayOutputStream()
Tracer.printRecords(0, PrintStream(stream))
// It's necessary to call reset on the tracer before tracing again.
Tracer.reset()
val coll2 = ArrayListTracer<Int>("NO LOCATION 2")
coll2.add(1)
coll2.add(1)
coll2.add(32)
coll2.add(32)
Tracer.printRecords(0, PrintStream(stream))
println(stream)
}
} }
\ 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