ExperimentTest.kt 4.18 KB
Newer Older
1
import org.junit.FixMethodOrder
Noric Couderc's avatar
Noric Couderc committed
2
3
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
4
5
6
import org.junit.runners.MethodSorters
import papi.Constants
import papi.EventSet
Noric Couderc's avatar
Noric Couderc committed
7
8
import se.lth.cs.bcgen.BCBenchmarkPackage
import se.lth.cs.papicounters.PAPICounter
9
import se.lth.cs.papicounters.PapiTracerRunner
10
import se.lth.cs.smartmodules.tracer.Tracer
Noric Couderc's avatar
Noric Couderc committed
11
12
import se.lth.cs.timing.OperationType
import se.lth.cs.util.*
13
import java.util.stream.Collectors
Noric Couderc's avatar
Noric Couderc committed
14

15
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
16
class ExperimentTest {
Noric Couderc's avatar
Noric Couderc committed
17

18
    val runner = PapiTracerRunner()
19

Noric Couderc's avatar
Noric Couderc committed
20
21
22
23
    @Test
    fun testExperimentNoFeatures() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

24
        val exp = Experiment(10, bench, FeatureSet(), runner)
Noric Couderc's avatar
Noric Couderc committed
25

26
        val results = exp.run().collect(Collectors.toList())
Noric Couderc's avatar
Noric Couderc committed
27
28
29
30
31
32
33
        Assertions.assertTrue(results.isEmpty())
    }

    @Test
    fun testExperiment1() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())
        val exp = Experiment(10, bench,
34
            FeatureSet(PAPICounter("PAPI_TOT_CYC")),
35
            runner
Noric Couderc's avatar
Noric Couderc committed
36
37
        )

38
        val results = exp.run().collect(Collectors.toList())
39

Noric Couderc's avatar
Noric Couderc committed
40
        Assertions.assertEquals(10, results.size)
Noric Couderc's avatar
Noric Couderc committed
41
42
43
44
        Assertions.assertEquals(
            IntRange(0, 9).toList(),
            results.map { it.iterationNumber }
        )
45
        Assertions.assertTrue(results.all { it.values[PAPICounter("PAPI_TOT_CYC")]!! > 0.0 })
Noric Couderc's avatar
Noric Couderc committed
46
        Assertions.assertEquals(setOf(PAPICounter("PAPI_TOT_CYC")),
Noric Couderc's avatar
Noric Couderc committed
47
            results.flatMap{ it.values.keys }.toSet())
Noric Couderc's avatar
Noric Couderc committed
48
49
50
51
52
53
54
55
56
57
58
59
60
    }

    @Test
    fun testExperiment2() {
        // This time, with more complicated features

        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

        val cacheMissRate = FeatureRatio(
            PAPICounter("PAPI_L2_DCM"),
            PAPICounter("PAPI_L2_DCA")
        )

61
        val costPerDelete = CostFeature(OperationType.DELETE)
Noric Couderc's avatar
Noric Couderc committed
62
63
64

        val exp = Experiment(10, bench,
            FeatureSet(
65
66
67
                PAPICounter("PAPI_TOT_INS"),
                costPerDelete,
                cacheMissRate
68
69
            ),
            runner
Noric Couderc's avatar
Noric Couderc committed
70
        )
71
        val results = exp.run()
Noric Couderc's avatar
Noric Couderc committed
72
73

        for (iteration in results) {
Noric Couderc's avatar
Noric Couderc committed
74
75
76
77
78
79
            Assertions.assertTrue(iteration.values.containsKey(PAPICounter("PAPI_TOT_INS")))
            Assertions.assertTrue(iteration.values.containsKey(costPerDelete))
            Assertions.assertTrue(iteration.values.containsKey(costPerDelete.counter))
            Assertions.assertTrue(iteration.values.containsKey(cacheMissRate))
            Assertions.assertTrue(iteration.values.containsKey(cacheMissRate.f1))
            Assertions.assertTrue(iteration.values.containsKey(cacheMissRate.f2))
Noric Couderc's avatar
Noric Couderc committed
80
81
82
        }
    }

83
    // @Disabled("PAPI_L1_DCA was not available on my machine, so it wouldn't work")
Noric Couderc's avatar
Noric Couderc committed
84
85
86
87
    @Test
    fun testExperimentBrainyFeatures() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

Noric Couderc's avatar
Noric Couderc committed
88
        val features = brainyFeatures().checked()
89
        val exp = Experiment(10, bench, features,runner)
Noric Couderc's avatar
Noric Couderc committed
90

91
        val results = exp.run()
92

93
94
95
96
97
98
        // Fails for some reason. I don't understand why
        // Throws an exception with number -8
        val eventSet = EventSet.create(Constants.PAPI_TOT_CYC)
        eventSet.start()
        eventSet.stop()

99
100
101
102
        for (iteration in results) {
            Assertions.assertEquals(bench, iteration.benchmark)
            Assertions.assertTrue(iteration.values.values.all { it > 0 })
        }
Noric Couderc's avatar
Noric Couderc committed
103
    }
104

105
106
107
108
109
110
    @Test
    fun cacheSizeFeatures() {
        val f = cacheLineSizeFeature()
        Assertions.assertFalse(f == null)
    }

111
112
113
114
    @Test
    fun testNormalizationBrainyFeatures() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

115
        val features = normalize(brainyFeatures()).checked()
116
117
118
119
120
121
122

        val exp = Experiment(10, bench, features,runner)

        val results = exp.run()

        for (iteration in results) {
            Assertions.assertEquals(bench, iteration.benchmark)
123
            Assertions.assertTrue(features.containsAll(iteration.strict().values.keys))
124
            Assertions.assertTrue(iteration.values.values.all { it > 0 })
125
            Assertions.assertTrue(iteration.strict().values.values.all { it <= 1.0 })
126
127
        }
    }
128
}