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") |
Kapileshwar Singh | a204044 | 2015-02-23 12:19:18 +0000 | [diff] [blame] | 24 | l.view(test=True) |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 25 | |
| 26 | def test_plot_multi_run(self): |
| 27 | """Tests LinePlot with no Pivot multi runs""" |
| 28 | run1 = cr2.Run(name="first") |
| 29 | run2 = cr2.Run(name="second") |
| 30 | l = cr2.LinePlot( |
| 31 | [run1, run2], cr2.thermal.Thermal, column="temp") |
Kapileshwar Singh | a204044 | 2015-02-23 12:19:18 +0000 | [diff] [blame] | 32 | l.view(test=True) |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 33 | |
| 34 | def test_plot_multi(self): |
| 35 | """Tests LinePlot with no Pivot multi attrs""" |
| 36 | run1 = cr2.Run(name="first") |
| 37 | run2 = cr2.Run(name="second") |
| 38 | l = cr2.LinePlot([run1, |
Kapileshwar Singh | 1882075 | 2015-02-11 12:01:08 +0000 | [diff] [blame] | 39 | run2], |
| 40 | [cr2.thermal.Thermal, |
| 41 | cr2.thermal.ThermalGovernor], |
| 42 | column=["temp", |
| 43 | "power_range"]) |
Kapileshwar Singh | a204044 | 2015-02-23 12:19:18 +0000 | [diff] [blame] | 44 | l.view(test=True) |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 45 | |
| 46 | def test_plot_filter(self): |
| 47 | """Tests LinePlot with no Pivot with filters""" |
| 48 | run1 = cr2.Run(name="first") |
| 49 | run2 = cr2.Run(name="second") |
| 50 | l = cr2.LinePlot([run1, |
Kapileshwar Singh | 1882075 | 2015-02-11 12:01:08 +0000 | [diff] [blame] | 51 | run2], |
| 52 | [cr2.power.OutPower], |
| 53 | column=["power"], |
| 54 | filters={"cdev_state": [1]}) |
Kapileshwar Singh | a204044 | 2015-02-23 12:19:18 +0000 | [diff] [blame] | 55 | l.view(test=True) |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 56 | |
| 57 | def test_plot_pivot(self): |
| 58 | """Tests LinePlot with Pivot""" |
| 59 | run1 = cr2.Run(name="first") |
| 60 | l = cr2.LinePlot( |
| 61 | run1, |
| 62 | cr2.thermal.Thermal, |
| 63 | column="temp", |
| 64 | pivot="thermal_zone") |
Kapileshwar Singh | a204044 | 2015-02-23 12:19:18 +0000 | [diff] [blame] | 65 | l.view(test=True) |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 66 | |
| 67 | def test_plot_multi_run_pivot(self): |
| 68 | """Tests LinePlot with Pivot multi runs""" |
| 69 | run1 = cr2.Run(name="first") |
| 70 | run2 = cr2.Run(name="second") |
| 71 | l = cr2.LinePlot( |
| 72 | [run1, run2], cr2.power.OutPower, column="power", pivot="cpus") |
Kapileshwar Singh | a204044 | 2015-02-23 12:19:18 +0000 | [diff] [blame] | 73 | l.view(test=True) |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 74 | |
| 75 | def test_plot_multi_pivot(self): |
| 76 | """Tests LinePlot with Pivot with multi attrs""" |
| 77 | run1 = cr2.Run(name="first") |
| 78 | run2 = cr2.Run(name="second") |
| 79 | l = cr2.LinePlot([run1, |
Kapileshwar Singh | 1882075 | 2015-02-11 12:01:08 +0000 | [diff] [blame] | 80 | run2], |
| 81 | [cr2.power.InPower, |
| 82 | cr2.power.OutPower], |
| 83 | column=["dynamic_power", |
| 84 | "power"], |
| 85 | pivot="cpus") |
Kapileshwar Singh | a204044 | 2015-02-23 12:19:18 +0000 | [diff] [blame] | 86 | l.view(test=True) |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 87 | |
| 88 | def test_plot_multi_pivot_filter(self): |
| 89 | """Tests LinePlot with Pivot and filters""" |
| 90 | run1 = cr2.Run(name="first") |
| 91 | run2 = cr2.Run(name="second") |
| 92 | l = cr2.LinePlot( |
| 93 | run1, |
| 94 | cr2.power.InPower, |
| 95 | column=[ |
Kapileshwar Singh | 1882075 | 2015-02-11 12:01:08 +0000 | [diff] [blame] | 96 | "dynamic_power", |
KP Singh | 7319a88 | 2014-12-24 18:18:01 +0000 | [diff] [blame] | 97 | "load1"], |
| 98 | filters={ |
| 99 | "cdev_state": [ |
| 100 | 1, |
| 101 | 0]}, |
| 102 | pivot="cpus") |
Kapileshwar Singh | a204044 | 2015-02-23 12:19:18 +0000 | [diff] [blame] | 103 | l.view(test=True) |
Kapileshwar Singh | 5ebf1a3 | 2015-02-06 15:50:41 +0000 | [diff] [blame] | 104 | |
| 105 | def test_plot_savefig(self): |
| 106 | """Tests plotter: savefig""" |
| 107 | run1 = cr2.Run(name="first") |
| 108 | run2 = cr2.Run(name="second") |
| 109 | l = cr2.LinePlot( |
| 110 | run1, |
| 111 | cr2.power.InPower, |
| 112 | column=[ |
| 113 | "dynamic_power", |
| 114 | "load1"], |
| 115 | filters={ |
| 116 | "cdev_state": [ |
| 117 | 1, |
| 118 | 0]}, |
| 119 | pivot="cpus") |
| 120 | png_file = tempfile.mktemp(dir="/tmp", suffix=".png") |
| 121 | l.savefig(png_file) |
| 122 | self.assertTrue(os.path.isfile(png_file)) |
| 123 | os.remove(png_file) |