EventSetBuilderTest.kt 2.74 KB
Newer Older
1
2
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeAll
Noric Couderc's avatar
Noric Couderc committed
3
import org.junit.jupiter.api.Disabled
4
5
6
7
8
import org.junit.jupiter.api.Test
import se.lth.cs.CounterSpecification
import se.lth.cs.papicounters.PAPICounter
import se.lth.cs.timing.OperationType
import se.lth.cs.util.CostFeature
9
import se.lth.cs.papicounters.EventSetBuilder
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
import se.lth.cs.util.FeatureRatio
import se.lth.cs.util.FeatureSet
import java.io.File
import java.lang.RuntimeException

class EventSetBuilderTest {

    companion object {

        var availableCounters : MutableList<PAPICounter> = mutableListOf()

        @BeforeAll
        @JvmStatic
        fun readAvailableCounters() {
            CounterSpecification.fromFile(File("../papi_avail")).currentSpec.forEach {
                availableCounters.add(PAPICounter(it.key))
            }
        }
    }


    @Test
    fun testEventBuilder() {
        val counters = listOf(
            PAPICounter("PAPI_TOT_CYC"),
            PAPICounter("PAPI_L1_DCM")
        )

38
        val spec = FeatureSet(*counters.toTypedArray())
39

40
        val builder = EventSetBuilder(spec)
41
42
43
44
45
46
47

        Assertions.assertEquals(counters.toSet(), builder.getCounterSet())
    }

    @Test
    fun testEventBuilderCost() {
        val features = listOf(
48
            CostFeature(OperationType.INSERT),
49
            PAPICounter("PAPI_L1_DCM")
50
        ).toTypedArray()
51

52
        val spec = FeatureSet(*features)
53

54
        val builder = EventSetBuilder(spec)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

        val expected = setOf(
            PAPICounter("PAPI_TOT_CYC"), // For Costs!
            PAPICounter("PAPI_L1_DCM")
        )

        // For some reason, regular equality didn't work.
        Assertions.assertEquals(expected.toString(),
            builder.getCounterSet().toString())
    }

    @Test
    fun testEventBuildRatio() {
        val features = listOf(
            FeatureRatio(
                PAPICounter("PAPI_L2_DCM"),
                PAPICounter("PAPI_L2_DCA")
            ),
            FeatureRatio(
74
75
                CostFeature(OperationType.INSERT),
                CostFeature(OperationType.DELETE)
76
            )
77
        ).toTypedArray()
78

79
        val spec = FeatureSet(*features)
80

81
        val builder = EventSetBuilder(spec)
82
83
84
85
86
87
88
89
90
91

        val expected = listOf(
            PAPICounter("PAPI_L2_DCM"),
            PAPICounter("PAPI_L2_DCA"),
            PAPICounter("PAPI_TOT_CYC")
        )

        Assertions.assertEquals(expected.toSet(), builder.getCounterSet())
    }

92
    // @Disabled("PAPI_L1_DCA is not available on the machine")
93
94
    @Test
    fun testEventBuildInvalidEvents() {
95
        val spec = FeatureSet()
96
        // Oh no! empty list of PAPI events!
97
        val builder = EventSetBuilder(spec)
98
        Assertions.assertThrows(RuntimeException::class.java) { spec.accept(builder) }
99
100
    }
}