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

Unified Diff: systrace/systrace/systrace_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, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « systrace/systrace/systrace_tracing_controller.py ('k') | systrace/systrace/tracing_agents/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: systrace/systrace/systrace_unittest.py
diff --git a/systrace/systrace/systrace_unittest.py b/systrace/systrace/systrace_unittest.py
new file mode 100755
index 0000000000000000000000000000000000000000..54b8c51eb292c596e24b48e380bbea553ffc23e4
--- /dev/null
+++ b/systrace/systrace/systrace_unittest.py
@@ -0,0 +1,127 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+import logging
+from systrace import tracing_controller
+from systrace.tracing_agents import TracingAgent, TraceResults
+
+from collections import namedtuple
+
+tmout = namedtuple('tmout', ['timeout', 'collection_timeout'])
+base_tmout = tmout(10, 30)
+
+class FakeTracingAgent(TracingAgent):
+ def __init__(self, name, clock_sync=True):
+ super(FakeTracingAgent, self).__init__()
+ self._name = name
+ self._clock_sync = clock_sync
+ self._sync_seen = False
+ def StartAgentTracing(self, options, categories, timeout=10):
+ # pylint: disable=unused-variable
+ # options, categories variables not used in test, but we still
+ # need to have them to match the interface
+ return True
+ def StopAgentTracing(self, timeout=10):
+ return True
+ def GetResults(self, timeout=30):
+ return TraceResults(self._name,
+ 'Sync' if self._sync_seen else 'NoSync')
+ def SupportsExplicitClockSync(self):
+ return self._clock_sync
+ def RecordClockSyncMarker(self, sync_id, callback):
+ if not self._clock_sync:
+ raise NotImplementedError
+ self._sync_seen = True
+ callback(1.0, sync_id)
+
+def _GetSyncCount(controller):
+ result = 0
+ for x in controller.GetResults().trace_data:
+ if x['name'] == 'clock_sync':
+ result += 1
+ return result
+
+class SystraceTest(unittest.TestCase):
+
+ def testStartTracing(self):
+ cont = tracing_controller.TracingController(base_tmout, None, [])
+ self.assertFalse(cont.trace_in_progress)
+ cont.StartTracing()
+ self.assertTrue(cont.trace_in_progress)
+ cont.StopTracing()
+
+ def testStopFirst(self):
+ cont = tracing_controller.TracingController(base_tmout, None, [])
+ self.assertRaises(AssertionError, cont.StopTracing)
+
+ def testDoubleStart(self):
+ cont = tracing_controller.TracingController(base_tmout, None, [])
+ cont.StartTracing()
+ self.assertRaises(AssertionError, cont.StartTracing)
+ cont.StopTracing()
+
+ def testDoubleStop(self):
+ cont = tracing_controller.TracingController(base_tmout, None, [])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertRaises(AssertionError, cont.StopTracing)
+
+ def testNoAgents(self):
+ cont = tracing_controller.TracingController(base_tmout, None, [])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 0)
+
+ def testNoSupportedAgents(self):
+ cont = tracing_controller.TracingController(base_tmout, None,
+ [FakeTracingAgent('1', False)])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 0)
+
+ def testOneSupportedAgent(self):
+ cont = tracing_controller.TracingController(base_tmout, None,
+ [FakeTracingAgent('1', False),
+ FakeTracingAgent('2', True)])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 1)
+
+ def testTwoSupportedAgents(self):
+ cont = tracing_controller.TracingController(base_tmout, None,
+ [FakeTracingAgent('1', True),
+ FakeTracingAgent('2', False),
+ FakeTracingAgent('3', True)])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 2)
+
+ def testOutputs(self):
+ cont = tracing_controller.TracingController(base_tmout, None,
+ [FakeTracingAgent('1', True),
+ FakeTracingAgent('2', False),
+ FakeTracingAgent('3', True)])
+ cont.StartTracing()
+ cont.StopTracing()
+ results = cont._all_results
+ self.assertEqual(results['1'], 'Sync')
+ self.assertEqual(results['2'], 'NoSync')
+ self.assertEqual(results['3'], 'Sync')
+
+ def testMultipleSyncCycles(self):
+ cont = tracing_controller.TracingController(base_tmout, None,
+ [FakeTracingAgent('1', True),
+ FakeTracingAgent('2', False),
+ FakeTracingAgent('3', True)])
+ cont.StartTracing()
+ cont._IssueClockSyncMarker()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 4)
+
+if __name__ == "__main__":
+ logging.getLogger().setLevel(logging.DEBUG)
+ unittest.main(verbosity=2)
« no previous file with comments | « systrace/systrace/systrace_tracing_controller.py ('k') | systrace/systrace/tracing_agents/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698