diff options
Diffstat (limited to 'tests/test_thermal.py')
-rw-r--r-- | tests/test_thermal.py | 130 |
1 files changed, 1 insertions, 129 deletions
diff --git a/tests/test_thermal.py b/tests/test_thermal.py index 2de2345..ab7f99b 100644 --- a/tests/test_thermal.py +++ b/tests/test_thermal.py @@ -4,63 +4,14 @@ import unittest import matplotlib import os import pandas as pd -import re import shutil import sys import tempfile import utils_tests import cr2 -sys.path.append(os.path.join(utils_tests.TESTS_DIRECTORY, "..", "cr2")) -import thermal - -class TestThermalMethods(unittest.TestCase): - """Test simple methods that don't need to set up a directory""" - def test_trace_parser_explode_array(self): - """Basic test of trace_parser_explode_array()""" - - line = "cpus=0000000f freq=1400000 raw_cpu_power=189 load={3 2 12 2} power=14" - expected = "cpus=0000000f freq=1400000 raw_cpu_power=189 load0=3 load1=2 load2=12 load3=2 power=14" - array_lengths = {"load": 4} - - result = thermal.trace_parser_explode_array(line, array_lengths) - self.assertEquals(result, expected) - - def test_trace_parser_explode_array_nop(self): - """trace_parser_explode_array() returns the same string if there's no array in it""" - - line = "cpus=0000000f freq=1400000 raw_cpu_power=189 load0=3 load1=2 load2=12 load3=2 power=14" - array_lengths = {"load": 0} - - result = thermal.trace_parser_explode_array(line, array_lengths) - self.assertEquals(result, line) - - def test_trace_parser_explode_array_2(self): - """trace_parser_explode_array() works if there's two arrays in the string""" - - line = "cpus=0000000f freq=1400000 load={3 2 12 2} power=14 req_power={10 7 2 34}" - expected = "cpus=0000000f freq=1400000 load0=3 load1=2 load2=12 load3=2 power=14 req_power0=10 req_power1=7 req_power2=2 req_power3=34" - array_lengths = {'load': 4, 'req_power': 4} - - result = thermal.trace_parser_explode_array(line, array_lengths) - self.assertEquals(result, expected) - - def test_trace_parser_explode_array_diff_lengths(self): - """trace_parser_explode_array() expands arrays that are shorter than -the expected length - trace_parser_explode_array() has to be able to deal with an - array of size 2 if we tell it in other parts of the trace it - is four. - - """ - - line = "cpus=0000000f freq=1400000 load={3 2} power=14" - expected = "cpus=0000000f freq=1400000 load0=3 load1=2 load2=0 load3=0 power=14" - array_lengths = {'load': 4} - - result = thermal.trace_parser_explode_array(line, array_lengths) - self.assertEquals(result, expected) +sys.path.append(os.path.join(utils_tests.TESTS_DIRECTORY, "..", "cr2")) class BaseTestThermal(utils_tests.SetupDirectory): def __init__(self, *args, **kwargs): @@ -69,71 +20,7 @@ class BaseTestThermal(utils_tests.SetupDirectory): *args, **kwargs) -class TestThermalBase(utils_tests.SetupDirectory): - """Incomplete tests for the ThermalBase class""" - - def __init__(self, *args, **kwargs): - super(TestThermalBase, self).__init__( - [], - *args, - **kwargs) - - def test_get_trace_array_lengths(self): - """Test InPower.get_trace_array_lengths()""" - - in_data = """ kworker/4:1-397 [004] 720.741315: thermal_power_actor_cpu_get_dyn_power: cpus=000000f0 freq=1900000 raw_cpu_power=1259 load={1 2} power=61 - kworker/4:1-397 [004] 720.741349: thermal_power_actor_cpu_get_dyn_power: cpus=0000000f freq=1400000 raw_cpu_power=189 load={1 3 4 89} power=14 - kworker/4:1-397 [004] 720.841315: thermal_power_actor_cpu_get_dyn_power: cpus=000000f0 freq=1900000 raw_cpu_power=1259 load={1 2} power=61 - kworker/4:1-397 [004] 720.841349: thermal_power_actor_cpu_get_dyn_power: cpus=0000000f freq=1400000 raw_cpu_power=189 load={} power=14 -""" - with open("trace.txt", "w") as fout: - fout.write(in_data) - - base = thermal.BaseThermal(".", "thermal_power_actor_cpu_get_dyn_power") - lengths = base.get_trace_array_lengths("trace.txt") - - self.assertEquals(len(lengths), 1) - self.assertEquals(lengths["load"], 4) - - def test_parse_empty_array(self): - """Test that trace that has an empty array creates a valid DataFrame""" - - in_data = """ kworker/4:1-397 [004] 720.741315: thermal_power_actor_cpu_get_dyn_power: cpus=000000f0 freq=1900000 raw_cpu_power=1259 load={} power=61 - kworker/4:1-397 [004] 720.741349: thermal_power_actor_cpu_get_dyn_power: cpus=0000000f freq=1400000 raw_cpu_power=189 load={} power=14""" - expected_columns = set(["cpus", "freq", "raw_cpu_power", "power"]) - - with open("trace.txt", "w") as fout: - fout.write(in_data) - - base = thermal.BaseThermal(".", "thermal_power_actor_cpu_get_dyn_power") - dfr = base.data_frame - - self.assertEquals(set(dfr.columns), expected_columns) - self.assertEquals(dfr["power"].iloc[0], 61) - class TestThermal(BaseTestThermal): - def test_get_dataframe(self): - dfr = cr2.Run().thermal.data_frame - - self.assertTrue("thermal_zone" in dfr.columns) - self.assertEquals(dfr["temp"].iloc[0], 24000) - - def test_write_csv(self): - """BaseThermal().write_csv() creates a valid csv""" - from csv import DictReader - - fname = "thermal.csv" - cr2.Run().thermal.write_csv(fname) - - with open(fname) as fin: - csv_reader = DictReader(fin) - - self.assertTrue("Time" in csv_reader.fieldnames) - self.assertTrue("temp" in csv_reader.fieldnames) - - first_data = csv_reader.next() - self.assertEquals(first_data["Time"], "0.0") - self.assertEquals(first_data["temp"], "24000") def test_plot_temperature(self): """Test ThermalGovernor.plot_temperature() @@ -167,21 +54,6 @@ class TestThermal(BaseTestThermal): cr2.Run().thermal.plot_temperature_hist(ax, "Foo") matplotlib.pyplot.close('all') - def test_normalize_time(self): - """BaseThermal.normalize_time() normalizes the time of the trace""" - thrm = cr2.Run().thermal - - last_prev_time = thrm.data_frame.index[-1] - - basetime = thrm.data_frame.index[0] - thrm.normalize_time(basetime) - - last_time = thrm.data_frame.index[-1] - expected_last_time = last_prev_time - basetime - - self.assertEquals(round(thrm.data_frame.index[0], 7), 0) - self.assertEquals(round(last_time - expected_last_time, 7), 0) - class TestThermalGovernor(BaseTestThermal): def __init__(self, *args, **kwargs): super(TestThermalGovernor, self).__init__(*args, **kwargs) |