ExperimentTest.kt 3.71 KB
Newer Older
Noric Couderc's avatar
Noric Couderc committed
1
2
3
4
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import se.lth.cs.bcgen.BCBenchmarkPackage
5
import se.lth.cs.papicounters.MockupPapiTracerRunner
Noric Couderc's avatar
Noric Couderc committed
6
import se.lth.cs.papicounters.PAPICounter
7
import se.lth.cs.papicounters.PapiTracerRunner
Noric Couderc's avatar
Noric Couderc committed
8
9
10
import se.lth.cs.timing.OperationType
import se.lth.cs.util.*

11
class ExperimentTest {
Noric Couderc's avatar
Noric Couderc committed
12

13
14
    val runner = MockupPapiTracerRunner()

Noric Couderc's avatar
Noric Couderc committed
15
16
17
18
    @Test
    fun testExperimentNoFeatures() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

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

21
        val results = exp.run()
Noric Couderc's avatar
Noric Couderc committed
22
23
24
25
26
27
28
        Assertions.assertTrue(results.isEmpty())
    }

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

33
34
        val results = exp.run()

Noric Couderc's avatar
Noric Couderc committed
35
        Assertions.assertEquals(10, results.size)
Noric Couderc's avatar
Noric Couderc committed
36
37
38
39
        Assertions.assertEquals(
            IntRange(0, 9).toList(),
            results.map { it.iterationNumber }
        )
40
        Assertions.assertTrue(results.all { it.values[PAPICounter("PAPI_TOT_CYC")] == 100000.0 })
Noric Couderc's avatar
Noric Couderc committed
41
        Assertions.assertEquals(setOf(PAPICounter("PAPI_TOT_CYC")),
Noric Couderc's avatar
Noric Couderc committed
42
            results.flatMap{ it.values.keys }.toSet())
Noric Couderc's avatar
Noric Couderc committed
43
44
45
46
47
48
49
50
51
52
53
54
55
    }

    @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")
        )

56
        val costPerDelete = CostFeature(OperationType.DELETE)
Noric Couderc's avatar
Noric Couderc committed
57
58
59

        val exp = Experiment(10, bench,
            FeatureSet(
60
61
62
                PAPICounter("PAPI_TOT_INS"),
                costPerDelete,
                cacheMissRate
63
64
            ),
            runner
Noric Couderc's avatar
Noric Couderc committed
65
        )
66
        val results = exp.run()
Noric Couderc's avatar
Noric Couderc committed
67
68

        for (iteration in results) {
Noric Couderc's avatar
Noric Couderc committed
69
70
71
72
73
74
            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
75
76
77
        }
    }

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

83
84
        val features = brainyFeatures()
        val exp = Experiment(10, bench, features,runner)
Noric Couderc's avatar
Noric Couderc committed
85

86
        val results = exp.run()
87
88
89
90
91
92


        for (iteration in results) {
            Assertions.assertEquals(bench, iteration.benchmark)
            Assertions.assertTrue(iteration.values.values.all { it > 0 })
        }
Noric Couderc's avatar
Noric Couderc committed
93
    }
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

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

        val features = normalize(brainyFeatures())

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

        val results = exp.run()

        for (iteration in results) {
            Assertions.assertEquals(bench, iteration.benchmark)
            Assertions.assertTrue(iteration.values.values.all { it > 0 })
            val normalizedFeatures = iteration.values.keys.filterIsInstance<NormalizedFeature>()
            for (f in normalizedFeatures) {
                val value = iteration.values[f]!!
                Assertions.assertTrue(value <= 1.0)
            }
        }
    }
115
}