cr2: turn cr2 into a module
In the process, make the old cr2.py into results.py
diff --git a/cr2/__init__.py b/cr2/__init__.py
new file mode 100644
index 0000000..6c3a957
--- /dev/null
+++ b/cr2/__init__.py
@@ -0,0 +1,6 @@
+#!/usr/bin/python
+
+from pi_controller import PIController
+from power import Power
+from thermal import Thermal
+from results import CR2, get_results, combine_results
diff --git a/cr2/cr2.py b/cr2/results.py
similarity index 100%
rename from cr2/cr2.py
rename to cr2/results.py
diff --git a/tests/cr2 b/tests/cr2
new file mode 120000
index 0000000..9e88218
--- /dev/null
+++ b/tests/cr2
@@ -0,0 +1 @@
+../cr2
\ No newline at end of file
diff --git a/tests/test_cr2.py b/tests/test_cr2.py
deleted file mode 100644
index e2c6f81..0000000
--- a/tests/test_cr2.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/python
-
-import unittest
-import os, sys
-import tempfile
-
-import utils_tests
-import cr2
-
-class TestCR2(utils_tests.SetupDirectory):
- def __init__(self, *args, **kwargs):
- super(TestCR2, self).__init__(
- ["results.csv"],
- *args, **kwargs)
-
- def test_get_results(self):
- results_frame = cr2.get_results()
-
- self.assertEquals(type(results_frame), cr2.CR2)
- self.assertEquals(len(results_frame.columns), 3)
- self.assertEquals(results_frame["antutu"][0], 2)
- self.assertEquals(results_frame["antutu"][1], 6)
- self.assertEquals(results_frame["antutu"][2], 3)
- self.assertEquals(results_frame["glbench_trex"][0], 740)
- self.assertEquals(results_frame["geekbench"][0], 3)
- self.assertEquals(results_frame["geekbench"][1], 4)
-
- def test_get_results_path(self):
- """cr2.get_results() can be given a directory for the results.csv"""
-
- other_random_dir = tempfile.mkdtemp()
- os.chdir(other_random_dir)
-
- results_frame = cr2.get_results(self.out_dir)
-
- self.assertEquals(len(results_frame.columns), 3)
-
- def test_combine_results(self):
- res1 = cr2.get_results()
- res2 = cr2.get_results()
-
- res2["antutu"][0] = 42
- combined = cr2.combine_results([res1, res2], keys=["power_allocator", "ipa"])
-
- self.assertEquals(type(combined), cr2.CR2)
- self.assertEquals(combined["antutu"]["power_allocator"][0], 2)
- self.assertEquals(combined["antutu"]["ipa"][0], 42)
- self.assertEquals(combined["geekbench"]["power_allocator"][1], 4)
- self.assertEquals(combined["glbench_trex"]["ipa"][2], 920)
-
- def test_plot_results_benchmark(self):
- """Test CR2.plot_results_benchmark()
-
- Can't test it, so just check that it doens't bomb
- """
- results_frame = cr2.get_results()
-
- results_frame.plot_results_benchmark("antutu")
- results_frame.plot_results_benchmark("glbench_trex", title="Glbench TRex")
-
- def test_get_run_number(self):
- self.assertEquals(cr2.get_run_number("score_2"), (True, 2))
- self.assertEquals(cr2.get_run_number("score"), (True, 0))
- self.assertEquals(cr2.get_run_number("score 3"), (True, 3))
- self.assertEquals(cr2.get_run_number("FPS_1"), (True, 1))
- self.assertEquals(cr2.get_run_number("Memory_score")[0], False)
-
- def test_plot_results(self):
- """Test CR2.plot_results()
-
- Can't test it, so just check that it doens't bomb
- """
-
- r1 = cr2.get_results()
- r2 = cr2.get_results()
- combined = cr2.combine_results([r1, r2], ["r1", "r2"])
-
- combined.plot_results()
diff --git a/tests/test_pi.py b/tests/test_pi.py
index b2277f0..d83a2ba 100644
--- a/tests/test_pi.py
+++ b/tests/test_pi.py
@@ -1,16 +1,12 @@
#!/usr/bin/python
-import unittest
-import os, sys
-
-import utils_tests
from test_thermal import TestThermalBase
-import pi_controller
+from cr2 import PIController
class TestPIController(TestThermalBase):
def test_get_dataframe(self):
"""Test PIController.get_data_frame()"""
- df = pi_controller.PIController().get_data_frame()
+ df = PIController().get_data_frame()
self.assertTrue(len(df) > 0)
self.assertTrue("err_integral" in df.columns)
diff --git a/tests/test_power.py b/tests/test_power.py
index 9372cb4..2e3b21b 100644
--- a/tests/test_power.py
+++ b/tests/test_power.py
@@ -1,16 +1,12 @@
#!/usr/bin/python
-import unittest
-import os, sys
-
-import utils_tests
from test_thermal import TestThermalBase
-import power
+from cr2 import Power
class TestPower(TestThermalBase):
def test_get_dataframe(self):
"""Test Power.get_data_frame()"""
- df = power.Power().get_data_frame()
+ df = Power().get_data_frame()
self.assertEquals(df["power"].iloc[0], 2898)
self.assertTrue("cdev_state" in df.columns)
diff --git a/tests/test_results.py b/tests/test_results.py
new file mode 100644
index 0000000..0bda9c4
--- /dev/null
+++ b/tests/test_results.py
@@ -0,0 +1,78 @@
+#!/usr/bin/python
+
+import os, sys
+import tempfile
+
+import utils_tests
+sys.path.append(os.path.join(utils_tests.TESTS_DIRECTORY, "..", "cr2"))
+import results
+
+class TestResults(utils_tests.SetupDirectory):
+ def __init__(self, *args, **kwargs):
+ super(TestResults, self).__init__(
+ ["results.csv"],
+ *args, **kwargs)
+
+ def test_get_results(self):
+ results_frame = results.get_results()
+
+ self.assertEquals(type(results_frame), results.CR2)
+ self.assertEquals(len(results_frame.columns), 3)
+ self.assertEquals(results_frame["antutu"][0], 2)
+ self.assertEquals(results_frame["antutu"][1], 6)
+ self.assertEquals(results_frame["antutu"][2], 3)
+ self.assertEquals(results_frame["glbench_trex"][0], 740)
+ self.assertEquals(results_frame["geekbench"][0], 3)
+ self.assertEquals(results_frame["geekbench"][1], 4)
+
+ def test_get_results_path(self):
+ """results.get_results() can be given a directory for the results.csv"""
+
+ other_random_dir = tempfile.mkdtemp()
+ os.chdir(other_random_dir)
+
+ results_frame = results.get_results(self.out_dir)
+
+ self.assertEquals(len(results_frame.columns), 3)
+
+ def test_combine_results(self):
+ res1 = results.get_results()
+ res2 = results.get_results()
+
+ res2["antutu"][0] = 42
+ combined = results.combine_results([res1, res2], keys=["power_allocator", "ipa"])
+
+ self.assertEquals(type(combined), results.CR2)
+ self.assertEquals(combined["antutu"]["power_allocator"][0], 2)
+ self.assertEquals(combined["antutu"]["ipa"][0], 42)
+ self.assertEquals(combined["geekbench"]["power_allocator"][1], 4)
+ self.assertEquals(combined["glbench_trex"]["ipa"][2], 920)
+
+ def test_plot_results_benchmark(self):
+ """Test CR2.plot_results_benchmark()
+
+ Can't test it, so just check that it doens't bomb
+ """
+ results_frame = results.get_results()
+
+ results_frame.plot_results_benchmark("antutu")
+ results_frame.plot_results_benchmark("glbench_trex", title="Glbench TRex")
+
+ def test_get_run_number(self):
+ self.assertEquals(results.get_run_number("score_2"), (True, 2))
+ self.assertEquals(results.get_run_number("score"), (True, 0))
+ self.assertEquals(results.get_run_number("score 3"), (True, 3))
+ self.assertEquals(results.get_run_number("FPS_1"), (True, 1))
+ self.assertEquals(results.get_run_number("Memory_score")[0], False)
+
+ def test_plot_results(self):
+ """Test CR2.plot_results()
+
+ Can't test it, so just check that it doens't bomb
+ """
+
+ r1 = results.get_results()
+ r2 = results.get_results()
+ combined = results.combine_results([r1, r2], ["r1", "r2"])
+
+ combined.plot_results()
diff --git a/tests/test_thermal.py b/tests/test_thermal.py
index 1424163..52588a0 100644
--- a/tests/test_thermal.py
+++ b/tests/test_thermal.py
@@ -5,6 +5,8 @@
import re, shutil, tempfile
import utils_tests
+from cr2 import Thermal
+sys.path.append(os.path.join(utils_tests.TESTS_DIRECTORY, "..", "cr2"))
import thermal
class TestThermalBase(utils_tests.SetupDirectory):
@@ -16,7 +18,7 @@
class TestThermal(TestThermalBase):
def test_do_txt_if_not_there(self):
- c = thermal.Thermal()
+ c = Thermal()
found = False
with open("trace.txt") as f:
@@ -31,10 +33,10 @@
def test_fail_if_no_trace_dat(self):
"""Raise an IOError if there's no trace.dat and trace.txt"""
os.remove("trace.dat")
- self.assertRaises(IOError, thermal.Thermal)
+ self.assertRaises(IOError, Thermal)
def test_get_thermal_csv(self):
- thermal.Thermal().write_thermal_csv()
+ Thermal().write_thermal_csv()
first_data_line = '328.473417,3,156,12,171,2898,2898,5252,6580,68,8934,48000,9000\n'
with open("thermal.csv") as f:
@@ -45,7 +47,7 @@
self.assertEquals(second_line, first_data_line)
def test_get_dataframe(self):
- df = thermal.Thermal().get_data_frame()
+ df = Thermal().get_data_frame()
self.assertTrue(len(df) > 0)
self.assertEquals(df["currT"].iloc[0], 48000)
@@ -56,20 +58,20 @@
"""Test Thermal.plot_temperature()
Can't check that the graph is ok, so just see that the method doesn't blow up"""
- thermal.Thermal().plot_temperature()
- thermal.Thermal().plot_temperature(title="Antutu")
+ Thermal().plot_temperature()
+ Thermal().plot_temperature(title="Antutu")
def test_plot_input_power(self):
"""Test plot_input_power()
Can't check that the graph is ok, so just see that the method doesn't blow up"""
- thermal.Thermal().plot_input_power()
+ Thermal().plot_input_power()
def test_plot_output_power(self):
"""Test plot_output_power()
Can't check that the graph is ok, so just see that the method doesn't blow up"""
- thermal.Thermal().plot_output_power()
+ Thermal().plot_output_power()
def test_set_plot_size(self):
"""Test that thermal.set_plot_size() doesn't bomb"""
@@ -84,7 +86,7 @@
other_random_dir = tempfile.mkdtemp()
os.chdir(other_random_dir)
- t = thermal.Thermal(self.out_dir)
+ t = Thermal(self.out_dir)
df = t.get_data_frame()
self.assertTrue(len(df) > 0)
@@ -122,5 +124,5 @@
shutil.rmtree(self.out_dir)
def test_empty_trace_txt(self):
- df = thermal.Thermal().get_data_frame()
+ df = Thermal().get_data_frame()
self.assertEquals(len(df), 0)
diff --git a/tests/utils_tests.py b/tests/utils_tests.py
index 7bf4079..d63165e 100644
--- a/tests/utils_tests.py
+++ b/tests/utils_tests.py
@@ -1,11 +1,10 @@
#!/usr/bin/python
import unittest
-import os, sys
+import os
import shutil, tempfile
TESTS_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(TESTS_DIRECTORY, "..", "cr2"))
class SetupDirectory(unittest.TestCase):
def __init__(self, files_to_copy, *args, **kwargs):