Index: tools/telemetry/telemetry/core/platform/timeline_objects_unittest.py |
diff --git a/tools/telemetry/telemetry/core/platform/timeline_objects_unittest.py b/tools/telemetry/telemetry/core/platform/timeline_objects_unittest.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..19029a4add159569bc03a3113844ea7001e7347c |
--- /dev/null |
+++ b/tools/telemetry/telemetry/core/platform/timeline_objects_unittest.py |
@@ -0,0 +1,48 @@ |
+# Copyright 2014 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 json |
+import unittest |
+import StringIO |
+ |
+from telemetry.core.platform import timeline_objects |
+ |
+ |
+class PlatformTimeLineObjectTest(unittest.TestCase): |
+ |
+ def testIdleWakeupCountMath(self): |
+ pid1 = 1 |
+ pid2 = 2 |
+ |
+ a = timeline_objects.IdleStatsData(pid1, 5) |
+ b = timeline_objects.IdleStatsData(pid2, 1) |
+ c = timeline_objects.IdleStatsData(pid1, 1) |
+ |
+ # Test addition. |
+ addition_result = (a + b).idle_wakeup_count_by_pid |
+ self.assertEquals(5, addition_result[pid1]) |
+ self.assertEquals(1, addition_result[pid2]) |
+ self.assertEquals(2, len(addition_result.keys())) |
+ |
+ # Test subtraction. |
+ subtraction_result = ((a + b) - c).idle_wakeup_count_by_pid |
+ self.assertEquals(4, subtraction_result[pid1]) |
+ self.assertEquals(1, len(subtraction_result.keys())) |
+ |
+ self.assertEquals(6, (a + b).IdleWakeupCount()) |
+ |
+ def testIdleWakeupCountReporting(self): |
+ pid1 = 1 |
+ pid2 = 2 |
+ |
+ a = timeline_objects.IdleStatsData(pid1, 1) |
+ b = timeline_objects.IdleStatsData(pid2, 99) |
+ c = a + b |
+ self.assertEquals(100, c.IdleWakeupCount()) |
+ |
+ # Test serialization. |
+ output = StringIO.StringIO() |
+ c.Serialize(output) |
+ deserialized = json.loads(output.getvalue()) |
+ self.assertEquals(100, deserialized['idleWakeupCount']) |