blob: e375dafa0087f0dc79fe696ece800d5b5659b2b6 [file] [log] [blame]
Brendan Jackmane81fdcb2017-01-04 17:10:29 +00001# Copyright 2015-2017 ARM Limited
Javi Merino034e7cc2015-04-22 18:39:21 +01002#
Javi Merinoaace7c02015-08-10 14:10:47 +01003# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
Javi Merino67958b12014-04-10 16:22:13 +010016
17import os, sys
Javi Merinoda493aa2014-07-10 15:47:12 +010018import shutil
Javi Merino67958b12014-04-10 16:22:13 +010019import tempfile
Javi Merino39452692014-06-21 19:01:13 +010020import matplotlib
Javi Merinob78ff492014-04-14 15:22:12 +010021import pandas as pd
Javi Merino67958b12014-04-10 16:22:13 +010022
23import utils_tests
Javi Merino435457c2015-08-10 15:59:10 +010024sys.path.append(os.path.join(utils_tests.TESTS_DIRECTORY, "..", "trappy"))
25from trappy.wa import Result, get_results, combine_results
Javi Merino67958b12014-04-10 16:22:13 +010026
27class TestResults(utils_tests.SetupDirectory):
28 def __init__(self, *args, **kwargs):
29 super(TestResults, self).__init__(
Javi Merino0d38cb82014-12-16 15:04:31 +000030 [("results.csv", "results.csv")],
Javi Merino67958b12014-04-10 16:22:13 +010031 *args, **kwargs)
32
33 def test_get_results(self):
Javi Merinofcd50a22015-06-12 11:20:53 +010034 results_frame = get_results()
Javi Merino67958b12014-04-10 16:22:13 +010035
Javi Merinofcd50a22015-06-12 11:20:53 +010036 self.assertEquals(type(results_frame), Result)
Javi Merino187ca0f2014-10-24 15:15:57 +010037 self.assertEquals(type(results_frame.columns), pd.core.index.MultiIndex)
38 self.assertEquals(results_frame["antutu"]["power_allocator"][0], 5)
39 self.assertEquals(results_frame["antutu"]["step_wise"][1], 9)
40 self.assertEquals(results_frame["antutu"]["step_wise"][2], 7)
41 self.assertEquals(results_frame["t-rex_offscreen"]["power_allocator"][0], 1777)
42 self.assertEquals(results_frame["geekbench"]["step_wise"][0], 8)
43 self.assertEquals(results_frame["geekbench"]["power_allocator"][1], 1)
Javi Merinoc95712b2014-10-24 17:07:38 +010044 self.assertAlmostEquals(results_frame["thechase"]["step_wise"][0], 242.0522258138)
Javi Merino67958b12014-04-10 16:22:13 +010045
46 def test_get_results_path(self):
Javi Merinofcd50a22015-06-12 11:20:53 +010047 """get_results() can be given a directory for the results.csv"""
Javi Merino67958b12014-04-10 16:22:13 +010048
49 other_random_dir = tempfile.mkdtemp()
50 os.chdir(other_random_dir)
51
Javi Merinofcd50a22015-06-12 11:20:53 +010052 results_frame = get_results(self.out_dir)
Javi Merino67958b12014-04-10 16:22:13 +010053
Javi Merinoc95712b2014-10-24 17:07:38 +010054 self.assertEquals(len(results_frame.columns), 10)
Javi Merinoda493aa2014-07-10 15:47:12 +010055
Punit Agrawal8fcb7d12015-06-02 11:18:38 +010056 def test_get_results_filename(self):
Javi Merinofcd50a22015-06-12 11:20:53 +010057 """get_results() can be given a specific filename"""
Punit Agrawal8fcb7d12015-06-02 11:18:38 +010058
59 old_path = os.path.join(self.out_dir, "results.csv")
60 new_path = os.path.join(self.out_dir, "new_results.csv")
61 os.rename(old_path, new_path)
62
Javi Merinofcd50a22015-06-12 11:20:53 +010063 results_frame = get_results(new_path)
Punit Agrawal8fcb7d12015-06-02 11:18:38 +010064
65 self.assertEquals(len(results_frame.columns), 10)
66
Javi Merinoc52d43d2015-06-12 11:40:20 +010067 def test_get_results_name(self):
68 """get_results() optional name argument overrides the one in the results file"""
69 res = get_results(name="malkovich")
Javi Merino977ac372014-10-25 12:02:37 +010070 self.assertIsNotNone(res["antutu"]["malkovich"])
71
Javi Merino67958b12014-04-10 16:22:13 +010072 def test_combine_results(self):
Javi Merinofcd50a22015-06-12 11:20:53 +010073 res1 = get_results()
74 res2 = get_results()
Javi Merino67958b12014-04-10 16:22:13 +010075
Javi Merino187ca0f2014-10-24 15:15:57 +010076 # First split them
77 res1.drop('step_wise', axis=1, level=1, inplace=True)
78 res2.drop('power_allocator', axis=1, level=1, inplace=True)
79
80 # Now combine them again
Javi Merinofcd50a22015-06-12 11:20:53 +010081 combined = combine_results([res1, res2])
Javi Merino67958b12014-04-10 16:22:13 +010082
Javi Merinofcd50a22015-06-12 11:20:53 +010083 self.assertEquals(type(combined), Result)
Javi Merino187ca0f2014-10-24 15:15:57 +010084 self.assertEquals(combined["antutu"]["step_wise"][0], 4)
85 self.assertEquals(combined["antutu"]["power_allocator"][0], 5)
86 self.assertEquals(combined["geekbench"]["power_allocator"][1], 1)
87 self.assertEquals(combined["t-rex_offscreen"]["step_wise"][2], 424)
Javi Merino67958b12014-04-10 16:22:13 +010088
89 def test_plot_results_benchmark(self):
Javi Merinofcd50a22015-06-12 11:20:53 +010090 """Test Result.plot_results_benchmark()
Javi Merino67958b12014-04-10 16:22:13 +010091
92 Can't test it, so just check that it doens't bomb
93 """
Javi Merino67958b12014-04-10 16:22:13 +010094
Javi Merinofcd50a22015-06-12 11:20:53 +010095 res = get_results()
Javi Merinob78ff492014-04-14 15:22:12 +010096
Javi Merino187ca0f2014-10-24 15:15:57 +010097 res.plot_results_benchmark("antutu")
98 res.plot_results_benchmark("t-rex_offscreen", title="Glbench TRex")
Javi Merinob78ff492014-04-14 15:22:12 +010099
Javi Merino39452692014-06-21 19:01:13 +0100100 (_, _, y_min, y_max) = matplotlib.pyplot.axis()
Javi Merinob78ff492014-04-14 15:22:12 +0100101
Javi Merino187ca0f2014-10-24 15:15:57 +0100102 trex_data = pd.concat(res["t-rex_offscreen"][s] for s in res["t-rex_offscreen"])
103 data_min = min(trex_data)
104 data_max = max(trex_data)
Javi Merinob78ff492014-04-14 15:22:12 +0100105
106 # Fail if the axes are within the limits of the data.
107 self.assertTrue(data_min > y_min)
108 self.assertTrue(data_max < y_max)
Javi Merino39452692014-06-21 19:01:13 +0100109 matplotlib.pyplot.close('all')
Javi Merino67958b12014-04-10 16:22:13 +0100110
111 def test_get_run_number(self):
Javi Merino435457c2015-08-10 15:59:10 +0100112 from trappy.wa.results import get_run_number
Javi Merinofcd50a22015-06-12 11:20:53 +0100113
114 self.assertEquals(get_run_number("score_2"), (True, 2))
115 self.assertEquals(get_run_number("score"), (True, 0))
116 self.assertEquals(get_run_number("score 3"), (True, 3))
117 self.assertEquals(get_run_number("FPS_1"), (True, 1))
118 self.assertEquals(get_run_number("Overall_Score"), (True, 0))
119 self.assertEquals(get_run_number("Overall_Score_2"), (True, 1))
120 self.assertEquals(get_run_number("Memory_score")[0], False)
Javi Merino67958b12014-04-10 16:22:13 +0100121
122 def test_plot_results(self):
Javi Merinofcd50a22015-06-12 11:20:53 +0100123 """Test Result.plot_results()
Javi Merino67958b12014-04-10 16:22:13 +0100124
125 Can't test it, so just check that it doens't bomb
126 """
127
Javi Merinofcd50a22015-06-12 11:20:53 +0100128 res = get_results()
Javi Merino67958b12014-04-10 16:22:13 +0100129
Javi Merino187ca0f2014-10-24 15:15:57 +0100130 res.plot_results()
Javi Merino39452692014-06-21 19:01:13 +0100131 matplotlib.pyplot.close('all')
Javi Merinob78ff492014-04-14 15:22:12 +0100132
133 def test_init_fig(self):
Javi Merinofcd50a22015-06-12 11:20:53 +0100134 r1 = get_results()
Javi Merinob78ff492014-04-14 15:22:12 +0100135 r1.init_fig()