blob: dbcef4933e8bea200cd4cfa67d3baf8d28ca9cb3 [file] [log] [blame]
Javi Merino7f3c8a62014-06-13 11:38:58 +01001#!/usr/bin/python
Javi Merino034e7cc2015-04-22 18:39:21 +01002# $Copyright:
3# ----------------------------------------------------------------
4# This confidential and proprietary software may be used only as
5# authorised by a licensing agreement from ARM Limited
6# (C) COPYRIGHT 2015 ARM Limited
7# ALL RIGHTS RESERVED
8# The entire notice above must be reproduced on all authorised
9# copies and copies may only be made to the extent permitted
10# by a licensing agreement from ARM Limited.
11# ----------------------------------------------------------------
12# File: test_plot_utils.py
13# ----------------------------------------------------------------
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 Merino6a5c88d2014-06-19 09:43:18 +010022import cr2
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
121 run = cr2.Run()
122 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
136 run = cr2.Run()
137 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 Merino1cc4bfc2014-08-11 16:29:11 +0100143 run1 = cr2.Run(name="first")
144 run2 = cr2.Run(name="second")
145 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
153 run1 = cr2.Run(name="first")
154 run2 = cr2.Run(name="second")
155 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"""
162 run = cr2.Run()
163
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
170 run1 = cr2.Run(name="first")
171 run2 = cr2.Run(name="second")
172 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"""
179 run = cr2.Run()
180
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
187 run1 = cr2.Run(name="first")
188 run2 = cr2.Run(name="second")
189 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
197 run1 = cr2.Run(name="first")
198 run2 = cr2.Run(name="second")
199 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
207 run1 = cr2.Run(name="first")
208 run2 = cr2.Run(name="second")
209 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
217 run1 = cr2.Run(name="first")
218 run2 = cr2.Run(name="second")
219 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
227 run = cr2.Run()
228
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
235 run1 = cr2.Run(name="first")
236 run2 = cr2.Run(name="second")
237 runs = [run1, run2]
238
239 plot_utils.plot_temperature_hist(runs)
240 matplotlib.pyplot.close('all')