diff options
author | Brendan Jackman <brendan.jackman@arm.com> | 2017-06-02 14:05:04 +0100 |
---|---|---|
committer | KP Singh <kpsingh@google.com> | 2017-06-29 22:52:52 +0200 |
commit | 878b9acd722329594362d333a6d7a1ee291746a8 (patch) | |
tree | 29ec7dd48d9be7f17a96ecf3e87dcc7b423ce347 | |
parent | 3fdf6872b0d59743ff05ca4f7ec7f429a3cc81be (diff) | |
download | trappy-878b9acd722329594362d333a6d7a1ee291746a8.tar.gz |
tests: Caching tests
Add test for invalid cache
Add test for caching with extra events
Add test for normalize_time and window parameters
Signed-off-by: Brendan Jackman <brendan.jackman@arm.com>
Signed-off-by: Joel Fernandes <joelaf@google.com>
Reviewed-by: KP Singh <kpsingh@google.com>
20 files changed, 123 insertions, 0 deletions
diff --git a/tests/test_caching.py b/tests/test_caching.py index a8e3ac1..d0893b7 100644 --- a/tests/test_caching.py +++ b/tests/test_caching.py @@ -14,6 +14,7 @@ # import os +import shutil import sys import unittest import utils_tests @@ -97,3 +98,96 @@ class TestCaching(utils_tests.SetupDirectory): self.assertTrue([r[1].prio for r in cached_dfr.iterrows()] == [r[1].prio for r in uncached_dfr.iterrows()]) + + def test_invalid_cache_overwritten(self): + """Test a cache with a bad checksum is overwritten""" + # This is a directory so we can't use the files_to_copy arg of + # SetUpDirectory, just do it ourselves. + cache_path = ".trace.txt.cache" + src = os.path.join(utils_tests.TESTS_DIRECTORY, "trace_sched.txt.cache") + shutil.copytree(src, cache_path) + + md5_path = os.path.join(cache_path, "md5sum") + def read_md5sum(): + with open(md5_path) as f: + return f.read() + + # Change 1 character of the stored checksum + md5sum = read_md5sum() + # Sorry, I guess modifying strings in Python is kind of awkward? + md5sum_inc = "".join(list(md5sum[:-1]) + [chr(ord(md5sum[-1]) + 1)]) + with open(md5_path, "w") as f: + f.write(md5sum_inc) + + # Parse a trace, this should delete and overwrite the invalidated cache + GenericFTrace.disable_cache = False + trace = trappy.FTrace() + + # Check that the modified md5sum was overwritten + self.assertNotEqual(read_md5sum(), md5sum_inc, + "The invalid ftrace cache wasn't overwritten") + + def test_cache_dynamic_events(self): + """Test that caching works if new event parsers have been registered""" + + # Parse the trace to create a cache + GenericFTrace.disable_cache = False + trace1 = trappy.FTrace() + + # Check we're actually testing what we think we are + if hasattr(trace1, 'dynamic_event'): + raise RuntimeError('Test bug: found unexpected event in trace') + + # Now register a new event type, call the constructor again, and check + # that the newly added event (which is not present in the cache) is + # parsed. + + parse_class = trappy.register_dynamic_ftrace("DynamicEvent", "dynamic_test_key") + + trace2 = trappy.FTrace() + self.assertTrue(len(trace2.dynamic_event.data_frame) == 1) + + trappy.unregister_dynamic_ftrace(parse_class) + + def test_cache_normalize_time(self): + """Test that caching doesn't break normalize_time""" + GenericFTrace.disable_cache = False + + # Times in trace_sched.txt + start_time = 6550.018511 + first_freq_event_time = 6550.056870 + + # Parse without normalizing time + trace1 = trappy.FTrace(events=['cpu_frequency', 'sched_wakeup'], + normalize_time=False) + + self.assertEqual(trace1.cpu_frequency.data_frame.index[0], + first_freq_event_time) + + # Parse with normalized time + trace2 = trappy.FTrace(events=['cpu_frequency', 'sched_wakeup'], + normalize_time=True) + + self.assertEqual(trace2.cpu_frequency.data_frame.index[0], + first_freq_event_time - start_time) + + def test_cache_window(self): + """Test that caching doesn't break the 'window' parameter""" + GenericFTrace.disable_cache = False + + trace1 = trappy.FTrace( + events=['sched_wakeup'], + window=(0, 1)) + + # Check that we're testing what we think we're testing The trace + # contains 2 sched_wakeup events; this window should get rid of one of + # them. + if len(trace1.sched_wakeup.data_frame) != 1: + raise RuntimeError('Test bug: bad sched_wakeup event count') + + # Parse again without the window + trace1 = trappy.FTrace( + events=['sched_wakeup'], + window=(0, None)) + + self.assertEqual(len(trace1.sched_wakeup.data_frame), 2) diff --git a/tests/trace_sched.txt.cache/CpuIdle.csv b/tests/trace_sched.txt.cache/CpuIdle.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/CpuIdle.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/CpuInPower.csv b/tests/trace_sched.txt.cache/CpuInPower.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/CpuInPower.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/CpuOutPower.csv b/tests/trace_sched.txt.cache/CpuOutPower.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/CpuOutPower.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/DevfreqInPower.csv b/tests/trace_sched.txt.cache/DevfreqInPower.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/DevfreqInPower.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/DevfreqOutPower.csv b/tests/trace_sched.txt.cache/DevfreqOutPower.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/DevfreqOutPower.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/PIDController.csv b/tests/trace_sched.txt.cache/PIDController.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/PIDController.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/SchedContribScaleFactor.csv b/tests/trace_sched.txt.cache/SchedContribScaleFactor.csv new file mode 100644 index 0000000..a1764fe --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedContribScaleFactor.csv @@ -0,0 +1,2 @@ +Time,__comm,__cpu,__pid,cpu,cpu_scale_factor,freq_scale_factor +0.000167999999576,<idle>,0,0,0,1024,426 diff --git a/tests/trace_sched.txt.cache/SchedCpuCapacity.csv b/tests/trace_sched.txt.cache/SchedCpuCapacity.csv new file mode 100644 index 0000000..4b75c6a --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedCpuCapacity.csv @@ -0,0 +1,2 @@ +Time,__comm,__cpu,__pid,capacity,cpu,rt_capacity +0.000293999999485,trace-cmd,3,3519,430,3,1024 diff --git a/tests/trace_sched.txt.cache/SchedCpuFrequency.csv b/tests/trace_sched.txt.cache/SchedCpuFrequency.csv new file mode 100644 index 0000000..dbb941d --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedCpuFrequency.csv @@ -0,0 +1,2 @@ +Time,__comm,__cpu,__pid,cpu,frequency +0.0383590000001,kworker/0:0,0,3410,0,600000 diff --git a/tests/trace_sched.txt.cache/SchedLoadAvgCpu.csv b/tests/trace_sched.txt.cache/SchedLoadAvgCpu.csv new file mode 100644 index 0000000..54a9596 --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedLoadAvgCpu.csv @@ -0,0 +1,2 @@ +Time,__comm,__cpu,__pid,cpu,load,utilization +1.99999976758e-06,sshd,0,2962,0,13,18 diff --git a/tests/trace_sched.txt.cache/SchedLoadAvgSchedGroup.csv b/tests/trace_sched.txt.cache/SchedLoadAvgSchedGroup.csv new file mode 100644 index 0000000..fc57841 --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedLoadAvgSchedGroup.csv @@ -0,0 +1,2 @@ +Time,__comm,__cpu,__pid,cpus,load,utilization +0.0,rcuos/2,1,22,00000002,0,0 diff --git a/tests/trace_sched.txt.cache/SchedLoadAvgTask.csv b/tests/trace_sched.txt.cache/SchedLoadAvgTask.csv new file mode 100644 index 0000000..8b3ccfe --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedLoadAvgTask.csv @@ -0,0 +1,2 @@ +Time,__comm,__cpu,__pid,avg_period,comm,load,pid,runnable_avg_sum,running_avg_sum,utilization +9.99999429041e-07,trace-cmd,4,2971,48595,sshd,0,2962,0,0,0 diff --git a/tests/trace_sched.txt.cache/SchedMigrateTask.csv b/tests/trace_sched.txt.cache/SchedMigrateTask.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedMigrateTask.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/SchedSwitch.csv b/tests/trace_sched.txt.cache/SchedSwitch.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedSwitch.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/SchedWakeup.csv b/tests/trace_sched.txt.cache/SchedWakeup.csv new file mode 100644 index 0000000..6210734 --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedWakeup.csv @@ -0,0 +1,3 @@ +Time,__comm,__cpu,__pid,comm,pid,prio,success,target_cpu +0.0814890000001,<idle>,1,0,rcu_preempt,7,120,1,1 +1.981491,<idle>,1,0,rcu_preempt,7,120,1,1 diff --git a/tests/trace_sched.txt.cache/SchedWakeupNew.csv b/tests/trace_sched.txt.cache/SchedWakeupNew.csv new file mode 100644 index 0000000..4ea006b --- /dev/null +++ b/tests/trace_sched.txt.cache/SchedWakeupNew.csv @@ -0,0 +1,3 @@ +Time,__comm,__cpu,__pid,comm,pid,prio,success,target_cpu +0.000152999999955,<...>,0,19427,shutils,19428,120,1,2 +1.975373,<...>,0,19427,shutils,19428,120,1,2 diff --git a/tests/trace_sched.txt.cache/Thermal.csv b/tests/trace_sched.txt.cache/Thermal.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/Thermal.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/ThermalGovernor.csv b/tests/trace_sched.txt.cache/ThermalGovernor.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/trace_sched.txt.cache/ThermalGovernor.csv @@ -0,0 +1 @@ +"" diff --git a/tests/trace_sched.txt.cache/md5sum b/tests/trace_sched.txt.cache/md5sum new file mode 100644 index 0000000..9b481a3 --- /dev/null +++ b/tests/trace_sched.txt.cache/md5sum @@ -0,0 +1 @@ +47be9ccdd36fa0c3646b0d9b0f649da4
\ No newline at end of file |