blob: 1efbc08b73e363e06d6216faf0670f64aff2afeb [file] [log] [blame]
KP Singh7319a882014-12-24 18:18:01 +00001#!/usr/bin/env python
2
3import unittest
4import matplotlib
5import pandas as pd
Kapileshwar Singh5ebf1a32015-02-06 15:50:41 +00006import tempfile
7import os
KP Singh7319a882014-12-24 18:18:01 +00008
9from test_thermal import BaseTestThermal
10import cr2
11
12
13class 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 Singh18820752015-02-11 12:01:08 +000041 run2],
42 [cr2.thermal.Thermal,
43 cr2.thermal.ThermalGovernor],
44 column=["temp",
45 "power_range"])
KP Singh7319a882014-12-24 18:18:01 +000046 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 Singh18820752015-02-11 12:01:08 +000054 run2],
55 [cr2.power.OutPower],
56 column=["power"],
57 filters={"cdev_state": [1]})
KP Singh7319a882014-12-24 18:18:01 +000058 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 Singh18820752015-02-11 12:01:08 +000086 run2],
87 [cr2.power.InPower,
88 cr2.power.OutPower],
89 column=["dynamic_power",
90 "power"],
91 pivot="cpus")
KP Singh7319a882014-12-24 18:18:01 +000092 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 Singh18820752015-02-11 12:01:08 +0000103 "dynamic_power",
KP Singh7319a882014-12-24 18:18:01 +0000104 "load1"],
105 filters={
106 "cdev_state": [
107 1,
108 0]},
109 pivot="cpus")
110 l.view()
111 matplotlib.pyplot.close('all')
Kapileshwar Singh5ebf1a32015-02-06 15:50:41 +0000112
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')