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
This commit is contained in:
David Pursell
2015-10-07 14:57:51 -07:00
parent d427f1e5f5
commit fa1d9db173

View File

@@ -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):