Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(780)

Unified Diff: build/android/pylib/device/device_utils_test.py

Issue 751063002: Allow RunShellCommand to work even with very large commands (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less mind-bendy version Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/device/device_utils_test.py
diff --git a/build/android/pylib/device/device_utils_test.py b/build/android/pylib/device/device_utils_test.py
index 4f47021e2dcb7ba66cc02c45f68dc3ac9597289e..eb1fd93ceb46f189649536076465f9266edeb616 100755
--- a/build/android/pylib/device/device_utils_test.py
+++ b/build/android/pylib/device/device_utils_test.py
@@ -21,6 +21,7 @@ import sys
import unittest
from pylib import android_commands
+from pylib import cmd_helper
from pylib import constants
from pylib.device import adb_wrapper
from pylib.device import device_errors
@@ -72,6 +73,7 @@ class MockTempFile(object):
def __init__(self, name='/tmp/some/file'):
self.file = mock.MagicMock(spec=file)
self.file.name = name
+ self.file.name_quoted = cmd_helper.SingleQuote(name)
def __enter__(self):
return self.file
@@ -621,6 +623,32 @@ class DeviceUtilsRunShellCommandTest(DeviceUtilsNewImplTest):
self.call.adb.Shell("cd '/some test/path with/spaces' && ls"), ''):
self.device.RunShellCommand('ls', cwd='/some test/path with/spaces')
+ def testRunShellCommand_withHugeCmd(self):
+ payload = 'hi! ' * 1024
+ expected_cmd = "echo '%s'" % payload
+ with self.assertCalls(
+ (mock.call.pylib.utils.device_temp_file.DeviceTempFile(
+ self.device, suffix='.sh'), MockTempFile('/sdcard/temp-123.sh')),
+ self.call.device.WriteFile(
+ '/sdcard/temp-123.sh', expected_cmd, as_root=False, force_push=True),
+ (self.call.adb.Shell('sh /sdcard/temp-123.sh'), payload + '\n')):
+ self.assertEquals([payload],
+ self.device.RunShellCommand(['echo', payload]))
+
+ def testRunShellCommand_withHugeCmdAmdSU(self):
+ payload = 'hi! ' * 1024
+ expected_cmd = """su -c sh -c 'echo '"'"'%s'"'"''""" % payload
+ with self.assertCalls(
+ (self.call.device.NeedsSU(), True),
+ (mock.call.pylib.utils.device_temp_file.DeviceTempFile(
+ self.device, suffix='.sh'), MockTempFile('/sdcard/temp-123.sh')),
+ self.call.device.WriteFile(
+ '/sdcard/temp-123.sh', expected_cmd, as_root=False, force_push=True),
+ (self.call.adb.Shell('sh /sdcard/temp-123.sh'), payload + '\n')):
+ self.assertEquals(
+ [payload],
+ self.device.RunShellCommand(['echo', payload], as_root=True))
+
def testRunShellCommand_withSu(self):
with self.assertCalls(
(self.call.device.NeedsSU(), True),

Powered by Google App Engine
This is Rietveld 408576698