blob: 1f87bb13da37e7a90e228be7e9bd641b502bc8aa [file] [log] [blame]
Javi Merino034e7cc2015-04-22 18:39:21 +01001# $Copyright:
2# ----------------------------------------------------------------
3# This confidential and proprietary software may be used only as
4# authorised by a licensing agreement from ARM Limited
5# (C) COPYRIGHT 2015 ARM Limited
6# ALL RIGHTS RESERVED
7# The entire notice above must be reproduced on all authorised
8# copies and copies may only be made to the extent permitted
9# by a licensing agreement from ARM Limited.
10# ----------------------------------------------------------------
11# File: test_plot_utils.py
12# ----------------------------------------------------------------
13# $
14#
Javi Merino7f3c8a62014-06-13 11:38:58 +010015
16import unittest
Javi Merino8e8e3212014-06-26 15:24:34 +010017import matplotlib
18import pandas as pd
Javi Merino7f3c8a62014-06-13 11:38:58 +010019
Javi Merino076277d2014-07-02 18:48:18 +010020from test_thermal import BaseTestThermal
Javi Merino6a5c88d2014-06-19 09:43:18 +010021import cr2
Javi Merino7f3c8a62014-06-13 11:38:58 +010022import plot_utils
23
24class TestPlotUtils(unittest.TestCase):
Javi Merino7f3c8a62014-06-13 11:38:58 +010025 def test_normalize_title(self):
26 """Test normalize_title"""
27 self.assertEquals(plot_utils.normalize_title("Foo", ""), "Foo")
28 self.assertEquals(plot_utils.normalize_title("Foo", "Bar"), "Bar - Foo")
Javi Merino3a736552014-06-19 19:22:44 +010029
Javi Merinoa1561272014-06-21 17:49:02 +010030 def test_set_lim(self):
31 """Test set_lim()"""
32
33 class GetSet(object):
34 def __init__(self):
35 self.min = 1
36 self.max = 2
37
38 def get(self):
39 return (self.min, self.max)
40
41 def set(self, minimum, maximum):
42 self.min = minimum
43 self.max = maximum
44
45 gs = GetSet()
46
47 plot_utils.set_lim("default", gs.get, gs.set)
48 self.assertEquals(gs.min, 1)
49 self.assertEquals(gs.max, 2)
50
51 plot_utils.set_lim("range", gs.get, gs.set)
52 self.assertEquals(gs.min, 0.9)
53 self.assertEquals(gs.max, 2.1)
54
55 plot_utils.set_lim((0, 100), gs.get, gs.set)
56 self.assertEquals(gs.min, 0)
57 self.assertEquals(gs.max, 100)
58
59 def test_set_ylim(self):
60 """Test that set_ylim() doesn't bomb"""
61
Javi Merino5981ee82014-08-11 17:45:38 +010062 _, ax = matplotlib.pyplot.subplots()
Javi Merinoa1561272014-06-21 17:49:02 +010063
64 plot_utils.set_ylim(ax, "default")
65 plot_utils.set_ylim(ax, (0, 5))
66
67 def test_set_xlim(self):
68 """Test that set_xlim() doesn't bomb"""
69
Javi Merino5981ee82014-08-11 17:45:38 +010070 _, ax = matplotlib.pyplot.subplots()
Javi Merinoa1561272014-06-21 17:49:02 +010071
72 plot_utils.set_xlim(ax, "default")
73 plot_utils.set_xlim(ax, (0, 5))
74
Javi Merinof9ac5782014-06-21 19:02:50 +010075 def test_pre_plot_setup(self):
76 """Test that plot_utils.pre_plot_setup() doesn't bomb"""
77 plot_utils.pre_plot_setup(None, None)
78 plot_utils.pre_plot_setup(height=9, width=None)
79 plot_utils.pre_plot_setup(height=None, width=9)
80 plot_utils.pre_plot_setup(3, 9)
81
Javi Merino7f88ae32014-08-11 16:53:35 +010082 axis = plot_utils.pre_plot_setup(ncols=2)
83 self.assertEquals(len(axis), 2)
84
Javi Merino270caac2014-08-12 10:41:38 +010085 axis = plot_utils.pre_plot_setup(nrows=2, ncols=3)
86 self.assertEquals(len(axis), 2)
87 self.assertEquals(len(axis[0]), 3)
88 self.assertEquals(len(axis[1]), 3)
89
Javi Merino3a736552014-06-19 19:22:44 +010090 def test_post_plot_setup(self):
91 """Test that post_plot_setup() doesn't bomb"""
92
Javi Merino5981ee82014-08-11 17:45:38 +010093 _, ax = matplotlib.pyplot.subplots()
Javi Merino3a736552014-06-19 19:22:44 +010094
95 plot_utils.post_plot_setup(ax)
96 plot_utils.post_plot_setup(ax, title="Foo")
97 plot_utils.post_plot_setup(ax, ylim=(0, 72))
Javi Merinoa1561272014-06-21 17:49:02 +010098 plot_utils.post_plot_setup(ax, ylim="range")
Javi Merinof9d43af2014-06-21 16:32:04 +010099 plot_utils.post_plot_setup(ax, xlabel="Bar")
Javi Merinod04643f2014-06-21 17:00:16 +0100100 plot_utils.post_plot_setup(ax, xlim=(0, 100))
Javi Merinoa1561272014-06-21 17:49:02 +0100101 plot_utils.post_plot_setup(ax, xlim="default")
Javi Merino6a5c88d2014-06-19 09:43:18 +0100102
Javi Merinoed977c12014-06-25 17:46:17 +0100103 def test_plot_hist(self):
104 """Test that plost_hist doesn't bomb"""
105 data = pd.Series([1, 1, 2, 4])
106
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100107 _, ax = matplotlib.pyplot.subplots()
Javi Merino23dff5d2015-03-09 19:05:46 +0000108 plot_utils.plot_hist(data, ax, "Foo", "m", 20, "numbers", (0, 4), "default")
Javi Merinoed977c12014-06-25 17:46:17 +0100109
Javi Merino076277d2014-07-02 18:48:18 +0100110class TestPlotUtilsNeedTrace(BaseTestThermal):
Javi Merino6bf48832014-08-11 17:15:35 +0100111 def __init__(self, *args, **kwargs):
112 super(TestPlotUtilsNeedTrace, self).__init__(*args, **kwargs)
Javi Merinod721b272015-04-20 15:37:53 +0100113 self.map_label = {"00000000,00000039": "A53", "00000000,00000006": "A57"}
114 self.actor_order = ["GPU", "A57", "A53"]
Javi Merino6bf48832014-08-11 17:15:35 +0100115
Javi Merino9d9c9b82015-04-29 11:15:11 +0100116 def test_number_freq_plots(self):
117 """Calculate the number of frequency plots correctly"""
118 trace_out = ""
119
120 run = cr2.Run()
121 self.assertEquals(plot_utils.number_freq_plots([run], self.map_label),
122 3)
123
124 # Strip out devfreq traces
125 with open("trace.txt") as fin:
126 for line in fin:
127 if ("thermal_power_devfreq_get_power:" not in line) and \
128 ("thermal_power_devfreq_limit:" not in line):
129 trace_out += line
130
131 with open("trace.txt", "w") as fout:
132 fout.write(trace_out)
133
134 # Without devfreq there should only be two plots
135 run = cr2.Run()
136 self.assertEquals(plot_utils.number_freq_plots([run], self.map_label),
137 2)
138
Javi Merino2919e8d2014-06-26 15:16:05 +0100139 def test_plot_temperature(self):
140 """Test that plot_utils.plot_temperature() doesn't bomb"""
141
Javi Merino1cc4bfc2014-08-11 16:29:11 +0100142 run1 = cr2.Run(name="first")
143 run2 = cr2.Run(name="second")
144 runs = [run1, run2]
Javi Merino2919e8d2014-06-26 15:16:05 +0100145
Javi Merino1cc4bfc2014-08-11 16:29:11 +0100146 plot_utils.plot_temperature(runs, ylim="default")
Javi Merino8e8e3212014-06-26 15:24:34 +0100147 matplotlib.pyplot.close('all')
Javi Merino6bf48832014-08-11 17:15:35 +0100148
149 def test_plot_load(self):
150 """Test that plot_utils.plot_load() doesn't bomb"""
151
152 run1 = cr2.Run(name="first")
153 run2 = cr2.Run(name="second")
154 runs = [run1, run2]
155
156 plot_utils.plot_load(runs, self.map_label, height=5)
157 matplotlib.pyplot.close('all')
Javi Merinoaf05f312014-08-11 17:47:59 +0100158
159 def test_plot_load_single_run(self):
160 """plot_utils.plot_load() can be used with a single run"""
161 run = cr2.Run()
162
163 plot_utils.plot_load([run], self.map_label)
164 matplotlib.pyplot.close('all')
Javi Merino0c484262014-08-12 11:55:04 +0100165
166 def test_plot_allfreqs(self):
167 """Test that plot_utils.plot_allfreqs() doesn't bomb"""
168
169 run1 = cr2.Run(name="first")
170 run2 = cr2.Run(name="second")
171 runs = [run1, run2]
172
173 plot_utils.plot_allfreqs(runs, self.map_label, width=20)
174 matplotlib.pyplot.close('all')
175
Javi Merino114c9cb2014-08-12 14:47:09 +0100176 def test_plot_allfreqs_single_run(self):
177 """plot_utils.plot_allfreqs() can be used with a single run"""
178 run = cr2.Run()
179
180 plot_utils.plot_allfreqs([run], self.map_label)
Javi Merino0c484262014-08-12 11:55:04 +0100181 matplotlib.pyplot.close('all')
Javi Merino38fd12d2014-08-12 15:02:47 +0100182
183 def test_plot_controller(self):
184 """plot_utils.plot_controller() doesn't bomb"""
185
186 run1 = cr2.Run(name="first")
187 run2 = cr2.Run(name="second")
188 runs = [run1, run2]
189
190 plot_utils.plot_controller(runs, height=5)
191 matplotlib.pyplot.close('all')
Javi Merinof5cd04b2014-08-12 15:26:22 +0100192
193 def test_plot_input_power(self):
194 """plot_utils.plot_input_power() doesn't bomb"""
195
196 run1 = cr2.Run(name="first")
197 run2 = cr2.Run(name="second")
198 runs = [run1, run2]
199
200 plot_utils.plot_input_power(runs, self.actor_order, width=20)
201 matplotlib.pyplot.close('all')
Javi Merino9fde2152014-08-12 15:34:24 +0100202
203 def test_plot_output_power(self):
204 """plot_utils.plot_output_power() doesn't bomb"""
205
206 run1 = cr2.Run(name="first")
207 run2 = cr2.Run(name="second")
208 runs = [run1, run2]
209
210 plot_utils.plot_output_power(runs, self.actor_order, width=20)
211 matplotlib.pyplot.close('all')
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100212
213 def test_plot_freq_hists(self):
214 """plot_utils.plot_freq_hists() doesn't bomb"""
215
216 run1 = cr2.Run(name="first")
217 run2 = cr2.Run(name="second")
218 runs = [run1, run2]
219
220 plot_utils.plot_freq_hists(runs, self.map_label)
221 matplotlib.pyplot.close('all')
222
223 def test_plot_freq_hists_single_run(self):
224 """plot_utils.plot_freq_hists() works with a single run"""
225
226 run = cr2.Run()
227
228 plot_utils.plot_freq_hists([run], self.map_label)
229 matplotlib.pyplot.close('all')
230
231 def test_plot_temperature_hist(self):
232 """plot_utils.plot_temperature_hist() doesn't bomb"""
233
234 run1 = cr2.Run(name="first")
235 run2 = cr2.Run(name="second")
236 runs = [run1, run2]
237
238 plot_utils.plot_temperature_hist(runs)
239 matplotlib.pyplot.close('all')