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

Side by Side Diff: systrace/profile_chrome/profiler_unittest.py

Issue 2276263003: Pass in custom options to Systrace agents (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: Created 4 years, 3 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import tempfile 6 import tempfile
7 import unittest 7 import unittest
8 import zipfile 8 import zipfile
9 9
10 from profile_chrome import profiler 10 from profile_chrome import profiler
11 from profile_chrome import ui 11 from profile_chrome import ui
12 from systrace import trace_result 12 from systrace import trace_result
13 13
14 14
15 class FakeAgent(object): 15 class FakeAgent(object):
16 def __init__(self, contents='fake-contents'): 16 def __init__(self, contents='fake-contents'):
17 self.contents = contents 17 self.contents = contents
18 self.stopped = False 18 self.stopped = False
19 self.filename = None 19 self.filename = None
20 self.options = None 20 self.config = None
21 self.categories = None
22 self.timeout = None 21 self.timeout = None
23 22
24 def StartAgentTracing(self, options, categories, timeout=None): 23 def StartAgentTracing(self, config, timeout=None):
25 self.options = options 24 self.config = config
26 self.categories = categories
27 self.timeout = timeout 25 self.timeout = timeout
28 26
29 # pylint: disable=unused-argument 27 # pylint: disable=unused-argument
30 def StopAgentTracing(self, timeout=None): 28 def StopAgentTracing(self, timeout=None):
31 self.stopped = True 29 self.stopped = True
32 30
33 # pylint: disable=unused-argument 31 # pylint: disable=unused-argument
34 def GetResults(self, timeout=None): 32 def GetResults(self, timeout=None):
35 trace_data = open(self.PullTrace()).read() 33 trace_data = open(self.PullTrace()).read()
36 return trace_result.TraceResult('fakeData', trace_data) 34 return trace_result.TraceResult('fakeData', trace_data)
(...skipping 16 matching lines...) Expand all
53 def __repr__(self): 51 def __repr__(self):
54 return 'faketrace' 52 return 'faketrace'
55 53
56 54
57 class ProfilerTest(unittest.TestCase): 55 class ProfilerTest(unittest.TestCase):
58 def setUp(self): 56 def setUp(self):
59 ui.EnableTestMode() 57 ui.EnableTestMode()
60 58
61 def testCaptureBasicProfile(self): 59 def testCaptureBasicProfile(self):
62 agent = FakeAgent() 60 agent = FakeAgent()
63 result = profiler.CaptureProfile([agent], 1) 61 result = profiler.CaptureProfile(None, [agent], 1)
64 62
65 try: 63 try:
66 self.assertTrue(agent.stopped) 64 self.assertTrue(agent.stopped)
67 self.assertTrue(os.path.exists(result)) 65 self.assertTrue(os.path.exists(result))
68 self.assertTrue(result.endswith('.html')) 66 self.assertTrue(result.endswith('.html'))
69 finally: 67 finally:
70 if os.path.exists(result): 68 if os.path.exists(result):
71 os.remove(result) 69 os.remove(result)
72 70
73 def testCaptureJsonProfile(self): 71 def testCaptureJsonProfile(self):
74 agent = FakeAgent() 72 agent = FakeAgent()
75 result = profiler.CaptureProfile([agent], 1, write_json=True) 73 result = profiler.CaptureProfile(None, [agent], 1, write_json=True)
76 74
77 try: 75 try:
78 self.assertFalse(result.endswith('.html')) 76 self.assertFalse(result.endswith('.html'))
79 with open(result) as f: 77 with open(result) as f:
80 self.assertEquals(f.read(), agent.contents) 78 self.assertEquals(f.read(), agent.contents)
81 finally: 79 finally:
82 if os.path.exists(result): 80 if os.path.exists(result):
83 os.remove(result) 81 os.remove(result)
84 82
85 def testCaptureMultipleProfiles(self): 83 def testCaptureMultipleProfiles(self):
86 agents = [FakeAgent('c1'), FakeAgent('c2')] 84 agents = [FakeAgent('c1'), FakeAgent('c2')]
87 result = profiler.CaptureProfile(agents, 1, write_json=True) 85 result = profiler.CaptureProfile(None, agents, 1, write_json=True)
88 86
89 try: 87 try:
90 self.assertTrue(result.endswith('.zip')) 88 self.assertTrue(result.endswith('.zip'))
91 self.assertTrue(zipfile.is_zipfile(result)) 89 self.assertTrue(zipfile.is_zipfile(result))
92 finally: 90 finally:
93 if os.path.exists(result): 91 if os.path.exists(result):
94 os.remove(result) 92 os.remove(result)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698