ExperimentTest.kt 3.87 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
import se.lth.cs.timing.OperationType
import se.lth.cs.util.*
10
import java.util.stream.Collectors
Noric Couderc's avatar
Noric Couderc committed
11

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

14
15
    val runner = MockupPapiTracerRunner()

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

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

22
        val results = exp.run().collect(Collectors.toList())
Noric Couderc's avatar
Noric Couderc committed
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,
30
            FeatureSet(PAPICounter("PAPI_TOT_CYC")),
31
            runner
Noric Couderc's avatar
Noric Couderc committed
32
33
        )

34
        val results = exp.run().collect(Collectors.toList())
35

Noric Couderc's avatar
Noric Couderc committed
36
        Assertions.assertEquals(10, results.size)
Noric Couderc's avatar
Noric Couderc committed
37
38
39
40
        Assertions.assertEquals(
            IntRange(0, 9).toList(),
            results.map { it.iterationNumber }
        )
41
        Assertions.assertTrue(results.all { it.values[PAPICounter("PAPI_TOT_CYC")] == 100000.0 })
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
    }

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

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

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

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

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

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

87
        val results = exp.run()
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
    @Test
    fun cacheSizeFeatures() {
        val f = cacheLineSizeFeature()
        Assertions.assertFalse(f == null)
    }

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

105
        val features = normalize(brainyFeatures()).checked()
106
107
108
109
110
111
112

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

        val results = exp.run()

        for (iteration in results) {
            Assertions.assertEquals(bench, iteration.benchmark)
113
            Assertions.assertTrue(features.containsAll(iteration.strict().values.keys))
114
            Assertions.assertTrue(iteration.values.values.all { it > 0 })
115
            Assertions.assertTrue(iteration.strict().values.values.all { it <= 1.0 })
116
117
        }
    }
118
}