Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: systrace/systrace/agents/ftrace_agent_unittest.py

Issue 1776013005: [DO NOT COMMIT] Refactor systrace to support new clock sync design (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: fix categories issue Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « systrace/systrace/agents/ftrace_agent.py ('k') | systrace/systrace/run_systrace.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 import unittest
8
9 from systrace import systrace
10 from systrace.agents import ftrace_agent
11
12 SYSTRACE_HOST_CMD_DEFAULT = ['./systrace.py', '--target=linux']
13 FT_DIR = "/sys/kernel/debug/tracing/"
14 FT_EVENT_DIR = FT_DIR + "events/"
15 FT_TRACE_ON = FT_DIR + "tracing_on"
16 FT_TRACE = FT_DIR + "trace"
17 FT_BUFFER_SIZE = FT_DIR + "buffer_size_kb"
18
19
20 def make_test_io_interface(permitted_files):
21 class TestIoImpl(object):
22
23 @staticmethod
24 def writeFile(path, data):
25 permitted_files[path] = data
26
27 @staticmethod
28 def readFile(path):
29 if path in permitted_files:
30 return permitted_files[path]
31 else:
32 return ""
33
34 @staticmethod
35 def haveWritePermissions(path):
36 return path in permitted_files
37 return TestIoImpl
38
39
40 class FtraceAgentTest(unittest.TestCase):
41
42 def test_avail_categories(self):
43 # sched only has required events
44 permitted_files = {
45 FT_EVENT_DIR + "sched/sched_switch/enable": "0",
46 FT_EVENT_DIR + "sched/sched_wakeup/enable": "0"
47 }
48 io_interface = make_test_io_interface(permitted_files)
49 options, categories = systrace.parse_options(SYSTRACE_HOST_CMD_DEFAULT)
50 agent = ftrace_agent.FtraceAgent(options, categories, io_interface)
51 self.assertEqual(['sched'], agent._avail_categories())
52
53 # check for no available categories
54 permitted_files = {}
55 io_interface = make_test_io_interface(permitted_files)
56 options, categories = systrace.parse_options(SYSTRACE_HOST_CMD_DEFAULT)
57 agent = ftrace_agent.FtraceAgent(options, categories, io_interface)
58 self.assertEqual([], agent._avail_categories())
59
60 # block has some required, some optional events
61 permitted_files = {
62 FT_EVENT_DIR + "block/block_rq_complete/enable": "0",
63 FT_EVENT_DIR + "block/block_rq_issue/enable": "0"
64 }
65 io_interface = make_test_io_interface(permitted_files)
66 options, categories = systrace.parse_options(SYSTRACE_HOST_CMD_DEFAULT)
67 agent = ftrace_agent.FtraceAgent(options, categories, io_interface)
68 self.assertEqual(['disk'], agent._avail_categories())
69
70 def test_tracing_bootstrap(self):
71 workq_event_path = FT_EVENT_DIR + "workqueue/enable"
72 permitted_files = {
73 workq_event_path: "0",
74 FT_TRACE: "x"
75 }
76 io_interface = make_test_io_interface(permitted_files)
77 systrace_cmd = SYSTRACE_HOST_CMD_DEFAULT + ["workq"]
78 options, categories = systrace.parse_options(systrace_cmd)
79 agent = ftrace_agent.FtraceAgent(options, categories, io_interface)
80 self.assertEqual(['workq'], agent._avail_categories())
81
82 # confirm tracing is enabled, buffer is cleared
83 agent.start()
84 self.assertEqual(permitted_files[FT_TRACE_ON], "1")
85 self.assertEqual(permitted_files[FT_TRACE], "")
86
87 # fill in file with dummy contents
88 dummy_trace = "trace_contents"
89 permitted_files[FT_TRACE] = dummy_trace
90
91 # confirm tracing is disabled
92 agent.collect_result()
93 self.assertEqual(permitted_files[FT_TRACE_ON], "0")
94
95 # confirm trace is expected, and read from fs
96 self.assertTrue(agent.expect_trace())
97 self.assertEqual(agent.get_trace_data(), dummy_trace)
98
99 # confirm buffer size is reset to 1
100 self.assertEqual(permitted_files[FT_BUFFER_SIZE], "1")
101
102 def test_tracing_event_enable_disable(self):
103 # turn on irq tracing
104 ipi_event_path = FT_EVENT_DIR + "ipi/enable"
105 irq_event_path = FT_EVENT_DIR + "irq/enable"
106 permitted_files = {
107 ipi_event_path: "0",
108 irq_event_path: "0"
109 }
110 io_interface = make_test_io_interface(permitted_files)
111 systrace_cmd = SYSTRACE_HOST_CMD_DEFAULT + ["irq"]
112 options, categories = systrace.parse_options(systrace_cmd)
113 agent = ftrace_agent.FtraceAgent(options, categories, io_interface)
114 self.assertEqual(['irq'], agent._avail_categories())
115
116 # confirm all the event nodes are turned on during tracing
117 agent.start()
118 self.assertEqual(permitted_files[irq_event_path], "1")
119 self.assertEqual(permitted_files[ipi_event_path], "1")
120
121 # and then turned off when completed.
122 agent.collect_result()
123 self.assertEqual(permitted_files[irq_event_path], "0")
124 self.assertEqual(permitted_files[ipi_event_path], "0")
125
126 def test_trace_time(self):
127 systrace_cmd = SYSTRACE_HOST_CMD_DEFAULT + ['-t', '10']
128 options, categories = systrace.parse_options(systrace_cmd)
129 agent = ftrace_agent.FtraceAgent(options, categories)
130 self.assertEqual(agent._get_trace_time(), 10)
131
132 def test_buffer_size(self):
133 systrace_cmd = SYSTRACE_HOST_CMD_DEFAULT + ['-b', '16000']
134 options, categories = systrace.parse_options(systrace_cmd)
135 agent = ftrace_agent.FtraceAgent(options, categories)
136 self.assertEqual(agent._get_trace_buffer_size(), 16000)
OLDNEW
« no previous file with comments | « systrace/systrace/agents/ftrace_agent.py ('k') | systrace/systrace/run_systrace.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698