Index: common/battor/battor/battor_stress_test.py |
diff --git a/common/battor/battor/battor_stress_test.py b/common/battor/battor/battor_stress_test.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8f5e31a4ad58780451260d7cb324fa537f280e95 |
--- /dev/null |
+++ b/common/battor/battor/battor_stress_test.py |
@@ -0,0 +1,74 @@ |
+# Copyright 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 logging |
+import platform |
+import random |
+import os |
+import sys |
+import time |
+import unittest |
+ |
+if __name__ == '__main__': |
+ sys.path.append( |
+ os.path.join(os.path.dirname(__file__), '..')) |
+ |
+from battor import battor_wrapper |
+from devil.utils import battor_device_mapping |
+from devil.utils import find_usb_devices |
+ |
+def _CreateBattOrWrapper(): |
+ telemetry_platform = None |
+ battor_list = None |
+ |
+ sys_platform = platform.system() |
+ if 'Win' in sys_platform: |
+ telemetry_platform = 'win' |
+ elif 'Linux' in sys_platform: |
+ telemetry_platform = 'linux' |
+ elif 'Darwin' in sys_platform: |
+ telemetry_platform = 'mac' |
+ |
+ if not battor_wrapper.IsBattOrConnected(telemetry_platform): |
+ return None |
+ |
+ # On Linux, there can be multiple BattOrs attached, so we need to explicitly |
+ # specify which BattOr to use. |
+ battor_path = None |
+ if telemetry_platform == 'linux': |
+ device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap() |
+ battor_list = battor_device_mapping.GetBattorList(device_tree) |
+ battor_path = '/dev/%s' % battor_list[0] |
+ |
+ return battor_wrapper.BattOrWrapper( |
+ telemetry_platform, battor_path=battor_path) |
+ |
+def Main(argv): |
+ while True: |
+ try: |
+ battor = _CreateBattOrWrapper() |
+ |
+ if not battor: |
+ print "Failed to create BattOrWrapper: is a BattOr attached?" |
+ break |
+ |
+ duration = random.randint(15, 180) |
+ battor.StartShell() |
+ battor.StartTracing() |
+ |
+ time.sleep(duration) |
+ battor.RecordClockSyncMarker('abc') |
+ time.sleep(0.5) |
+ battor.StopTracing() |
+ battor.CollectTraceData() |
+ print "PASS for duration = %s" % (duration) |
+ |
+ except KeyboardInterrupt: |
+ raise |
+ except Exception as e: |
+ print 'FAIL for duration = %s, exception: %s' % (duration, e) |
+ raise |
+ |
+if __name__ == '__main__': |
+ sys.exit(Main(sys.argv)) |