OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import logging |
| 6 import platform |
| 7 import random |
| 8 import os |
| 9 import sys |
| 10 import time |
| 11 import unittest |
| 12 |
| 13 if __name__ == '__main__': |
| 14 sys.path.append( |
| 15 os.path.join(os.path.dirname(__file__), '..')) |
| 16 |
| 17 from battor import battor_wrapper |
| 18 from devil.utils import battor_device_mapping |
| 19 from devil.utils import find_usb_devices |
| 20 |
| 21 def _CreateBattOrWrapper(): |
| 22 telemetry_platform = None |
| 23 battor_list = None |
| 24 |
| 25 sys_platform = platform.system() |
| 26 if 'Win' in sys_platform: |
| 27 telemetry_platform = 'win' |
| 28 elif 'Linux' in sys_platform: |
| 29 telemetry_platform = 'linux' |
| 30 elif 'Darwin' in sys_platform: |
| 31 telemetry_platform = 'mac' |
| 32 |
| 33 if not battor_wrapper.IsBattOrConnected(telemetry_platform): |
| 34 return None |
| 35 |
| 36 # On Linux, there can be multiple BattOrs attached, so we need to explicitly |
| 37 # specify which BattOr to use. |
| 38 battor_path = None |
| 39 if telemetry_platform == 'linux': |
| 40 device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap() |
| 41 battor_list = battor_device_mapping.GetBattorList(device_tree) |
| 42 battor_path = '/dev/%s' % battor_list[0] |
| 43 |
| 44 return battor_wrapper.BattOrWrapper( |
| 45 telemetry_platform, battor_path=battor_path) |
| 46 |
| 47 def Main(argv): |
| 48 while True: |
| 49 try: |
| 50 battor = _CreateBattOrWrapper() |
| 51 |
| 52 if not battor: |
| 53 print "Failed to create BattOrWrapper: is a BattOr attached?" |
| 54 break |
| 55 |
| 56 duration = random.randint(15, 180) |
| 57 battor.StartShell() |
| 58 battor.StartTracing() |
| 59 |
| 60 time.sleep(duration) |
| 61 battor.RecordClockSyncMarker('abc') |
| 62 time.sleep(0.5) |
| 63 battor.StopTracing() |
| 64 battor.CollectTraceData() |
| 65 print "PASS for duration = %s" % (duration) |
| 66 |
| 67 except KeyboardInterrupt: |
| 68 raise |
| 69 except Exception as e: |
| 70 print 'FAIL for duration = %s, exception: %s' % (duration, e) |
| 71 raise |
| 72 |
| 73 if __name__ == '__main__': |
| 74 sys.exit(Main(sys.argv)) |
OLD | NEW |