Chromium Code Reviews| Index: systrace/systrace/tracing_agents/ftrace_agent_unittest.py |
| diff --git a/systrace/systrace/agents/ftrace_agent_unittest.py b/systrace/systrace/tracing_agents/ftrace_agent_unittest.py |
| old mode 100644 |
| new mode 100755 |
| similarity index 71% |
| rename from systrace/systrace/agents/ftrace_agent_unittest.py |
| rename to systrace/systrace/tracing_agents/ftrace_agent_unittest.py |
| index 9e8ea607aedbdbaab983dfe46cc7c3c922041b75..d5b4d2d08232d53e242917416122ce1202c0e323 |
| --- a/systrace/systrace/agents/ftrace_agent_unittest.py |
| +++ b/systrace/systrace/tracing_agents/ftrace_agent_unittest.py |
| @@ -5,9 +5,9 @@ |
| # found in the LICENSE file. |
| import unittest |
| - |
| -from systrace import systrace |
| -from systrace.agents import ftrace_agent |
| +import logging |
| +from systrace import run_systrace |
| +from systrace.tracing_agents import ftrace_agent |
| SYSTRACE_HOST_CMD_DEFAULT = ['./systrace.py', '--target=linux'] |
| FT_DIR = "/sys/kernel/debug/tracing/" |
| @@ -34,6 +34,11 @@ def make_test_io_interface(permitted_files): |
| @staticmethod |
| def haveWritePermissions(path): |
| return path in permitted_files |
| + |
| + @staticmethod |
| + def checkedWriteFile(path, data): |
|
Zhen Wang
2016/03/30 16:14:08
nit: checkAndWriteFile
alexandermont
2016/03/30 19:33:25
Done
|
| + permitted_files[path] = data |
| + |
| return TestIoImpl |
| @@ -46,15 +51,13 @@ class FtraceAgentTest(unittest.TestCase): |
| FT_EVENT_DIR + "sched/sched_wakeup/enable": "0" |
| } |
| io_interface = make_test_io_interface(permitted_files) |
| - options, categories = systrace.parse_options(SYSTRACE_HOST_CMD_DEFAULT) |
| - agent = ftrace_agent.FtraceAgent(options, categories, io_interface) |
| + agent = ftrace_agent.FtraceAgent(io_interface) |
| self.assertEqual(['sched'], agent._avail_categories()) |
| # check for no available categories |
| permitted_files = {} |
| io_interface = make_test_io_interface(permitted_files) |
| - options, categories = systrace.parse_options(SYSTRACE_HOST_CMD_DEFAULT) |
| - agent = ftrace_agent.FtraceAgent(options, categories, io_interface) |
| + agent = ftrace_agent.FtraceAgent(io_interface) |
| self.assertEqual([], agent._avail_categories()) |
| # block has some required, some optional events |
| @@ -63,8 +66,7 @@ class FtraceAgentTest(unittest.TestCase): |
| FT_EVENT_DIR + "block/block_rq_issue/enable": "0" |
| } |
| io_interface = make_test_io_interface(permitted_files) |
| - options, categories = systrace.parse_options(SYSTRACE_HOST_CMD_DEFAULT) |
| - agent = ftrace_agent.FtraceAgent(options, categories, io_interface) |
| + agent = ftrace_agent.FtraceAgent(io_interface) |
| self.assertEqual(['disk'], agent._avail_categories()) |
| def test_tracing_bootstrap(self): |
| @@ -75,12 +77,12 @@ class FtraceAgentTest(unittest.TestCase): |
| } |
| io_interface = make_test_io_interface(permitted_files) |
| systrace_cmd = SYSTRACE_HOST_CMD_DEFAULT + ["workq"] |
| - options, categories = systrace.parse_options(systrace_cmd) |
| - agent = ftrace_agent.FtraceAgent(options, categories, io_interface) |
| + options, categories = run_systrace.parse_options(systrace_cmd) |
| + agent = ftrace_agent.FtraceAgent(io_interface) |
| self.assertEqual(['workq'], agent._avail_categories()) |
| # confirm tracing is enabled, buffer is cleared |
| - agent.start() |
| + agent.StartAgentTracing(options, categories) |
| self.assertEqual(permitted_files[FT_TRACE_ON], "1") |
| self.assertEqual(permitted_files[FT_TRACE], "") |
| @@ -89,12 +91,11 @@ class FtraceAgentTest(unittest.TestCase): |
| permitted_files[FT_TRACE] = dummy_trace |
| # confirm tracing is disabled |
| - agent.collect_result() |
| + agent.StopAgentTracing() |
| self.assertEqual(permitted_files[FT_TRACE_ON], "0") |
| # confirm trace is expected, and read from fs |
| - self.assertTrue(agent.expect_trace()) |
| - self.assertEqual(agent.get_trace_data(), dummy_trace) |
| + self.assertEqual(agent.GetResults().trace_data, dummy_trace) |
| # confirm buffer size is reset to 1 |
| self.assertEqual(permitted_files[FT_BUFFER_SIZE], "1") |
| @@ -109,28 +110,25 @@ class FtraceAgentTest(unittest.TestCase): |
| } |
| io_interface = make_test_io_interface(permitted_files) |
| systrace_cmd = SYSTRACE_HOST_CMD_DEFAULT + ["irq"] |
| - options, categories = systrace.parse_options(systrace_cmd) |
| - agent = ftrace_agent.FtraceAgent(options, categories, io_interface) |
| + options, categories = run_systrace.parse_options(systrace_cmd) |
| + agent = ftrace_agent.FtraceAgent(io_interface) |
| self.assertEqual(['irq'], agent._avail_categories()) |
| # confirm all the event nodes are turned on during tracing |
| - agent.start() |
| + agent.StartAgentTracing(options, categories) |
| self.assertEqual(permitted_files[irq_event_path], "1") |
| self.assertEqual(permitted_files[ipi_event_path], "1") |
| # and then turned off when completed. |
| - agent.collect_result() |
| + agent.StopAgentTracing() |
| self.assertEqual(permitted_files[irq_event_path], "0") |
| self.assertEqual(permitted_files[ipi_event_path], "0") |
| - def test_trace_time(self): |
| - systrace_cmd = SYSTRACE_HOST_CMD_DEFAULT + ['-t', '10'] |
| - options, categories = systrace.parse_options(systrace_cmd) |
| - agent = ftrace_agent.FtraceAgent(options, categories) |
| - self.assertEqual(agent._get_trace_time(), 10) |
| - |
| def test_buffer_size(self): |
| systrace_cmd = SYSTRACE_HOST_CMD_DEFAULT + ['-b', '16000'] |
| - options, categories = systrace.parse_options(systrace_cmd) |
| - agent = ftrace_agent.FtraceAgent(options, categories) |
| - self.assertEqual(agent._get_trace_buffer_size(), 16000) |
| + options, _ = run_systrace.parse_options(systrace_cmd) |
| + self.assertEqual(ftrace_agent._get_trace_buffer_size(options), 16000) |
| + |
| +if __name__ == "__main__": |
| + logging.getLogger().setLevel(logging.DEBUG) |
| + unittest.main(verbosity=2) |