Javi Merino | aace7c0 | 2015-08-10 14:10:47 +0100 | [diff] [blame^] | 1 | # Copyright 2015-2015 ARM Limited |
Javi Merino | 034e7cc | 2015-04-22 18:39:21 +0100 | [diff] [blame] | 2 | # |
Javi Merino | aace7c0 | 2015-08-10 14:10:47 +0100 | [diff] [blame^] | 3 | # 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 Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 16 | |
| 17 | import unittest |
Javi Merino | 8e8e321 | 2014-06-26 15:24:34 +0100 | [diff] [blame] | 18 | import matplotlib |
| 19 | import pandas as pd |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 20 | |
Javi Merino | 076277d | 2014-07-02 18:48:18 +0100 | [diff] [blame] | 21 | from test_thermal import BaseTestThermal |
Javi Merino | 6a5c88d | 2014-06-19 09:43:18 +0100 | [diff] [blame] | 22 | import cr2 |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 23 | import plot_utils |
| 24 | |
| 25 | class TestPlotUtils(unittest.TestCase): |
Javi Merino | 7f3c8a6 | 2014-06-13 11:38:58 +0100 | [diff] [blame] | 26 | 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 Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 30 | |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 31 | 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 Merino | 5981ee8 | 2014-08-11 17:45:38 +0100 | [diff] [blame] | 63 | _, ax = matplotlib.pyplot.subplots() |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 64 | |
| 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 Merino | 5981ee8 | 2014-08-11 17:45:38 +0100 | [diff] [blame] | 71 | _, ax = matplotlib.pyplot.subplots() |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 72 | |
| 73 | plot_utils.set_xlim(ax, "default") |
| 74 | plot_utils.set_xlim(ax, (0, 5)) |
| 75 | |
Javi Merino | f9ac578 | 2014-06-21 19:02:50 +0100 | [diff] [blame] | 76 | 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 Merino | 7f88ae3 | 2014-08-11 16:53:35 +0100 | [diff] [blame] | 83 | axis = plot_utils.pre_plot_setup(ncols=2) |
| 84 | self.assertEquals(len(axis), 2) |
| 85 | |
Javi Merino | 270caac | 2014-08-12 10:41:38 +0100 | [diff] [blame] | 86 | 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 Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 91 | def test_post_plot_setup(self): |
| 92 | """Test that post_plot_setup() doesn't bomb""" |
| 93 | |
Javi Merino | 5981ee8 | 2014-08-11 17:45:38 +0100 | [diff] [blame] | 94 | _, ax = matplotlib.pyplot.subplots() |
Javi Merino | 3a73655 | 2014-06-19 19:22:44 +0100 | [diff] [blame] | 95 | |
| 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 Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 99 | plot_utils.post_plot_setup(ax, ylim="range") |
Javi Merino | f9d43af | 2014-06-21 16:32:04 +0100 | [diff] [blame] | 100 | plot_utils.post_plot_setup(ax, xlabel="Bar") |
Javi Merino | d04643f | 2014-06-21 17:00:16 +0100 | [diff] [blame] | 101 | plot_utils.post_plot_setup(ax, xlim=(0, 100)) |
Javi Merino | a156127 | 2014-06-21 17:49:02 +0100 | [diff] [blame] | 102 | plot_utils.post_plot_setup(ax, xlim="default") |
Javi Merino | 6a5c88d | 2014-06-19 09:43:18 +0100 | [diff] [blame] | 103 | |
Javi Merino | ed977c1 | 2014-06-25 17:46:17 +0100 | [diff] [blame] | 104 | def test_plot_hist(self): |
| 105 | """Test that plost_hist doesn't bomb""" |
| 106 | data = pd.Series([1, 1, 2, 4]) |
| 107 | |
Javi Merino | e5ea60a | 2014-08-12 16:41:42 +0100 | [diff] [blame] | 108 | _, ax = matplotlib.pyplot.subplots() |
Javi Merino | 23dff5d | 2015-03-09 19:05:46 +0000 | [diff] [blame] | 109 | plot_utils.plot_hist(data, ax, "Foo", "m", 20, "numbers", (0, 4), "default") |
Javi Merino | ed977c1 | 2014-06-25 17:46:17 +0100 | [diff] [blame] | 110 | |
Javi Merino | 076277d | 2014-07-02 18:48:18 +0100 | [diff] [blame] | 111 | class TestPlotUtilsNeedTrace(BaseTestThermal): |
Javi Merino | 6bf4883 | 2014-08-11 17:15:35 +0100 | [diff] [blame] | 112 | def __init__(self, *args, **kwargs): |
| 113 | super(TestPlotUtilsNeedTrace, self).__init__(*args, **kwargs) |
Javi Merino | d721b27 | 2015-04-20 15:37:53 +0100 | [diff] [blame] | 114 | self.map_label = {"00000000,00000039": "A53", "00000000,00000006": "A57"} |
| 115 | self.actor_order = ["GPU", "A57", "A53"] |
Javi Merino | 6bf4883 | 2014-08-11 17:15:35 +0100 | [diff] [blame] | 116 | |
Javi Merino | 9d9c9b8 | 2015-04-29 11:15:11 +0100 | [diff] [blame] | 117 | 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 Merino | 2919e8d | 2014-06-26 15:16:05 +0100 | [diff] [blame] | 140 | def test_plot_temperature(self): |
| 141 | """Test that plot_utils.plot_temperature() doesn't bomb""" |
| 142 | |
Javi Merino | 1cc4bfc | 2014-08-11 16:29:11 +0100 | [diff] [blame] | 143 | run1 = cr2.Run(name="first") |
| 144 | run2 = cr2.Run(name="second") |
| 145 | runs = [run1, run2] |
Javi Merino | 2919e8d | 2014-06-26 15:16:05 +0100 | [diff] [blame] | 146 | |
Javi Merino | 1cc4bfc | 2014-08-11 16:29:11 +0100 | [diff] [blame] | 147 | plot_utils.plot_temperature(runs, ylim="default") |
Javi Merino | 8e8e321 | 2014-06-26 15:24:34 +0100 | [diff] [blame] | 148 | matplotlib.pyplot.close('all') |
Javi Merino | 6bf4883 | 2014-08-11 17:15:35 +0100 | [diff] [blame] | 149 | |
| 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 Merino | af05f31 | 2014-08-11 17:47:59 +0100 | [diff] [blame] | 159 | |
| 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 Merino | 0c48426 | 2014-08-12 11:55:04 +0100 | [diff] [blame] | 166 | |
| 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 Merino | 114c9cb | 2014-08-12 14:47:09 +0100 | [diff] [blame] | 177 | 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 Merino | 0c48426 | 2014-08-12 11:55:04 +0100 | [diff] [blame] | 182 | matplotlib.pyplot.close('all') |
Javi Merino | 38fd12d | 2014-08-12 15:02:47 +0100 | [diff] [blame] | 183 | |
| 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 Merino | f5cd04b | 2014-08-12 15:26:22 +0100 | [diff] [blame] | 193 | |
| 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 Merino | 9fde215 | 2014-08-12 15:34:24 +0100 | [diff] [blame] | 203 | |
| 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 Merino | e5ea60a | 2014-08-12 16:41:42 +0100 | [diff] [blame] | 213 | |
| 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') |