KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import unittest |
| 4 | import matplotlib |
| 5 | import pandas as pd |
Kapileshwar Singh | 5ebf1a3 | 2015-02-06 15:50:41 +0000 | [diff] [blame] | 6 | import tempfile |
| 7 | import os |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 8 | |
| 9 | from test_thermal import BaseTestThermal |
| 10 | import cr2 |
| 11 | |
| 12 | |
| 13 | class TestPlotter(BaseTestThermal): |
| 14 | |
| 15 | """No Bombing testcases for plotter""" |
| 16 | |
| 17 | def __init__(self, *args, **kwargs): |
| 18 | super(TestPlotter, self).__init__(*args, **kwargs) |
| 19 | |
| 20 | def test_plot_no_pivot(self): |
| 21 | """Tests LinePlot with no pivot""" |
| 22 | run1 = cr2.Run(name="first") |
| 23 | l = cr2.LinePlot(run1, cr2.thermal.Thermal, column="temp") |
| 24 | l.view() |
| 25 | matplotlib.pyplot.close('all') |
| 26 | |
| 27 | def test_plot_multi_run(self): |
| 28 | """Tests LinePlot with no Pivot multi runs""" |
| 29 | run1 = cr2.Run(name="first") |
| 30 | run2 = cr2.Run(name="second") |
| 31 | l = cr2.LinePlot( |
| 32 | [run1, run2], cr2.thermal.Thermal, column="temp") |
| 33 | l.view() |
| 34 | matplotlib.pyplot.close('all') |
| 35 | |
| 36 | def test_plot_multi(self): |
| 37 | """Tests LinePlot with no Pivot multi attrs""" |
| 38 | run1 = cr2.Run(name="first") |
| 39 | run2 = cr2.Run(name="second") |
| 40 | l = cr2.LinePlot([run1, |
Kapileshwar Singh | 1882075 | 2015-02-11 12:01:08 +0000 | [diff] [blame] | 41 | run2], |
| 42 | [cr2.thermal.Thermal, |
| 43 | cr2.thermal.ThermalGovernor], |
| 44 | column=["temp", |
| 45 | "power_range"]) |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 46 | l.view() |
| 47 | matplotlib.pyplot.close('all') |
| 48 | |
| 49 | def test_plot_filter(self): |
| 50 | """Tests LinePlot with no Pivot with filters""" |
| 51 | run1 = cr2.Run(name="first") |
| 52 | run2 = cr2.Run(name="second") |
| 53 | l = cr2.LinePlot([run1, |
Kapileshwar Singh | 1882075 | 2015-02-11 12:01:08 +0000 | [diff] [blame] | 54 | run2], |
| 55 | [cr2.power.OutPower], |
| 56 | column=["power"], |
| 57 | filters={"cdev_state": [1]}) |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 58 | l.view() |
| 59 | matplotlib.pyplot.close('all') |
| 60 | |
| 61 | def test_plot_pivot(self): |
| 62 | """Tests LinePlot with Pivot""" |
| 63 | run1 = cr2.Run(name="first") |
| 64 | l = cr2.LinePlot( |
| 65 | run1, |
| 66 | cr2.thermal.Thermal, |
| 67 | column="temp", |
| 68 | pivot="thermal_zone") |
| 69 | l.view() |
| 70 | matplotlib.pyplot.close('all') |
| 71 | |
| 72 | def test_plot_multi_run_pivot(self): |
| 73 | """Tests LinePlot with Pivot multi runs""" |
| 74 | run1 = cr2.Run(name="first") |
| 75 | run2 = cr2.Run(name="second") |
| 76 | l = cr2.LinePlot( |
| 77 | [run1, run2], cr2.power.OutPower, column="power", pivot="cpus") |
| 78 | l.view() |
| 79 | matplotlib.pyplot.close('all') |
| 80 | |
| 81 | def test_plot_multi_pivot(self): |
| 82 | """Tests LinePlot with Pivot with multi attrs""" |
| 83 | run1 = cr2.Run(name="first") |
| 84 | run2 = cr2.Run(name="second") |
| 85 | l = cr2.LinePlot([run1, |
Kapileshwar Singh | 1882075 | 2015-02-11 12:01:08 +0000 | [diff] [blame] | 86 | run2], |
| 87 | [cr2.power.InPower, |
| 88 | cr2.power.OutPower], |
| 89 | column=["dynamic_power", |
| 90 | "power"], |
| 91 | pivot="cpus") |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 92 | l.view() |
| 93 | matplotlib.pyplot.close('all') |
| 94 | |
| 95 | def test_plot_multi_pivot_filter(self): |
| 96 | """Tests LinePlot with Pivot and filters""" |
| 97 | run1 = cr2.Run(name="first") |
| 98 | run2 = cr2.Run(name="second") |
| 99 | l = cr2.LinePlot( |
| 100 | run1, |
| 101 | cr2.power.InPower, |
| 102 | column=[ |
Kapileshwar Singh | 1882075 | 2015-02-11 12:01:08 +0000 | [diff] [blame] | 103 | "dynamic_power", |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 104 | "load1"], |
| 105 | filters={ |
| 106 | "cdev_state": [ |
| 107 | 1, |
| 108 | 0]}, |
| 109 | pivot="cpus") |
| 110 | l.view() |
| 111 | matplotlib.pyplot.close('all') |
Kapileshwar Singh | 5ebf1a3 | 2015-02-06 15:50:41 +0000 | [diff] [blame] | 112 | |
| 113 | def test_plot_savefig(self): |
| 114 | """Tests plotter: savefig""" |
| 115 | run1 = cr2.Run(name="first") |
| 116 | run2 = cr2.Run(name="second") |
| 117 | l = cr2.LinePlot( |
| 118 | run1, |
| 119 | cr2.power.InPower, |
| 120 | column=[ |
| 121 | "dynamic_power", |
| 122 | "load1"], |
| 123 | filters={ |
| 124 | "cdev_state": [ |
| 125 | 1, |
| 126 | 0]}, |
| 127 | pivot="cpus") |
| 128 | png_file = tempfile.mktemp(dir="/tmp", suffix=".png") |
| 129 | l.savefig(png_file) |
| 130 | self.assertTrue(os.path.isfile(png_file)) |
| 131 | os.remove(png_file) |
| 132 | matplotlib.pyplot.close('all') |