| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
| 6 | 6 |
| 7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import collections | 10 import collections |
| 11 import datetime | 11 import datetime |
| 12 import logging | 12 import logging |
| 13 import os | 13 import os |
| 14 import random | |
| 15 import re | 14 import re |
| 16 import shlex | 15 import shlex |
| 17 import subprocess | 16 import subprocess |
| 18 import sys | 17 import sys |
| 19 import tempfile | 18 import tempfile |
| 20 import time | 19 import time |
| 21 | 20 |
| 22 import pexpect | 21 import pexpect |
| 23 import io_stats_parser | 22 import io_stats_parser |
| 24 | 23 |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 Args: | 1004 Args: |
| 1006 file_name: Full path of file to check. | 1005 file_name: Full path of file to check. |
| 1007 | 1006 |
| 1008 Returns: | 1007 Returns: |
| 1009 True if the file exists, False otherwise. | 1008 True if the file exists, False otherwise. |
| 1010 """ | 1009 """ |
| 1011 assert '"' not in file_name, 'file_name cannot contain double quotes' | 1010 assert '"' not in file_name, 'file_name cannot contain double quotes' |
| 1012 status = self._adb.SendShellCommand( | 1011 status = self._adb.SendShellCommand( |
| 1013 '\'test -f "%s"; echo $?\'' % (file_name)) | 1012 '\'test -f "%s"; echo $?\'' % (file_name)) |
| 1014 return int(status) == 0 | 1013 return int(status) == 0 |
| 1015 | |
| 1016 def RunMonkey(self, package_name, category=None, throttle=100, seed=None, | |
| 1017 event_count=10000, verbosity=1, extra_args=''): | |
| 1018 """Runs monkey test for a given package. | |
| 1019 | |
| 1020 Args: | |
| 1021 package_name: Allowed package. | |
| 1022 category: A list of allowed categories. | |
| 1023 throttle: Delay between events (ms). | |
| 1024 seed: Seed value for pseduo-random generator. Same seed value | |
| 1025 generates the same sequence of events. Seed is randomized by | |
| 1026 default. | |
| 1027 event_count: Number of events to generate. | |
| 1028 verbosity: Verbosity level [0-3]. | |
| 1029 extra_args: A string of other args to pass to the command verbatim. | |
| 1030 | |
| 1031 Returns: | |
| 1032 Output of the test run. | |
| 1033 """ | |
| 1034 category = category or [] | |
| 1035 seed = seed or random.randint(1, 100) | |
| 1036 | |
| 1037 cmd = ['monkey', | |
| 1038 '-p %s' % package_name, | |
| 1039 ' '.join(['-c %s' % c for c in category]), | |
| 1040 '--throttle %d' % throttle, | |
| 1041 '-s %d' % seed, | |
| 1042 '-v ' * verbosity, | |
| 1043 '--monitor-native-crashes', | |
| 1044 '--kill-process-after-error', | |
| 1045 extra_args, | |
| 1046 '%d' % event_count] | |
| 1047 return self.RunShellCommand(' '.join(cmd), | |
| 1048 timeout_time=event_count*throttle*1.5) | |
| OLD | NEW |