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

9
class ExperimentTest {
Noric Couderc's avatar
Noric Couderc committed
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

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

        val exp = Experiment(10, bench, FeatureSet(listOf()))

        val results = exp.run(listOf())
        Assertions.assertTrue(results.isEmpty())
    }

    @Test
    fun testExperiment1() {
        val available = listOf(PAPICounter("PAPI_TOT_CYC"),
            PAPICounter("PAPI_TOT_INS")
        )

        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())
        val exp = Experiment(10, bench,
            FeatureSet(
                listOf(PAPICounter("PAPI_TOT_CYC"))
            )
        )

        val results = exp.run(available)
        Assertions.assertEquals(10, results.size)
        Assertions.assertEquals(setOf(PAPICounter("PAPI_TOT_CYC")),
            results.flatMap{ it.keys }.toSet())
    }

    @Test
    fun testExperiment2() {
        // This time, with more complicated features
        val available = listOf(
            PAPICounter("PAPI_L2_DCM"),
            PAPICounter("PAPI_L2_DCA"),
            PAPICounter("PAPI_TOT_CYC"),
            PAPICounter("PAPI_TOT_INS")
        )

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

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

        val costPerDelete = CostFeature(
                OperationType.DELETE,
                PAPICounter("PAPI_TOT_CYC"))

        val exp = Experiment(10, bench,
            FeatureSet(
                listOf(
                    PAPICounter("PAPI_TOT_INS"),
                    costPerDelete,
                    cacheMissRate
                )
            )
        )
        val results = exp.run(available)

        for (iteration in results) {
            Assertions.assertTrue(iteration.containsKey(PAPICounter("PAPI_TOT_INS")))
            Assertions.assertTrue(iteration.containsKey(costPerDelete))
            Assertions.assertTrue(iteration.containsKey(costPerDelete.counter))
            Assertions.assertTrue(iteration.containsKey(cacheMissRate))
            Assertions.assertTrue(iteration.containsKey(cacheMissRate.f1))
            Assertions.assertTrue(iteration.containsKey(cacheMissRate.f2))
        }
    }

    @Disabled("PAPI_L1_DCA was not available on my machine, so it wouldn't work")
    @Test
    fun testExperimentBrainyFeatures() {
        val available = listOf(
            PAPICounter("PAPI_L1_DCM"),
            PAPICounter("PAPI_L1_DCA"),
            PAPICounter("PAPI_BR_CN"),
            PAPICounter("PAPI_L2_DCM"),
            PAPICounter("PAPI_BR_MSP"),
            PAPICounter("PAPI_L2_DCA"),
            PAPICounter("PAPI_TOT_CYC"),
            PAPICounter("PAPI_TOT_INS")
        )

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

        val exp = Experiment(10, bench, brainyFeatures())

        val results = exp.run(available)
        Assertions.assertEquals(listOf<Map<Feature, Double>>(), results)
    }
103
}