| 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)
|
|
|