diff options
author | David Pursell <dpursell@google.com> | 2015-10-07 14:57:51 -0700 |
---|---|---|
committer | David Pursell <dpursell@google.com> | 2015-10-09 16:51:12 -0700 |
commit | fa1d9db173386c5ad52404797168a32d9c4f27ac (patch) | |
tree | 1cec065268caa74a34ced547dcc03b44a6ffbe8e /python-packages | |
parent | d427f1e5f538537b78361c1fc905e8694f1f85a1 (diff) | |
download | android_development-fa1d9db173386c5ad52404797168a32d9c4f27ac.tar.gz android_development-fa1d9db173386c5ad52404797168a32d9c4f27ac.tar.bz2 android_development-fa1d9db173386c5ad52404797168a32d9c4f27ac.zip |
adb: add test for non-interactive stdin.
Add a test to send stdin to non-interactive `adb shell`.
This new test will hang on ToT devices that support shell_v2 until they
are rebuilt with the corresponding adb CL. A new feature could be added
instead to filter those devices out, but it doesn't seem worth it as no
devices have yet been released with shell_v2.
This CL also fixes a mistake I made earlier with device.linesep; this
is used to check device output, not separate device input. Using it
added unnecessary newline characters on Windows.
Bug: http://b/24565284
Change-Id: Ic123402975033d74688f56a36acac993af6815e6
Diffstat (limited to 'python-packages')
-rw-r--r-- | python-packages/adb/test_device.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/python-packages/adb/test_device.py b/python-packages/adb/test_device.py index a1e659fd9..c4f7f36e4 100644 --- a/python-packages/adb/test_device.py +++ b/python-packages/adb/test_device.py @@ -24,6 +24,7 @@ import random import shlex import shutil import signal +import string import subprocess import tempfile import unittest @@ -134,9 +135,9 @@ class ShellTest(DeviceTest): stderr=subprocess.PIPE) # Closing host-side stdin doesn't currently trigger the interactive # shell to exit so we need to explicitly add an exit command to - # close the session from the device side, and append linesep to complete + # close the session from the device side, and append newline to complete # the interactive command. - proc.communicate('{}; exit{}'.format(input, self.device.linesep)) + proc.communicate(input + '; exit\n') return proc.returncode def test_cat(self): @@ -261,6 +262,26 @@ class ShellTest(DeviceTest): self.assertEqual(1, self.device.shell_nocheck(proc_query)[0], 'subprocess failed to terminate') + def test_non_interactive_stdin(self): + """Tests that non-interactive shells send stdin.""" + if self.device.SHELL_PROTOCOL_FEATURE not in self.device.features: + raise unittest.SkipTest('non-interactive stdin unsupported ' + 'on this device') + + # Test both small and large inputs. + small_input = 'foo' + large_input = '\n'.join(c * 100 for c in (string.ascii_letters + + string.digits)) + + for input in (small_input, large_input): + proc = subprocess.Popen(self.device.adb_cmd + ['shell', 'cat'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = proc.communicate(input) + self.assertEqual(input.splitlines(), stdout.splitlines()) + self.assertEqual('', stderr) + class ArgumentEscapingTest(DeviceTest): def test_shell_escaping(self): |