ExperimentTest.kt 2.93 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(listOf()), 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
29
30
        Assertions.assertTrue(results.isEmpty())
    }

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

35
36
        val results = exp.run()

Noric Couderc's avatar
Noric Couderc committed
37
        Assertions.assertEquals(10, results.size)
Noric Couderc's avatar
Noric Couderc committed
38
39
40
41
        Assertions.assertEquals(
            IntRange(0, 9).toList(),
            results.map { it.iterationNumber }
        )
Noric Couderc's avatar
Noric Couderc committed
42
        Assertions.assertEquals(setOf(PAPICounter("PAPI_TOT_CYC")),
Noric Couderc's avatar
Noric Couderc committed
43
            results.flatMap{ it.values.keys }.toSet())
Noric Couderc's avatar
Noric Couderc committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    }

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

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

        val exp = Experiment(10, bench,
            FeatureSet(
                listOf(
                    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
84
85
86
87
        }
    }

    @Disabled("PAPI_L1_DCA was not available on my machine, so it wouldn't work")
    @Test
    fun testExperimentBrainyFeatures() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

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

90
        val results = exp.run()
Noric Couderc's avatar
Noric Couderc committed
91
92
        Assertions.assertEquals(listOf<Map<Feature, Double>>(), results)
    }
93
}