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

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: add timeouts and fix tests 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..b73165860235563accf062e3360e15344302d463
--- /dev/null
+++ b/systrace/systrace/systrace_unittest.py
@@ -0,0 +1,118 @@
+#!/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'])
+
+class FakeTracingAgent(TracingAgent):
+ def __init__(self, name, clock_sync=True):
+ super(FakeTracingAgent, self).__init__(tmout(10, 30), None)
+ self._name = name
+ self._clock_sync = clock_sync
+ self._sync_seen = False
+ def _StartAgentTracing_func(self):
+ return True
+ def _StopAgentTracing_func(self):
+ return True
+ def _GetResults_func(self):
+ 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([])
+ 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('1', False)])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 0)
+
+ def testOneSupportedAgent(self):
+ cont = tracing_controller.TracingController([FakeTracingAgent('1', False),
+ FakeTracingAgent('2', True)])
+ cont.StartTracing()
+ cont.StopTracing()
+ self.assertEqual(_GetSyncCount(cont), 1)
+
+ def testTwoSupportedAgents(self):
+ cont = tracing_controller.TracingController([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([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([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)

Powered by Google App Engine
This is Rietveld 408576698