ExperimentTest.kt 2.73 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

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

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

17
        val results = exp.run()
Noric Couderc's avatar
Noric Couderc committed
18
19
20
21
22
23
24
25
26
27
28
29
        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"))
            )
        )

30
31
        val results = exp.run()

Noric Couderc's avatar
Noric Couderc committed
32
        Assertions.assertEquals(10, results.size)
Noric Couderc's avatar
Noric Couderc committed
33
34
35
36
        Assertions.assertEquals(
            IntRange(0, 9).toList(),
            results.map { it.iterationNumber }
        )
Noric Couderc's avatar
Noric Couderc committed
37
        Assertions.assertEquals(setOf(PAPICounter("PAPI_TOT_CYC")),
Noric Couderc's avatar
Noric Couderc committed
38
            results.flatMap{ it.values.keys }.toSet())
Noric Couderc's avatar
Noric Couderc committed
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
    }

    @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
                )
            )
        )
65
        val results = exp.run()
Noric Couderc's avatar
Noric Couderc committed
66
67

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

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

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

84
        val results = exp.run()
Noric Couderc's avatar
Noric Couderc committed
85
86
        Assertions.assertEquals(listOf<Map<Feature, Double>>(), results)
    }
87
}