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