blob: bedc0b2267af0ef89e68a919f8b30856e15a2af2 [file] [log] [blame]
Javi Merinoaace7c02015-08-10 14:10:47 +01001# Copyright 2015-2015 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 Merino7f3c8a62014-06-13 11:38:58 +010016
17import unittest
Javi Merino8e8e3212014-06-26 15:24:34 +010018import matplotlib
19import pandas as pd
Javi Merino7f3c8a62014-06-13 11:38:58 +010020
Javi Merino076277d2014-07-02 18:48:18 +010021from test_thermal import BaseTestThermal
Javi Merino435457c2015-08-10 15:59:10 +010022import trappy
Javi Merino7f3c8a62014-06-13 11:38:58 +010023import plot_utils
24
25class TestPlotUtils(unittest.TestCase):
Javi Merino7f3c8a62014-06-13 11:38:58 +010026 def test_normalize_title(self):
27 """Test normalize_title"""
28 self.assertEquals(plot_utils.normalize_title("Foo", ""), "Foo")
29 self.assertEquals(plot_utils.normalize_title("Foo", "Bar"), "Bar - Foo")
Javi Merino3a736552014-06-19 19:22:44 +010030
Javi Merinoa1561272014-06-21 17:49:02 +010031 def test_set_lim(self):
32 """Test set_lim()"""
33
34 class GetSet(object):
35 def __init__(self):
36 self.min = 1
37 self.max = 2
38
39 def get(self):
40 return (self.min, self.max)
41
42 def set(self, minimum, maximum):
43 self.min = minimum
44 self.max = maximum
45
46 gs = GetSet()
47
48 plot_utils.set_lim("default", gs.get, gs.set)
49 self.assertEquals(gs.min, 1)
50 self.assertEquals(gs.max, 2)
51
52 plot_utils.set_lim("range", gs.get, gs.set)
53 self.assertEquals(gs.min, 0.9)
54 self.assertEquals(gs.max, 2.1)
55
56 plot_utils.set_lim((0, 100), gs.get, gs.set)
57 self.assertEquals(gs.min, 0)
58 self.assertEquals(gs.max, 100)
59
60 def test_set_ylim(self):
61 """Test that set_ylim() doesn't bomb"""
62
Javi Merino5981ee82014-08-11 17:45:38 +010063 _, ax = matplotlib.pyplot.subplots()
Javi Merinoa1561272014-06-21 17:49:02 +010064
65 plot_utils.set_ylim(ax, "default")
66 plot_utils.set_ylim(ax, (0, 5))
67
68 def test_set_xlim(self):
69 """Test that set_xlim() doesn't bomb"""
70
Javi Merino5981ee82014-08-11 17:45:38 +010071 _, ax = matplotlib.pyplot.subplots()
Javi Merinoa1561272014-06-21 17:49:02 +010072
73 plot_utils.set_xlim(ax, "default")
74 plot_utils.set_xlim(ax, (0, 5))
75
Javi Merinof9ac5782014-06-21 19:02:50 +010076 def test_pre_plot_setup(self):
77 """Test that plot_utils.pre_plot_setup() doesn't bomb"""
78 plot_utils.pre_plot_setup(None, None)
79 plot_utils.pre_plot_setup(height=9, width=None)
80 plot_utils.pre_plot_setup(height=None, width=9)
81 plot_utils.pre_plot_setup(3, 9)
82
Javi Merino7f88ae32014-08-11 16:53:35 +010083 axis = plot_utils.pre_plot_setup(ncols=2)
84 self.assertEquals(len(axis), 2)
85
Javi Merino270caac2014-08-12 10:41:38 +010086 axis = plot_utils.pre_plot_setup(nrows=2, ncols=3)
87 self.assertEquals(len(axis), 2)
88 self.assertEquals(len(axis[0]), 3)
89 self.assertEquals(len(axis[1]), 3)
90
Javi Merino3a736552014-06-19 19:22:44 +010091 def test_post_plot_setup(self):
92 """Test that post_plot_setup() doesn't bomb"""
93
Javi Merino5981ee82014-08-11 17:45:38 +010094 _, ax = matplotlib.pyplot.subplots()
Javi Merino3a736552014-06-19 19:22:44 +010095
96 plot_utils.post_plot_setup(ax)
97 plot_utils.post_plot_setup(ax, title="Foo")
98 plot_utils.post_plot_setup(ax, ylim=(0, 72))
Javi Merinoa1561272014-06-21 17:49:02 +010099 plot_utils.post_plot_setup(ax, ylim="range")
Javi Merinof9d43af2014-06-21 16:32:04 +0100100 plot_utils.post_plot_setup(ax, xlabel="Bar")
Javi Merinod04643f2014-06-21 17:00:16 +0100101 plot_utils.post_plot_setup(ax, xlim=(0, 100))
Javi Merinoa1561272014-06-21 17:49:02 +0100102 plot_utils.post_plot_setup(ax, xlim="default")
Javi Merino6a5c88d2014-06-19 09:43:18 +0100103
Javi Merinoed977c12014-06-25 17:46:17 +0100104 def test_plot_hist(self):
105 """Test that plost_hist doesn't bomb"""
106 data = pd.Series([1, 1, 2, 4])
107
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100108 _, ax = matplotlib.pyplot.subplots()
Javi Merino23dff5d2015-03-09 19:05:46 +0000109 plot_utils.plot_hist(data, ax, "Foo", "m", 20, "numbers", (0, 4), "default")
Javi Merinoed977c12014-06-25 17:46:17 +0100110
Javi Merino076277d2014-07-02 18:48:18 +0100111class TestPlotUtilsNeedTrace(BaseTestThermal):
Javi Merino6bf48832014-08-11 17:15:35 +0100112 def __init__(self, *args, **kwargs):
113 super(TestPlotUtilsNeedTrace, self).__init__(*args, **kwargs)
Javi Merinod721b272015-04-20 15:37:53 +0100114 self.map_label = {"00000000,00000039": "A53", "00000000,00000006": "A57"}
115 self.actor_order = ["GPU", "A57", "A53"]
Javi Merino6bf48832014-08-11 17:15:35 +0100116
Javi Merino9d9c9b82015-04-29 11:15:11 +0100117 def test_number_freq_plots(self):
118 """Calculate the number of frequency plots correctly"""
119 trace_out = ""
120
Javi Merino435457c2015-08-10 15:59:10 +0100121 run = trappy.Run()
Javi Merino9d9c9b82015-04-29 11:15:11 +0100122 self.assertEquals(plot_utils.number_freq_plots([run], self.map_label),
123 3)
124
125 # Strip out devfreq traces
126 with open("trace.txt") as fin:
127 for line in fin:
128 if ("thermal_power_devfreq_get_power:" not in line) and \
129 ("thermal_power_devfreq_limit:" not in line):
130 trace_out += line
131
132 with open("trace.txt", "w") as fout:
133 fout.write(trace_out)
134
135 # Without devfreq there should only be two plots
Javi Merino435457c2015-08-10 15:59:10 +0100136 run = trappy.Run()
Javi Merino9d9c9b82015-04-29 11:15:11 +0100137 self.assertEquals(plot_utils.number_freq_plots([run], self.map_label),
138 2)
139
Javi Merino2919e8d2014-06-26 15:16:05 +0100140 def test_plot_temperature(self):
141 """Test that plot_utils.plot_temperature() doesn't bomb"""
142
Javi Merino435457c2015-08-10 15:59:10 +0100143 run1 = trappy.Run(name="first")
144 run2 = trappy.Run(name="second")
Javi Merino1cc4bfc2014-08-11 16:29:11 +0100145 runs = [run1, run2]
Javi Merino2919e8d2014-06-26 15:16:05 +0100146
Javi Merino1cc4bfc2014-08-11 16:29:11 +0100147 plot_utils.plot_temperature(runs, ylim="default")
Javi Merino8e8e3212014-06-26 15:24:34 +0100148 matplotlib.pyplot.close('all')
Javi Merino6bf48832014-08-11 17:15:35 +0100149
150 def test_plot_load(self):
151 """Test that plot_utils.plot_load() doesn't bomb"""
152
Javi Merino435457c2015-08-10 15:59:10 +0100153 run1 = trappy.Run(name="first")
154 run2 = trappy.Run(name="second")
Javi Merino6bf48832014-08-11 17:15:35 +0100155 runs = [run1, run2]
156
157 plot_utils.plot_load(runs, self.map_label, height=5)
158 matplotlib.pyplot.close('all')
Javi Merinoaf05f312014-08-11 17:47:59 +0100159
160 def test_plot_load_single_run(self):
161 """plot_utils.plot_load() can be used with a single run"""
Javi Merino435457c2015-08-10 15:59:10 +0100162 run = trappy.Run()
Javi Merinoaf05f312014-08-11 17:47:59 +0100163
164 plot_utils.plot_load([run], self.map_label)
165 matplotlib.pyplot.close('all')
Javi Merino0c484262014-08-12 11:55:04 +0100166
167 def test_plot_allfreqs(self):
168 """Test that plot_utils.plot_allfreqs() doesn't bomb"""
169
Javi Merino435457c2015-08-10 15:59:10 +0100170 run1 = trappy.Run(name="first")
171 run2 = trappy.Run(name="second")
Javi Merino0c484262014-08-12 11:55:04 +0100172 runs = [run1, run2]
173
174 plot_utils.plot_allfreqs(runs, self.map_label, width=20)
175 matplotlib.pyplot.close('all')
176
Javi Merino114c9cb2014-08-12 14:47:09 +0100177 def test_plot_allfreqs_single_run(self):
178 """plot_utils.plot_allfreqs() can be used with a single run"""
Javi Merino435457c2015-08-10 15:59:10 +0100179 run = trappy.Run()
Javi Merino114c9cb2014-08-12 14:47:09 +0100180
181 plot_utils.plot_allfreqs([run], self.map_label)
Javi Merino0c484262014-08-12 11:55:04 +0100182 matplotlib.pyplot.close('all')
Javi Merino38fd12d2014-08-12 15:02:47 +0100183
184 def test_plot_controller(self):
185 """plot_utils.plot_controller() doesn't bomb"""
186
Javi Merino435457c2015-08-10 15:59:10 +0100187 run1 = trappy.Run(name="first")
188 run2 = trappy.Run(name="second")
Javi Merino38fd12d2014-08-12 15:02:47 +0100189 runs = [run1, run2]
190
191 plot_utils.plot_controller(runs, height=5)
192 matplotlib.pyplot.close('all')
Javi Merinof5cd04b2014-08-12 15:26:22 +0100193
194 def test_plot_input_power(self):
195 """plot_utils.plot_input_power() doesn't bomb"""
196
Javi Merino435457c2015-08-10 15:59:10 +0100197 run1 = trappy.Run(name="first")
198 run2 = trappy.Run(name="second")
Javi Merinof5cd04b2014-08-12 15:26:22 +0100199 runs = [run1, run2]
200
201 plot_utils.plot_input_power(runs, self.actor_order, width=20)
202 matplotlib.pyplot.close('all')
Javi Merino9fde2152014-08-12 15:34:24 +0100203
204 def test_plot_output_power(self):
205 """plot_utils.plot_output_power() doesn't bomb"""
206
Javi Merino435457c2015-08-10 15:59:10 +0100207 run1 = trappy.Run(name="first")
208 run2 = trappy.Run(name="second")
Javi Merino9fde2152014-08-12 15:34:24 +0100209 runs = [run1, run2]
210
211 plot_utils.plot_output_power(runs, self.actor_order, width=20)
212 matplotlib.pyplot.close('all')
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100213
214 def test_plot_freq_hists(self):
215 """plot_utils.plot_freq_hists() doesn't bomb"""
216
Javi Merino435457c2015-08-10 15:59:10 +0100217 run1 = trappy.Run(name="first")
218 run2 = trappy.Run(name="second")
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100219 runs = [run1, run2]
220
221 plot_utils.plot_freq_hists(runs, self.map_label)
222 matplotlib.pyplot.close('all')
223
224 def test_plot_freq_hists_single_run(self):
225 """plot_utils.plot_freq_hists() works with a single run"""
226
Javi Merino435457c2015-08-10 15:59:10 +0100227 run = trappy.Run()
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100228
229 plot_utils.plot_freq_hists([run], self.map_label)
230 matplotlib.pyplot.close('all')
231
232 def test_plot_temperature_hist(self):
233 """plot_utils.plot_temperature_hist() doesn't bomb"""
234
Javi Merino435457c2015-08-10 15:59:10 +0100235 run1 = trappy.Run(name="first")
236 run2 = trappy.Run(name="second")
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100237 runs = [run1, run2]
238
239 plot_utils.plot_temperature_hist(runs)
240 matplotlib.pyplot.close('all')