| 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 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 """ | 995 """ |
| 997 assert '"' not in file_name, 'file_name cannot contain double quotes' | 996 assert '"' not in file_name, 'file_name cannot contain double quotes' |
| 998 status = self._adb.SendShellCommand( | 997 status = self._adb.SendShellCommand( |
| 999 '\'test -f "%s"; echo $?\'' % (file_name)) | 998 '\'test -f "%s"; echo $?\'' % (file_name)) |
| 1000 if 'test: not found' not in status: | 999 if 'test: not found' not in status: |
| 1001 return int(status) == 0 | 1000 return int(status) == 0 |
| 1002 | 1001 |
| 1003 status = self._adb.SendShellCommand( | 1002 status = self._adb.SendShellCommand( |
| 1004 '\'ls "%s" >/dev/null 2>&1; echo $?\'' % (file_name)) | 1003 '\'ls "%s" >/dev/null 2>&1; echo $?\'' % (file_name)) |
| 1005 return int(status) == 0 | 1004 return int(status) == 0 |
| 1006 | |
| 1007 def RunMonkey(self, package_name, category=None, throttle=100, seed=None, | |
| 1008 event_count=10000, verbosity=1, extra_args=''): | |
| 1009 """Runs monkey test for a given package. | |
| 1010 | |
| 1011 Args: | |
| 1012 package_name: Allowed package. | |
| 1013 category: A list of allowed categories. | |
| 1014 throttle: Delay between events (ms). | |
| 1015 seed: Seed value for pseduo-random generator. Same seed value | |
| 1016 generates the same sequence of events. Seed is randomized by | |
| 1017 default. | |
| 1018 event_count: Number of events to generate. | |
| 1019 verbosity: Verbosity level [0-3]. | |
| 1020 extra_args: A string of other args to pass to the command verbatim. | |
| 1021 | |
| 1022 Returns: | |
| 1023 Output of the test run. | |
| 1024 """ | |
| 1025 category = category or [] | |
| 1026 seed = seed or random.randint(1, 100) | |
| 1027 | |
| 1028 cmd = ['monkey', | |
| 1029 '-p %s' % package_name, | |
| 1030 ' '.join(['-c %s' % c for c in category]), | |
| 1031 '--throttle %d' % throttle, | |
| 1032 '-s %d' % seed, | |
| 1033 '-v ' * verbosity, | |
| 1034 '--monitor-native-crashes', | |
| 1035 '--kill-process-after-error', | |
| 1036 extra_args, | |
| 1037 '%d' % event_count] | |
| 1038 return self.RunShellCommand(' '.join(cmd), | |
| 1039 timeout_time=event_count*throttle*1.5) | |
| OLD | NEW |