aboutsummaryrefslogtreecommitdiff
path: root/tests/test_results.py
blob: d56cd39f44f6f114e73d18e4f5056f56638578e9 (plain)
1
2
3
4
5
6
7
8
9
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
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python

import os, sys
import shutil
import tempfile
import matplotlib
import pandas as pd

import utils_tests
sys.path.append(os.path.join(utils_tests.TESTS_DIRECTORY, "..", "cr2"))
import results

class TestResults(utils_tests.SetupDirectory):
    def __init__(self, *args, **kwargs):
        super(TestResults, self).__init__(
            ["results.csv", "new_antutu_results.csv"],
            *args, **kwargs)

    def test_get_results(self):
        results_frame = results.get_results()

        self.assertEquals(type(results_frame), results.CR2)
        self.assertEquals(len(results_frame.columns), 3)
        self.assertEquals(results_frame["antutu"][0], 2)
        self.assertEquals(results_frame["antutu"][1], 6)
        self.assertEquals(results_frame["antutu"][2], 3)
        self.assertEquals(results_frame["glbench_trex"][0], 740)
        self.assertEquals(results_frame["geekbench"][0], 3)
        self.assertEquals(results_frame["geekbench"][1], 4)

    def test_get_results_path(self):
        """results.get_results() can be given a directory for the results.csv"""

        other_random_dir = tempfile.mkdtemp()
        os.chdir(other_random_dir)

        results_frame = results.get_results(self.out_dir)

        self.assertEquals(len(results_frame.columns), 3)

    def test_get_results_new_antutu(self):
        """Test that the new antutu results are correctly parsed"""
        shutil.move("new_antutu_results.csv", "results.csv")
        results_frame = results.get_results()

        self.assertEquals(results_frame["antutu"][0], 35549)
        self.assertEquals(results_frame["antutu"][1], 35437)

    def test_combine_results(self):
        res1 = results.get_results()
        res2 = results.get_results()

        res2["antutu"][0] = 42
        combined = results.combine_results([res1, res2], keys=["power_allocator", "ipa"])

        self.assertEquals(type(combined), results.CR2)
        self.assertEquals(combined["antutu"]["power_allocator"][0], 2)
        self.assertEquals(combined["antutu"]["ipa"][0], 42)
        self.assertEquals(combined["geekbench"]["power_allocator"][1], 4)
        self.assertEquals(combined["glbench_trex"]["ipa"][2], 920)

    def test_plot_results_benchmark(self):
        """Test CR2.plot_results_benchmark()

        Can't test it, so just check that it doens't bomb
        """

        r1 = results.get_results()
        r2 = results.get_results()
        r2["glbench_trex"].loc[1] = 28
        r2["glbench_trex"].loc[2] = 28
        combined = results.combine_results([r1, r2], ["r1", "r2"])

        combined.plot_results_benchmark("antutu")
        combined.plot_results_benchmark("glbench_trex", title="Glbench TRex")

        (_, _, y_min, y_max) = matplotlib.pyplot.axis()

        concat_data = pd.concat(combined["glbench_trex"][s] for s in combined["glbench_trex"])
        data_min = min(concat_data)
        data_max = max(concat_data)

        # Fail if the axes are within the limits of the data.
        self.assertTrue(data_min > y_min)
        self.assertTrue(data_max < y_max)
        matplotlib.pyplot.close('all')

    def test_get_run_number(self):
        self.assertEquals(results.get_run_number("score_2"), (True, 2))
        self.assertEquals(results.get_run_number("score"), (True, 0))
        self.assertEquals(results.get_run_number("score 3"), (True, 3))
        self.assertEquals(results.get_run_number("FPS_1"), (True, 1))
        self.assertEquals(results.get_run_number("Overall_Score"), (True, 0))
        self.assertEquals(results.get_run_number("Overall_Score_2"), (True, 1))
        self.assertEquals(results.get_run_number("Memory_score")[0], False)

    def test_plot_results(self):
        """Test CR2.plot_results()

        Can't test it, so just check that it doens't bomb
        """

        r1 = results.get_results()
        r2 = results.get_results()
        combined = results.combine_results([r1, r2], ["r1", "r2"])

        combined.plot_results()
        matplotlib.pyplot.close('all')

    def test_init_fig(self):
        r1 = results.get_results()
        r1.init_fig()