PapiEventTest.kt 1.49 KB
Newer Older
Noric Couderc's avatar
Noric Couderc committed
1
2
3
4
5
6
7
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import papi.Constants
import papi.EventSet
import papi.Papi
import papi.PapiException

Noric Couderc's avatar
Noric Couderc committed
8
class PapiEventTest {
Noric Couderc's avatar
Noric Couderc committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
    @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()
    }
Noric Couderc's avatar
Noric Couderc committed
66
}