Home | History | Annotate | Download | only in tests
      1 #    Copyright 2015-2017 ARM Limited
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #     http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 #
     15 
     16 
     17 import os
     18 import re
     19 import matplotlib, tempfile
     20 
     21 import trappy
     22 from test_thermal import BaseTestThermal
     23 
     24 class TestTrappy(BaseTestThermal):
     25     def __init__(self, *args, **kwargs):
     26         super(TestTrappy, self).__init__(*args, **kwargs)
     27         self.map_label = {"00000000,00000039": "A53", "00000000,00000006": "A57"}
     28         self.actor_order = ["GPU", "A57", "A53"]
     29 
     30     def test_summary_plots(self):
     31         """Test summary_plots()
     32 
     33         Can't check that the graphs are ok, so just see that the method doesn't blow up"""
     34 
     35         trappy.summary_plots(self.actor_order, self.map_label)
     36         matplotlib.pyplot.close('all')
     37 
     38         trappy.summary_plots(self.actor_order, self.map_label, width=14,
     39                           title="Foo")
     40         matplotlib.pyplot.close('all')
     41 
     42     def test_summary_plots_bad_parameters(self):
     43         """When summary_plots() receives bad parameters, it offers an understandable error"""
     44 
     45         self.assertRaises(TypeError, trappy.summary_plots,
     46                           (self.map_label, self.actor_order))
     47 
     48         try:
     49             trappy.summary_plots(self.map_label, self.actor_order)
     50             self.fail()
     51         except TypeError as exception:
     52             pass
     53 
     54         self.assertTrue("actor_order" in str(exception))
     55 
     56         try:
     57             trappy.summary_plots(self.actor_order, self.actor_order)
     58             self.fail()
     59         except TypeError as exception:
     60             pass
     61 
     62         self.assertTrue("map_label" in str(exception))
     63 
     64     def test_summary_other_dir(self):
     65         """Test summary_plots() with another directory"""
     66 
     67         other_random_dir = tempfile.mkdtemp()
     68         os.chdir(other_random_dir)
     69 
     70         trappy.summary_plots(self.actor_order, self.map_label, path=self.out_dir)
     71         matplotlib.pyplot.close('all')
     72 
     73         # Sanity check that the test actually ran from another directory
     74         self.assertEquals(os.getcwd(), other_random_dir)
     75 
     76     def test_summary_plots_only_power_allocator_trace(self):
     77         """Test that summary_plots() work if there is only power allocator
     78         trace"""
     79 
     80         # Strip out "thermal_temperature" from the trace
     81         trace_out = ""
     82         with open("trace.txt") as fin:
     83             for line in fin:
     84                 if not re.search("thermal_temperature:", line):
     85                     trace_out += line
     86 
     87         with open("trace.txt", "w") as fout:
     88             fout.write(trace_out)
     89 
     90         trappy.summary_plots(self.actor_order, self.map_label)
     91         matplotlib.pyplot.close('all')
     92 
     93     def test_summary_plots_no_gpu(self):
     94         """summary_plots() works if there is no GPU trace"""
     95 
     96         # Strip out devfreq traces
     97         trace_out = ""
     98         with open("trace.txt") as fin:
     99             for line in fin:
    100                 if ("thermal_power_devfreq_get_power:" not in line) and \
    101                    ("thermal_power_devfreq_limit:" not in line):
    102                     trace_out += line
    103 
    104         with open("trace.txt", "w") as fout:
    105             fout.write(trace_out)
    106 
    107         trappy.summary_plots(self.actor_order, self.map_label)
    108         matplotlib.pyplot.close('all')
    109 
    110     def test_summary_plots_one_actor(self):
    111         """summary_plots() works if there is only one actor"""
    112 
    113         # Strip out devfreq and little traces
    114         trace_out = ""
    115         with open("trace.txt") as fin:
    116             for line in fin:
    117                 if ("thermal_power_devfreq_get_power:" not in line) and \
    118                    ("thermal_power_devfreq_limit:" not in line) and \
    119                    ("thermal_power_cpu_get_power: cpus=00000000,00000039" not in line) and \
    120                    ("thermal_power_cpu_limit: cpus=00000000,00000039" not in line):
    121                     trace_out += line
    122 
    123         with open("trace.txt", "w") as fout:
    124             fout.write(trace_out)
    125 
    126         map_label = {"00000000,00000006": "A57"}
    127         trappy.summary_plots(self.actor_order, map_label)
    128         matplotlib.pyplot.close('all')
    129 
    130     def test_compare_runs(self):
    131         """Basic compare_runs() functionality"""
    132 
    133         trappy.compare_runs(self.actor_order, self.map_label,
    134                         runs=[("new", "."), ("old", self.out_dir)])
    135         matplotlib.pyplot.close('all')
    136