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

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: changes from code review 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
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..8a5ce36df6c3380862c145e1b5740dfa4cb7164c
--- /dev/null
+++ b/systrace/systrace/systrace_unittest.py
@@ -0,0 +1,108 @@
+#!/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_agent, tracing_controller
+
+
+class FakeTracingAgent(tracing_agent.TracingAgent):
+ def __init__(self, clock_sync=True):
+ super(FakeTracingAgent, self).__init__()
+ self._clock_sync = clock_sync
+ self._sync_seen = False
+ def StartAgentTracing(self):
+ pass
+ def StopAgentTracing(self):
+ pass
+ def GetResults(self):
+ return tracing_agent.TraceResults('trace-data',
+ 'Sync' if self._sync_seen else 'NoSync',
+ True)
+ def SupportsExplicitClockSync(self):
+ return self._clock_sync
+ def RecordClockSyncMarker(self, *_):
+ if not self._clock_sync:
+ raise NotImplementedError
+ self._sync_seen = True
+
+def _GetSyncCount(controller):
+ return controller.GetResults().trace_data.count('clock_sync')
+
+class SystraceTest(unittest.TestCase):
+
+ def testStartTracing(self):
+ cont = tracing_controller.TracingController([])
+ self.assertFalse(cont.trace_in_progress)
+ cont.StartTracing()
+ self.assertTrue(cont.trace_in_progress)
+ cont.StopTracing()
+
+ def testStopFirst(self):
+ cont = tracing_controller.TracingController([])
+ self.assertRaises(AssertionError, cont.StopTracing)
+
+ def testDoubleStart(self):
+ cont = tracing_controller.TracingController([])
+ cont.StartTracing()
+ self.assertRaises(AssertionError, cont.StartTracing)
+ cont.StopTracing()
+
+ def testDoubleStop(self):
+ cont = tracing_controller.TracingController([])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertRaises(AssertionError, cont.StopTracing)
+
+ def testNoAgents(self):
+ cont = tracing_controller.TracingController([])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 0)
+
+ def testNoSupportedAgents(self):
+ cont = tracing_controller.TracingController([FakeTracingAgent(False)])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 0)
+
+ def testOneSupportedAgent(self):
+ cont = tracing_controller.TracingController([FakeTracingAgent(False),
+ FakeTracingAgent(True)])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 1)
+
+ def testTwoSupportedAgents(self):
+ cont = tracing_controller.TracingController([FakeTracingAgent(True),
+ FakeTracingAgent(False),
+ FakeTracingAgent(True)])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 2)
+
+ def testOutputs(self):
+ cont = tracing_controller.TracingController([FakeTracingAgent(True),
+ FakeTracingAgent(False),
+ FakeTracingAgent(True)])
+ cont.StartTracing()
+ results = cont.StopTracing()
+ self.assertEqual(results[0].trace_data, 'Sync')
+ self.assertEqual(results[1].trace_data, 'NoSync')
+ self.assertEqual(results[2].trace_data, 'Sync')
+
+ def testMultipleSyncCycles(self):
+ cont = tracing_controller.TracingController([FakeTracingAgent(True),
+ FakeTracingAgent(False),
+ FakeTracingAgent(True)])
+ cont.StartTracing()
+ cont._IssueClockSyncMarker()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 4)
+
+if __name__ == "__main__":
+ logging.getLogger().setLevel(logging.DEBUG)
+ unittest.main(verbosity=2)

Powered by Google App Engine
This is Rietveld 408576698