blob: fa328b1dbd714df72f4188fa62cf3bf5ceddc40c [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")
Kapileshwar Singha2040442015-02-23 12:19:18 +000024 l.view(test=True)
KP Singh7319a882014-12-24 18:18:01 +000025
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 Singha2040442015-02-23 12:19:18 +000032 l.view(test=True)
KP Singh7319a882014-12-24 18:18:01 +000033
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 Singh18820752015-02-11 12:01:08 +000039 run2],
40 [cr2.thermal.Thermal,
41 cr2.thermal.ThermalGovernor],
42 column=["temp",
43 "power_range"])
Kapileshwar Singha2040442015-02-23 12:19:18 +000044 l.view(test=True)
KP Singh7319a882014-12-24 18:18:01 +000045
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 Singh18820752015-02-11 12:01:08 +000051 run2],
52 [cr2.power.OutPower],
53 column=["power"],
54 filters={"cdev_state": [1]})
Kapileshwar Singha2040442015-02-23 12:19:18 +000055 l.view(test=True)
KP Singh7319a882014-12-24 18:18:01 +000056
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 Singha2040442015-02-23 12:19:18 +000065 l.view(test=True)
KP Singh7319a882014-12-24 18:18:01 +000066
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 Singha2040442015-02-23 12:19:18 +000073 l.view(test=True)
KP Singh7319a882014-12-24 18:18:01 +000074
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 Singh18820752015-02-11 12:01:08 +000080 run2],
81 [cr2.power.InPower,
82 cr2.power.OutPower],
83 column=["dynamic_power",
84 "power"],
85 pivot="cpus")
Kapileshwar Singha2040442015-02-23 12:19:18 +000086 l.view(test=True)
KP Singh7319a882014-12-24 18:18:01 +000087
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 Singh18820752015-02-11 12:01:08 +000096 "dynamic_power",
KP Singh7319a882014-12-24 18:18:01 +000097 "load1"],
98 filters={
99 "cdev_state": [
100 1,
101 0]},
102 pivot="cpus")
Kapileshwar Singha2040442015-02-23 12:19:18 +0000103 l.view(test=True)
Kapileshwar Singh5ebf1a32015-02-06 15:50:41 +0000104
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)