diff options
Diffstat (limited to 'catapult/devil/devil/android/device_utils_test.py')
-rwxr-xr-x | catapult/devil/devil/android/device_utils_test.py | 439 |
1 files changed, 284 insertions, 155 deletions
diff --git a/catapult/devil/devil/android/device_utils_test.py b/catapult/devil/devil/android/device_utils_test.py index 88c91b51..e0ed666c 100755 --- a/catapult/devil/devil/android/device_utils_test.py +++ b/catapult/devil/devil/android/device_utils_test.py @@ -316,28 +316,32 @@ class DeviceUtilsHasRootTest(DeviceUtilsTest): def testHasRoot_true(self): with self.patch_call(self.call.device.product_name, return_value='notasailfish'), ( - self.assertCall(self.call.adb.Shell('ls /root'), 'foo\n')): + self.assertCall(self.call.adb.Shell( + 'ls /root', ensure_logs_on_timeout=False), 'foo\n')): self.assertTrue(self.device.HasRoot()) def testhasRootSpecial_true(self): with self.patch_call(self.call.device.product_name, return_value='sailfish'), ( - self.assertCall(self.call.adb.Shell('getprop service.adb.root'), - '1\n')): + self.assertCall( + self.call.adb.Shell('getprop service.adb.root', + ensure_logs_on_timeout=False), '1\n')): self.assertTrue(self.device.HasRoot()) def testHasRoot_false(self): with self.patch_call(self.call.device.product_name, return_value='notasailfish'), ( - self.assertCall(self.call.adb.Shell('ls /root'), - self.ShellError())): + self.assertCall( + self.call.adb.Shell( + 'ls /root', ensure_logs_on_timeout=False), self.ShellError())): self.assertFalse(self.device.HasRoot()) def testHasRootSpecial_false(self): with self.patch_call(self.call.device.product_name, return_value='sailfish'), ( - self.assertCall(self.call.adb.Shell('getprop service.adb.root'), - '\n')): + self.assertCall( + self.call.adb.Shell( + 'getprop service.adb.root', ensure_logs_on_timeout=False), '\n')): self.assertFalse(self.device.HasRoot()) @@ -445,7 +449,8 @@ class DeviceUtils_GetApplicationVersionTest(DeviceUtilsTest): def test_GetApplicationVersion_exists(self): with self.assertCalls( - (self.call.adb.Shell('dumpsys package com.android.chrome'), + (self.call.adb.Shell( + 'dumpsys package com.android.chrome', ensure_logs_on_timeout=False), 'Packages:\n' ' Package [com.android.chrome] (3901ecfb):\n' ' userId=1234 gids=[123, 456, 789]\n' @@ -456,13 +461,16 @@ class DeviceUtils_GetApplicationVersionTest(DeviceUtilsTest): def test_GetApplicationVersion_notExists(self): with self.assertCalls( - (self.call.adb.Shell('dumpsys package com.android.chrome'), '')): + (self.call.adb.Shell( + 'dumpsys package com.android.chrome', ensure_logs_on_timeout=False), + '')): self.assertEquals(None, self.device.GetApplicationVersion('com.android.chrome')) def test_GetApplicationVersion_fails(self): with self.assertCalls( - (self.call.adb.Shell('dumpsys package com.android.chrome'), + (self.call.adb.Shell( + 'dumpsys package com.android.chrome', ensure_logs_on_timeout=False), 'Packages:\n' ' Package [com.android.chrome] (3901ecfb):\n' ' userId=1234 gids=[123, 456, 789]\n' @@ -520,7 +528,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): self.call.adb.WaitForDevice(), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), ''), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), ''), # pm_ready (self.call.device._GetApplicationPathsInternal('android', skip_cache=True), @@ -534,7 +543,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): self.call.adb.WaitForDevice(), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), ''), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), ''), # pm_ready (self.call.device._GetApplicationPathsInternal('android', skip_cache=True), @@ -542,7 +552,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): # boot_completed (self.call.device.GetProp('sys.boot_completed', cache=False), '1'), # wifi_enabled - (self.call.adb.Shell('dumpsys wifi'), + (self.call.adb.Shell( + 'dumpsys wifi', ensure_logs_on_timeout=False), 'stuff\nWi-Fi is enabled\nmore stuff\n')): self.device.WaitUntilFullyBooted(wifi=True) @@ -559,7 +570,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), ''), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), ''), # pm_ready (self.call.device._GetApplicationPathsInternal('android', skip_cache=True), @@ -573,7 +585,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): self.call.adb.WaitForDevice(), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), ''), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), ''), # pm_ready (self.call.device._GetApplicationPathsInternal('android', skip_cache=True), @@ -598,13 +611,18 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): self.call.adb.WaitForDevice(), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), self.ShellError()), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), + self.ShellError()), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), self.ShellError()), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), + self.ShellError()), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), self.TimeoutError())): with self.assertRaises(device_errors.CommandTimeoutError): self.device.WaitUntilFullyBooted(wifi=False) @@ -614,7 +632,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): self.call.adb.WaitForDevice(), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), ''), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), ''), # pm_ready (self.call.device._GetApplicationPathsInternal('android', skip_cache=True), @@ -635,7 +654,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): self.call.adb.WaitForDevice(), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), ''), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), ''), # pm_ready (self.call.device._GetApplicationPathsInternal('android', skip_cache=True), @@ -655,7 +675,8 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): self.call.adb.WaitForDevice(), # sd_card_ready (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), - (self.call.adb.Shell('test -d /fake/storage/path'), ''), + (self.call.adb.Shell( + 'test -d /fake/storage/path', ensure_logs_on_timeout=False), ''), # pm_ready (self.call.device._GetApplicationPathsInternal('android', skip_cache=True), @@ -663,11 +684,14 @@ class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): # boot_completed (self.call.device.GetProp('sys.boot_completed', cache=False), '1'), # wifi_enabled - (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), + (self.call.adb.Shell( + 'dumpsys wifi', ensure_logs_on_timeout=False), 'stuff\nmore stuff\n'), # wifi_enabled - (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), + (self.call.adb.Shell( + 'dumpsys wifi', ensure_logs_on_timeout=False), 'stuff\nmore stuff\n'), # wifi_enabled - (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): + (self.call.adb.Shell( + 'dumpsys wifi', ensure_logs_on_timeout=False), self.TimeoutError())): with self.assertRaises(device_errors.CommandTimeoutError): self.device.WaitUntilFullyBooted(wifi=True) @@ -930,30 +954,36 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): self.device.NeedsSU = mock.Mock(return_value=False) def testRunShellCommand_commandAsList(self): - with self.assertCall(self.call.adb.Shell('pm list packages'), ''): + with self.assertCall(self.call.adb.Shell( + 'pm list packages', ensure_logs_on_timeout=False), ''): self.device.RunShellCommand( ['pm', 'list', 'packages'], check_return=True) def testRunShellCommand_commandAsListQuoted(self): - with self.assertCall(self.call.adb.Shell("echo 'hello world' '$10'"), ''): + with self.assertCall(self.call.adb.Shell( + "echo 'hello world' '$10'", ensure_logs_on_timeout=False), ''): self.device.RunShellCommand( ['echo', 'hello world', '$10'], check_return=True) def testRunShellCommand_commandAsString(self): - with self.assertCall(self.call.adb.Shell('echo "$VAR"'), ''): + with self.assertCall(self.call.adb.Shell( + 'echo "$VAR"', ensure_logs_on_timeout=False), ''): self.device.RunShellCommand( 'echo "$VAR"', shell=True, check_return=True) def testNewRunShellImpl_withEnv(self): with self.assertCall( - self.call.adb.Shell('VAR=some_string echo "$VAR"'), ''): + self.call.adb.Shell( + 'VAR=some_string echo "$VAR"', ensure_logs_on_timeout=False), ''): self.device.RunShellCommand( 'echo "$VAR"', shell=True, check_return=True, env={'VAR': 'some_string'}) def testNewRunShellImpl_withEnvQuoted(self): with self.assertCall( - self.call.adb.Shell('PATH="$PATH:/other/path" run_this'), ''): + self.call.adb.Shell( + 'PATH="$PATH:/other/path" run_this', ensure_logs_on_timeout=False), + ''): self.device.RunShellCommand( ['run_this'], check_return=True, env={'PATH': '$PATH:/other/path'}) @@ -963,13 +993,17 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): ['some_cmd'], check_return=True, env={'INVALID NAME': 'value'}) def testNewRunShellImpl_withCwd(self): - with self.assertCall(self.call.adb.Shell('cd /some/test/path && ls'), ''): + with self.assertCall(self.call.adb.Shell( + 'cd /some/test/path && ls', ensure_logs_on_timeout=False), ''): self.device.RunShellCommand( ['ls'], check_return=True, cwd='/some/test/path') def testNewRunShellImpl_withCwdQuoted(self): with self.assertCall( - self.call.adb.Shell("cd '/some test/path with/spaces' && ls"), ''): + self.call.adb.Shell( + "cd '/some test/path with/spaces' && ls", + ensure_logs_on_timeout=False), + ''): self.device.RunShellCommand( ['ls'], check_return=True, cwd='/some test/path with/spaces') @@ -980,7 +1014,9 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): (mock.call.devil.android.device_temp_file.DeviceTempFile( self.adb, suffix='.sh'), MockTempFile('/sdcard/temp-123.sh')), self.call.device._WriteFileWithPush('/sdcard/temp-123.sh', expected_cmd), - (self.call.adb.Shell('sh /sdcard/temp-123.sh'), payload + '\n')): + (self.call.adb.Shell( + 'sh /sdcard/temp-123.sh', ensure_logs_on_timeout=False), + payload + '\n')): self.assertEquals( [payload], self.device.RunShellCommand(['echo', payload], check_return=True)) @@ -995,7 +1031,9 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): (mock.call.devil.android.device_temp_file.DeviceTempFile( self.adb, suffix='.sh'), MockTempFile('/sdcard/temp-123.sh')), self.call.device._WriteFileWithPush('/sdcard/temp-123.sh', expected_cmd), - (self.call.adb.Shell('sh /sdcard/temp-123.sh'), payload + '\n')): + (self.call.adb.Shell( + 'sh /sdcard/temp-123.sh', ensure_logs_on_timeout=False), + payload + '\n')): self.assertEquals( [payload], self.device.RunShellCommand( @@ -1007,7 +1045,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): with self.assertCalls( (self.call.device.NeedsSU(), True), (self.call.device._Su(expected_cmd_without_su), expected_cmd), - (self.call.adb.Shell(expected_cmd), '')): + (self.call.adb.Shell( + expected_cmd, ensure_logs_on_timeout=False), '')): self.device.RunShellCommand( ['setprop', 'service.adb.root', '0'], check_return=True, as_root=True) @@ -1016,7 +1055,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): expected_cmd_without_run_as = "sh -c 'mkdir -p files'" expected_cmd = ( 'run-as org.devil.test_package %s' % expected_cmd_without_run_as) - with self.assertCall(self.call.adb.Shell(expected_cmd), ''): + with self.assertCall(self.call.adb.Shell( + expected_cmd, ensure_logs_on_timeout=False), ''): self.device.RunShellCommand( ['mkdir', '-p', 'files'], check_return=True, run_as='org.devil.test_package') @@ -1031,7 +1071,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): with self.assertCalls( (self.call.device.NeedsSU(), True), (self.call.device._Su(expected_cmd_without_su), expected_cmd), - (self.call.adb.Shell(expected_cmd), '')): + (self.call.adb.Shell( + expected_cmd, ensure_logs_on_timeout=False), '')): self.device.RunShellCommand( ['mkdir', '-p', 'files'], check_return=True, run_as='org.devil.test_package', @@ -1039,14 +1080,16 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): def testRunShellCommand_manyLines(self): cmd = 'ls /some/path' - with self.assertCall(self.call.adb.Shell(cmd), 'file1\nfile2\nfile3\n'): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), 'file1\nfile2\nfile3\n'): self.assertEquals( ['file1', 'file2', 'file3'], self.device.RunShellCommand(cmd.split(), check_return=True)) def testRunShellCommand_manyLinesRawOutput(self): cmd = 'ls /some/path' - with self.assertCall(self.call.adb.Shell(cmd), '\rfile1\nfile2\r\nfile3\n'): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), '\rfile1\nfile2\r\nfile3\n'): self.assertEquals( '\rfile1\nfile2\r\nfile3\n', self.device.RunShellCommand( @@ -1054,7 +1097,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): def testRunShellCommand_singleLine_success(self): cmd = 'echo $VALUE' - with self.assertCall(self.call.adb.Shell(cmd), 'some value\n'): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), 'some value\n'): self.assertEquals( 'some value', self.device.RunShellCommand( @@ -1062,7 +1106,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): def testRunShellCommand_singleLine_successEmptyLine(self): cmd = 'echo $VALUE' - with self.assertCall(self.call.adb.Shell(cmd), '\n'): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), '\n'): self.assertEquals( '', self.device.RunShellCommand( @@ -1070,7 +1115,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): def testRunShellCommand_singleLine_successWithoutEndLine(self): cmd = 'echo -n $VALUE' - with self.assertCall(self.call.adb.Shell(cmd), 'some value'): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), 'some value'): self.assertEquals( 'some value', self.device.RunShellCommand( @@ -1078,7 +1124,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): def testRunShellCommand_singleLine_successNoOutput(self): cmd = 'echo -n $VALUE' - with self.assertCall(self.call.adb.Shell(cmd), ''): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), ''): self.assertEquals( '', self.device.RunShellCommand( @@ -1086,7 +1133,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): def testRunShellCommand_singleLine_failTooManyLines(self): cmd = 'echo $VALUE' - with self.assertCall(self.call.adb.Shell(cmd), + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), 'some value\nanother value\n'): with self.assertRaises(device_errors.CommandFailedError): self.device.RunShellCommand( @@ -1095,7 +1143,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): def testRunShellCommand_checkReturn_success(self): cmd = 'echo $ANDROID_DATA' output = '/data\n' - with self.assertCall(self.call.adb.Shell(cmd), output): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), output): self.assertEquals( [output.rstrip()], self.device.RunShellCommand(cmd, shell=True, check_return=True)) @@ -1103,14 +1152,16 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): def testRunShellCommand_checkReturn_failure(self): cmd = 'ls /root' output = 'opendir failed, Permission denied\n' - with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), self.ShellError(output)): with self.assertRaises(device_errors.AdbCommandFailedError): self.device.RunShellCommand(cmd.split(), check_return=True) def testRunShellCommand_checkReturn_disabled(self): cmd = 'ls /root' output = 'opendir failed, Permission denied\n' - with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), self.ShellError(output)): self.assertEquals( [output.rstrip()], self.device.RunShellCommand(cmd.split(), check_return=False)) @@ -1122,7 +1173,7 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): with self.assertCalls( (mock.call.devil.android.device_temp_file.DeviceTempFile(self.adb), temp_file), - (self.call.adb.Shell(cmd_redirect)), + (self.call.adb.Shell(cmd_redirect, ensure_logs_on_timeout=False)), (self.call.device.ReadFile(temp_file.name, force_pull=True), 'something')): self.assertEquals( @@ -1132,7 +1183,8 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): def testRunShellCommand_largeOutput_disabledNoTrigger(self): cmd = 'something' - with self.assertCall(self.call.adb.Shell(cmd), self.ShellError('')): + with self.assertCall(self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), self.ShellError('')): with self.assertRaises(device_errors.AdbCommandFailedError): self.device.RunShellCommand([cmd], check_return=True) @@ -1141,10 +1193,12 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): temp_file = MockTempFile('/sdcard/temp-123') cmd_redirect = '( %s )>%s 2>&1' % (cmd, temp_file.name) with self.assertCalls( - (self.call.adb.Shell(cmd), self.ShellError('', None)), + (self.call.adb.Shell( + cmd, ensure_logs_on_timeout=False), self.ShellError('', None)), (mock.call.devil.android.device_temp_file.DeviceTempFile(self.adb), temp_file), - (self.call.adb.Shell(cmd_redirect)), + (self.call.adb.Shell( + cmd_redirect, ensure_logs_on_timeout=False)), (self.call.device.ReadFile(mock.ANY, force_pull=True), 'something')): self.assertEquals( @@ -1210,7 +1264,8 @@ class DeviceUtilsKillAllTest(DeviceUtilsTest): with self.assertCalls( (self.call.device.ListProcesses('some.process'), Processes(('some.process', 1234), ('some.process.thing', 5678))), - (self.call.adb.Shell('kill -9 1234 5678'), '')): + (self.call.adb.Shell( + 'kill -9 1234 5678', ensure_logs_on_timeout=False), '')): self.assertEquals( 2, self.device.KillAll('some.process', blocking=False)) @@ -1218,7 +1273,8 @@ class DeviceUtilsKillAllTest(DeviceUtilsTest): with self.assertCalls( (self.call.device.ListProcesses('some.process'), Processes(('some.process', 1234), ('some.process.thing', 5678))), - (self.call.adb.Shell('kill -9 1234 5678'), ''), + (self.call.adb.Shell( + 'kill -9 1234 5678', ensure_logs_on_timeout=False), ''), (self.call.device.ListProcesses('some.process'), Processes(('some.process.thing', 5678))), (self.call.device.ListProcesses('some.process'), @@ -1231,7 +1287,8 @@ class DeviceUtilsKillAllTest(DeviceUtilsTest): with self.assertCalls( (self.call.device.ListProcesses('some.process'), Processes(('some.process', 1234), ('some.process.thing', 5678))), - (self.call.adb.Shell('kill -9 1234'), '')): + (self.call.adb.Shell( + 'kill -9 1234', ensure_logs_on_timeout=False), '')): self.assertEquals( 1, self.device.KillAll('some.process', exact=True, blocking=False)) @@ -1239,7 +1296,8 @@ class DeviceUtilsKillAllTest(DeviceUtilsTest): with self.assertCalls( (self.call.device.ListProcesses('some.process'), Processes(('some.process', 1234), ('some.process.thing', 5678))), - (self.call.adb.Shell('kill -9 1234'), ''), + (self.call.adb.Shell( + 'kill -9 1234', ensure_logs_on_timeout=False), ''), (self.call.device.ListProcesses('some.process'), Processes(('some.process', 1234), ('some.process.thing', 5678))), (self.call.device.ListProcesses('some.process'), @@ -1254,7 +1312,8 @@ class DeviceUtilsKillAllTest(DeviceUtilsTest): (self.call.device.NeedsSU(), True), (self.call.device._Su("sh -c 'kill -9 1234'"), "su -c sh -c 'kill -9 1234'"), - (self.call.adb.Shell("su -c sh -c 'kill -9 1234'"), '')): + (self.call.adb.Shell( + "su -c sh -c 'kill -9 1234'", ensure_logs_on_timeout=False), '')): self.assertEquals( 1, self.device.KillAll('some.process', as_root=True)) @@ -1262,7 +1321,8 @@ class DeviceUtilsKillAllTest(DeviceUtilsTest): with self.assertCalls( (self.call.device.ListProcesses('some.process'), Processes(('some.process', 1234))), - (self.call.adb.Shell('kill -15 1234'), '')): + (self.call.adb.Shell( + 'kill -15 1234', ensure_logs_on_timeout=False), '')): self.assertEquals( 1, self.device.KillAll('some.process', signum=device_signal.SIGTERM)) @@ -1270,7 +1330,8 @@ class DeviceUtilsKillAllTest(DeviceUtilsTest): with self.assertCalls( (self.call.device.ListProcesses('some.process'), Processes(('some.process', 1234), ('some.process', 4567))), - (self.call.adb.Shell('kill -15 1234 4567'), '')): + (self.call.adb.Shell( + 'kill -15 1234 4567', ensure_logs_on_timeout=False), '')): self.assertEquals( 2, self.device.KillAll('some.process', signum=device_signal.SIGTERM)) @@ -1280,8 +1341,10 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): def testStartActivity_actionOnly(self): test_intent = intent.Intent(action='android.intent.action.VIEW') with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent) @@ -1290,9 +1353,11 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): package='test.package', activity='.Main') with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent) @@ -1301,9 +1366,11 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): package='test.package', activity='.Main') with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Error: Failed to start test activity'): with self.assertRaises(device_errors.CommandFailedError): self.device.StartActivity(test_intent) @@ -1313,10 +1380,12 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): package='test.package', activity='.Main') with self.assertCall( - self.call.adb.Shell('am start ' - '-W ' - '-a android.intent.action.VIEW ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am start ' + '-W ' + '-a android.intent.action.VIEW ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent, blocking=True) @@ -1326,10 +1395,12 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): activity='.Main', category='android.intent.category.HOME') with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW ' - '-c android.intent.category.HOME ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW ' + '-c android.intent.category.HOME ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent) @@ -1340,11 +1411,13 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): category=['android.intent.category.HOME', 'android.intent.category.BROWSABLE']) with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW ' - '-c android.intent.category.HOME ' - '-c android.intent.category.BROWSABLE ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW ' + '-c android.intent.category.HOME ' + '-c android.intent.category.BROWSABLE ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent) @@ -1354,10 +1427,12 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): activity='.Main', data='http://www.google.com/') with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW ' - '-d http://www.google.com/ ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW ' + '-d http://www.google.com/ ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent) @@ -1367,10 +1442,12 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): activity='.Main', extras={'foo': 'test'}) with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW ' - '-n test.package/.Main ' - '--es foo test'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW ' + '-n test.package/.Main ' + '--es foo test', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent) @@ -1380,10 +1457,12 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): activity='.Main', extras={'foo': True}) with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW ' - '-n test.package/.Main ' - '--ez foo True'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW ' + '-n test.package/.Main ' + '--ez foo True', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent) @@ -1393,10 +1472,12 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): activity='.Main', extras={'foo': 123}) with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW ' - '-n test.package/.Main ' - '--ei foo 123'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW ' + '-n test.package/.Main ' + '--ei foo 123', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent) @@ -1405,10 +1486,12 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): package='test.package', activity='.Main') with self.assertCall( - self.call.adb.Shell('am start ' - '--start-profiler test_trace_file.out ' - '-a android.intent.action.VIEW ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am start ' + '--start-profiler test_trace_file.out ' + '-a android.intent.action.VIEW ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent, trace_file_name='test_trace_file.out') @@ -1418,10 +1501,12 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): package='test.package', activity='.Main') with self.assertCall( - self.call.adb.Shell('am start ' - '-S ' - '-a android.intent.action.VIEW ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am start ' + '-S ' + '-a android.intent.action.VIEW ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent, force_stop=True) @@ -1434,10 +1519,12 @@ class DeviceUtilsStartActivityTest(DeviceUtilsTest): intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED ]) with self.assertCall( - self.call.adb.Shell('am start ' - '-a android.intent.action.VIEW ' - '-n test.package/.Main ' - '-f 0x10200000'), + self.call.adb.Shell( + 'am start ' + '-a android.intent.action.VIEW ' + '-n test.package/.Main ' + '-f 0x10200000', + ensure_logs_on_timeout=False), 'Starting: Intent { act=android.intent.action.VIEW }'): self.device.StartActivity(test_intent) @@ -1450,9 +1537,11 @@ class DeviceUtilsStartServiceTest(DeviceUtilsTest): with self.patch_call(self.call.device.build_version_sdk, return_value=version_codes.NOUGAT): with self.assertCall( - self.call.adb.Shell('am startservice ' - '-a android.intent.action.START ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am startservice ' + '-a android.intent.action.START ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting service: Intent { act=android.intent.action.START }'): self.device.StartService(test_intent) @@ -1463,9 +1552,11 @@ class DeviceUtilsStartServiceTest(DeviceUtilsTest): with self.patch_call(self.call.device.build_version_sdk, return_value=version_codes.NOUGAT): with self.assertCall( - self.call.adb.Shell('am startservice ' - '-a android.intent.action.START ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am startservice ' + '-a android.intent.action.START ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Error: Failed to start test service'): with self.assertRaises(device_errors.CommandFailedError): self.device.StartService(test_intent) @@ -1477,10 +1568,12 @@ class DeviceUtilsStartServiceTest(DeviceUtilsTest): with self.patch_call(self.call.device.build_version_sdk, return_value=version_codes.NOUGAT): with self.assertCall( - self.call.adb.Shell('am startservice ' - '--user TestUser ' - '-a android.intent.action.START ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am startservice ' + '--user TestUser ' + '-a android.intent.action.START ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting service: Intent { act=android.intent.action.START }'): self.device.StartService(test_intent, user_id='TestUser') @@ -1491,9 +1584,11 @@ class DeviceUtilsStartServiceTest(DeviceUtilsTest): with self.patch_call(self.call.device.build_version_sdk, return_value=version_codes.OREO): with self.assertCall( - self.call.adb.Shell('am start-service ' - '-a android.intent.action.START ' - '-n test.package/.Main'), + self.call.adb.Shell( + 'am start-service ' + '-a android.intent.action.START ' + '-n test.package/.Main', + ensure_logs_on_timeout=False), 'Starting service: Intent { act=android.intent.action.START }'): self.device.StartService(test_intent) @@ -1546,7 +1641,9 @@ class DeviceUtilsBroadcastIntentTest(DeviceUtilsTest): def testBroadcastIntent_noExtras(self): test_intent = intent.Intent(action='test.package.with.an.INTENT') with self.assertCall( - self.call.adb.Shell('am broadcast -a test.package.with.an.INTENT'), + self.call.adb.Shell( + 'am broadcast -a test.package.with.an.INTENT', + ensure_logs_on_timeout=False), 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): self.device.BroadcastIntent(test_intent) @@ -1555,7 +1652,8 @@ class DeviceUtilsBroadcastIntentTest(DeviceUtilsTest): extras={'foo': 'bar value'}) with self.assertCall( self.call.adb.Shell( - "am broadcast -a test.package.with.an.INTENT --es foo 'bar value'"), + "am broadcast -a test.package.with.an.INTENT --es foo 'bar value'", + ensure_logs_on_timeout=False), 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): self.device.BroadcastIntent(test_intent) @@ -1564,7 +1662,8 @@ class DeviceUtilsBroadcastIntentTest(DeviceUtilsTest): extras={'foo': None}) with self.assertCall( self.call.adb.Shell( - 'am broadcast -a test.package.with.an.INTENT --esn foo'), + 'am broadcast -a test.package.with.an.INTENT --esn foo', + ensure_logs_on_timeout=False), 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): self.device.BroadcastIntent(test_intent) @@ -1728,7 +1827,8 @@ class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): class DeviceUtilsSendKeyEventTest(DeviceUtilsTest): def testSendKeyEvent(self): - with self.assertCall(self.call.adb.Shell('input keyevent 66'), ''): + with self.assertCall(self.call.adb.Shell( + 'input keyevent 66', ensure_logs_on_timeout=False), ''): self.device.SendKeyEvent(66) @@ -2067,12 +2167,14 @@ class DeviceUtilsWriteFileTest(DeviceUtilsTest): def testWriteFile_withEcho(self): with self.assertCall(self.call.adb.Shell( - "echo -n the.contents > /test/file/to.write"), ''): + "echo -n the.contents > /test/file/to.write", + ensure_logs_on_timeout=False), ''): self.device.WriteFile('/test/file/to.write', 'the.contents') def testWriteFile_withEchoAndQuotes(self): with self.assertCall(self.call.adb.Shell( - "echo -n 'the contents' > '/test/file/to write'"), ''): + "echo -n 'the contents' > '/test/file/to write'", + ensure_logs_on_timeout=False), ''): self.device.WriteFile('/test/file/to write', 'the contents') def testWriteFile_withEchoAndSU(self): @@ -2081,7 +2183,8 @@ class DeviceUtilsWriteFileTest(DeviceUtilsTest): with self.assertCalls( (self.call.device.NeedsSU(), True), (self.call.device._Su(expected_cmd_without_su), expected_cmd), - (self.call.adb.Shell(expected_cmd), + (self.call.adb.Shell( + expected_cmd, ensure_logs_on_timeout=False), '')): self.device.WriteFile('/test/file', 'contents', as_root=True) @@ -2562,51 +2665,60 @@ class DeviceUtilsListProcessesTest(DeviceUtilsTest): class DeviceUtilsGetSetEnforce(DeviceUtilsTest): def testGetEnforce_Enforcing(self): - with self.assertCall(self.call.adb.Shell('getenforce'), 'Enforcing'): + with self.assertCall(self.call.adb.Shell( + 'getenforce', ensure_logs_on_timeout=False), 'Enforcing'): self.assertEqual(True, self.device.GetEnforce()) def testGetEnforce_Permissive(self): - with self.assertCall(self.call.adb.Shell('getenforce'), 'Permissive'): + with self.assertCall(self.call.adb.Shell( + 'getenforce', ensure_logs_on_timeout=False), 'Permissive'): self.assertEqual(False, self.device.GetEnforce()) def testGetEnforce_Disabled(self): - with self.assertCall(self.call.adb.Shell('getenforce'), 'Disabled'): + with self.assertCall(self.call.adb.Shell( + 'getenforce', ensure_logs_on_timeout=False), 'Disabled'): self.assertEqual(None, self.device.GetEnforce()) def testSetEnforce_Enforcing(self): with self.assertCalls( (self.call.device.NeedsSU(), False), - (self.call.adb.Shell('setenforce 1'), '')): + (self.call.adb.Shell( + 'setenforce 1', ensure_logs_on_timeout=False), '')): self.device.SetEnforce(enabled=True) def testSetEnforce_Permissive(self): with self.assertCalls( (self.call.device.NeedsSU(), False), - (self.call.adb.Shell('setenforce 0'), '')): + (self.call.adb.Shell( + 'setenforce 0', ensure_logs_on_timeout=False), '')): self.device.SetEnforce(enabled=False) def testSetEnforce_EnforcingWithInt(self): with self.assertCalls( (self.call.device.NeedsSU(), False), - (self.call.adb.Shell('setenforce 1'), '')): + (self.call.adb.Shell( + 'setenforce 1', ensure_logs_on_timeout=False), '')): self.device.SetEnforce(enabled=1) def testSetEnforce_PermissiveWithInt(self): with self.assertCalls( (self.call.device.NeedsSU(), False), - (self.call.adb.Shell('setenforce 0'), '')): + (self.call.adb.Shell( + 'setenforce 0', ensure_logs_on_timeout=False), '')): self.device.SetEnforce(enabled=0) def testSetEnforce_EnforcingWithStr(self): with self.assertCalls( (self.call.device.NeedsSU(), False), - (self.call.adb.Shell('setenforce 1'), '')): + (self.call.adb.Shell( + 'setenforce 1', ensure_logs_on_timeout=False), '')): self.device.SetEnforce(enabled='1') def testSetEnforce_PermissiveWithStr(self): with self.assertCalls( (self.call.device.NeedsSU(), False), - (self.call.adb.Shell('setenforce 0'), '')): + (self.call.adb.Shell( + 'setenforce 0', ensure_logs_on_timeout=False), '')): self.device.SetEnforce(enabled='0') # Not recommended but it works! @@ -2614,12 +2726,14 @@ class DeviceUtilsSetWebViewImplementationTest(DeviceUtilsTest): def testSetWebViewImplementation_success(self): with self.assertCall(self.call.adb.Shell( - 'cmd webviewupdate set-webview-implementation foo.org'), 'Success'): + 'cmd webviewupdate set-webview-implementation foo.org', + ensure_logs_on_timeout=False), 'Success'): self.device.SetWebViewImplementation('foo.org') def testSetWebViewImplementation_failure(self): with self.assertCall(self.call.adb.Shell( - 'cmd webviewupdate set-webview-implementation foo.org'), 'Oops!'): + 'cmd webviewupdate set-webview-implementation foo.org', + ensure_logs_on_timeout=False), 'Oops!'): with self.assertRaises(device_errors.CommandFailedError): self.device.SetWebViewImplementation('foo.org') @@ -2631,7 +2745,9 @@ class DeviceUtilsTakeScreenshotTest(DeviceUtilsTest): (mock.call.devil.android.device_temp_file.DeviceTempFile( self.adb, suffix='.png'), MockTempFile('/tmp/path/temp-123.png')), - (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'), + (self.call.adb.Shell( + '/system/bin/screencap -p /tmp/path/temp-123.png', + ensure_logs_on_timeout=False), ''), self.call.device.PullFile('/tmp/path/temp-123.png', '/test/host/screenshot.png')): @@ -2775,7 +2891,7 @@ class DeviceUtilsHealthyDevicesTest(mock_calls.TestCase): (mock.call.devil.android.sdk.adb_wrapper.AdbWrapper.Devices(), [_AdbWrapperMock(s) for s in test_serials])): with self.assertRaises(device_errors.NoDevicesError): - device_utils.DeviceUtils.HealthyDevices(device_arg=None, retry=False) + device_utils.DeviceUtils.HealthyDevices(device_arg=None, retries=0) def testHealthyDevices_noneDeviceArg_multiple_attached_ANDROID_SERIAL(self): try: @@ -2818,17 +2934,23 @@ class DeviceUtilsHealthyDevicesTest(mock_calls.TestCase): (mock.call.devil.android.sdk.adb_wrapper.AdbWrapper.Devices(), [_AdbWrapperMock(s) for s in test_serials])): with self.assertRaises(device_errors.NoDevicesError): - device_utils.DeviceUtils.HealthyDevices(device_arg=[], retry=False) - - def testHealthyDevices_EmptyListDeviceArg_no_attached_with_retry(self): - test_serials = [] - with self.assertCalls( - (mock.call.devil.android.sdk.adb_wrapper.AdbWrapper.Devices(), - [_AdbWrapperMock(s) for s in test_serials]), - (mock.call.devil.android.sdk.adb_wrapper.AdbWrapper.Devices(), - [_AdbWrapperMock(s) for s in test_serials])): + device_utils.DeviceUtils.HealthyDevices(device_arg=[], retries=0) + + @mock.patch('time.sleep') + @mock.patch('devil.android.device_utils.RestartServer') + def testHealthyDevices_EmptyListDeviceArg_no_attached_with_retry( + self, mock_restart, mock_sleep): + with self.assertCalls( + (mock.call.devil.android.sdk.adb_wrapper.AdbWrapper.Devices(), []), + (mock.call.devil.android.sdk.adb_wrapper.AdbWrapper.Devices(), []), + (mock.call.devil.android.sdk.adb_wrapper.AdbWrapper.Devices(), []), + (mock.call.devil.android.sdk.adb_wrapper.AdbWrapper.Devices(), []), + (mock.call.devil.android.sdk.adb_wrapper.AdbWrapper.Devices(), [])): with self.assertRaises(device_errors.NoDevicesError): - device_utils.DeviceUtils.HealthyDevices(device_arg=[], retry=True) + device_utils.DeviceUtils.HealthyDevices(device_arg=[], retries=4) + self.assertEquals(mock_restart.call_count, 4) + self.assertEquals(mock_sleep.call_args_list, [ + mock.call(2), mock.call(4), mock.call(8), mock.call(16)]) def testHealthyDevices_ListDeviceArg(self): device_arg = ['0123456789abcdef', 'fedcba9876543210'] @@ -2850,7 +2972,7 @@ class DeviceUtilsHealthyDevicesTest(mock_calls.TestCase): (mock.call.devil.android.device_utils.DeviceUtils.GetABI(), ARM32_ABI)): with self.assertRaises(device_errors.NoDevicesError): - device_utils.DeviceUtils.HealthyDevices(device_arg=[], retry=False, + device_utils.DeviceUtils.HealthyDevices(device_arg=[], retries=0, abis=[ARM64_ABI]) def testHealthyDevices_abisArg_filter_on_abi(self): @@ -2863,7 +2985,7 @@ class DeviceUtilsHealthyDevicesTest(mock_calls.TestCase): (mock.call.devil.android.device_utils.DeviceUtils.GetABI(), ARM32_ABI)): devices = device_utils.DeviceUtils.HealthyDevices(device_arg=[], - retry=False, + retries=0, abis=[ARM64_ABI]) self.assertEquals(1, len(devices)) @@ -3078,7 +3200,9 @@ class DeviceUtilsGetIMEITest(DeviceUtilsTest): ' Device ID = 123454321') with self.assertCalls( (self.call.device.GetProp('ro.build.version.sdk', cache=True), '19'), - (self.call.adb.Shell('dumpsys iphonesubinfo'), dumpsys_output)): + (self.call.adb.Shell( + 'dumpsys iphonesubinfo', ensure_logs_on_timeout=False), + dumpsys_output)): self.assertEquals(self.device.GetIMEI(), '123454321') def testSuccessfulServiceCall(self): @@ -3090,20 +3214,25 @@ class DeviceUtilsGetIMEITest(DeviceUtilsTest): """ with self.assertCalls( (self.call.device.GetProp('ro.build.version.sdk', cache=True), '24'), - (self.call.adb.Shell('service call iphonesubinfo 1'), service_output)): + (self.call.adb.Shell( + 'service call iphonesubinfo 1', ensure_logs_on_timeout=False), + service_output)): self.assertEquals(self.device.GetIMEI(), '765432101234567') def testNoIMEI(self): with self.assertCalls( (self.call.device.GetProp('ro.build.version.sdk', cache=True), '19'), - (self.call.adb.Shell('dumpsys iphonesubinfo'), 'no device id')): + (self.call.adb.Shell( + 'dumpsys iphonesubinfo', ensure_logs_on_timeout=False), + 'no device id')): with self.assertRaises(device_errors.CommandFailedError): self.device.GetIMEI() def testAdbError(self): with self.assertCalls( (self.call.device.GetProp('ro.build.version.sdk', cache=True), '24'), - (self.call.adb.Shell('service call iphonesubinfo 1'), + (self.call.adb.Shell( + 'service call iphonesubinfo 1', ensure_logs_on_timeout=False), self.ShellError())): with self.assertRaises(device_errors.CommandFailedError): self.device.GetIMEI() |