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

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

Issue 2295913002: Enable some profile_chrome unit tests on Trybots (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: Add Chris as owner of Systrace bin directory 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 2016 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 optparse
6 import tempfile 6 import tempfile
7 import unittest
8 import zipfile
9 7
10 from profile_chrome import profiler
11 from profile_chrome import ui
12 from systrace import trace_result 8 from systrace import trace_result
9 from systrace import tracing_agents
13 10
14 11
15 class FakeAgent(object): 12 class FakeAgent(object):
16 def __init__(self, contents='fake-contents'): 13 def __init__(self, contents='fake-contents'):
17 self.contents = contents 14 self.contents = contents
18 self.stopped = False 15 self.stopped = False
19 self.filename = None 16 self.filename = None
20 self.config = None 17 self.config = None
21 self.timeout = None 18 self.timeout = None
22 19
(...skipping 24 matching lines...) Expand all
47 44
48 # pylint: disable=unused-argument, no-self-use 45 # pylint: disable=unused-argument, no-self-use
49 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): 46 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback):
50 print ('Clock sync marker cannot be recorded since explicit clock sync ' 47 print ('Clock sync marker cannot be recorded since explicit clock sync '
51 'is not supported.') 48 'is not supported.')
52 49
53 def __repr__(self): 50 def __repr__(self):
54 return 'faketrace' 51 return 'faketrace'
55 52
56 53
57 class ProfilerTest(unittest.TestCase): 54 class FakeConfig(tracing_agents.TracingConfig):
58 def setUp(self): 55 def __init__(self):
59 ui.EnableTestMode() 56 tracing_agents.TracingConfig.__init__(self)
60 57
61 def testCaptureBasicProfile(self):
62 agent = FakeAgent()
63 result = profiler.CaptureProfile(None, [agent], 1)
64 58
65 try: 59 # pylint: disable=unused-argument
66 self.assertTrue(agent.stopped) 60 def try_create_agent(config):
67 self.assertTrue(os.path.exists(result)) 61 return FakeAgent()
68 self.assertTrue(result.endswith('.html'))
69 finally:
70 if os.path.exists(result):
71 os.remove(result)
72 62
73 def testCaptureJsonProfile(self): 63 def add_options(parser):
74 agent = FakeAgent() 64 options = optparse.OptionGroup(parser, 'Fake options.')
75 result = profiler.CaptureProfile(None, [agent], 1, write_json=True) 65 return options
76 66
77 try: 67 # pylint: disable=unused-argument
78 self.assertFalse(result.endswith('.html')) 68 def get_config(options):
79 with open(result) as f: 69 return FakeConfig()
80 self.assertEquals(f.read(), agent.contents)
81 finally:
82 if os.path.exists(result):
83 os.remove(result)
84
85 def testCaptureMultipleProfiles(self):
86 agents = [FakeAgent('c1'), FakeAgent('c2')]
87 result = profiler.CaptureProfile(None, agents, 1, write_json=True)
88
89 try:
90 self.assertTrue(result.endswith('.zip'))
91 self.assertTrue(zipfile.is_zipfile(result))
92 finally:
93 if os.path.exists(result):
94 os.remove(result)
OLDNEW
« no previous file with comments | « systrace/profile_chrome/ddms_tracing_agent_unittest.py ('k') | systrace/profile_chrome/fake_agent_2.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698