Commit graph

52 commits

Author SHA1 Message Date
Josh Gao
fb08510784 Add feature flag for b/110953234 fix.
Bug: http://b/110953234
Bug: http://b/117946501
Test: adb features
Test: test_device.py
Change-Id: I340a30544a6d0ab1b2545e5371c8f98d04158c56
2018-10-23 18:28:46 +00:00
Josh Gao
faf1328a64 Revert "adb: don't close sockets before hitting EOF."
This reverts commit ffc11d3cf3.

Reason for revert: DeviceIdleFreqCheckTest failing

Bug: http://b/117630047
Change-Id: Ia51a4a30e785bc5b2526695de3f442aac298198f
2018-10-12 05:08:45 +00:00
Josh Gao
ffc11d3cf3 adb: don't close sockets before hitting EOF.
The standard (RFC 1122 - 4.2.2.13) says that if we call close on a
socket while we have pending data, a TCP RST should be sent to the
other end to notify it that we didn't read all of its data. However,
this can result in data that we've succesfully written out to be dropped
on the other end. To avoid this, instead of immediately closing a
socket, call shutdown on it instead, and then read from the file
descriptor until we hit EOF or an error before closing.

Bug: http://b/74616284
Test: ./test_adb.py
Test: ./test_device.py
Change-Id: I36f72bd14965821dc23de82774b0806b2db24f13
2018-10-04 14:01:07 -07:00
Josh Gao
ed17650438 adb: fix test_device.FileOperationsTest.test_push_empty.
It was doing a test with `[ -d foo`, without the closing square bracket.

Test: python -m unittest test_device.FileOperationsTest.test_push_empty
Change-Id: I996b98850cf916986ef969768a7235547fcc404a
2018-09-26 12:44:30 -07:00
Josh Gao
caab47f513 adb: make test_device.py executable.
For symmetry with test_adb.py, since they have different interpreter
requirements now.

Test: ./test_device.py
Change-Id: I02fe659a7216a619383661c8019d356f9ccfb34d
2018-09-20 17:55:37 -07:00
Treehugger Robot
756e28ee0c Merge "adb: win32: test for Unicode console output" 2018-09-08 01:35:29 +00:00
Josh Gao
5d799cd454 adb: fix spurious usb write failure on Windows.
We were accidentally returning 0 instead of the number of bytes written
whenever we wrote a USB packet that had a size that was a multiple of
the USB packet size, which resulted in the device getting kicked.

Bug: http://b/113070258
Test: python test_device.py
Change-Id: Ib3d6415545e90e1f4730afc8ad8713d10bb1534a
2018-08-22 17:11:40 -07:00
Spencer Low
69d8c39502 adb: win32: test for Unicode console output
Unit test for adb on Windows writing Unicode to an actual console
Window, as opposed to a pipe or file.

Test: Ran test on Ubuntu and Windows 10, tested version of adb with
incorrect Unicode handling and verified that test failed

Change-Id: Ibdda46d0fee83004537bcbb48a5c2fd6d3e1d593
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2018-08-11 00:16:16 -07:00
Josh Gao
a8db274a69 adb: disable test_device.FileOperationsTest.test_pull_symlink_dir.
selinux prevents us from doing this.

Test: python test_device.py
Change-Id: I7117dd19348b0764638977b7c958331a4839ea4f
2018-08-08 17:40:15 -07:00
Josh Gao
6c1b42ccd0 adb: fix test_device.FileOperationsTest.test_push_empty
Test: python test_device.py
Change-Id: Iaa5006e39c3d61374de11c05bcaffb4f30b7512e
2018-08-08 17:40:15 -07:00
Josh Gao
0cee7ccc59 adb: work around adbd push bug.
We shipped (well, are about to ship) an adbd that spuriously fails to
create directories upon push. Work around this in the adb client by
running a mkdir on all of the directories we would have otherwise
created.

On devices where we perform the workaround, this coincidentally fixes
a historic bug where we failed to push empty directories.

Bug: http://b/25566053
Bug: http://b/110953234
Test: python test_device.py
Change-Id: I690ec356c206fed4e5ab2c681c5570c8b231e26b
2018-07-10 13:20:40 -07:00
Josh Gao
4c0078d67a adbd: fix spurious failure to create dirs when pushing.
When pushing to a path, we first try to ensure the directory path
exists and has the permissions expected by fs_config. Due to a change
that changed the fs_config check from a blacklist to a whitelist, we
started doing this for /data (which doesn't begin with /data/), and the
UID/GID for that path was accidentally being reused for following path
segments that didn't exist, leading to a failed attempt to chown
/data/local/tmp/foo to be owned by system.

Bug: http://b/110953234
Test: python test_device.py
Change-Id: Ie798eec48bcf54aea40f6d90cc03bb2170280ee8
2018-07-09 14:25:51 -07:00
Elliott Hughes
77561c1f28 Remove out of date comment.
Bug: https://code.google.com/p/android/issues/detail?id=189821
Test: N/A
Change-Id: I25e64611d0c2db75a9caf0f19e7dd17c725d98a1
2018-04-16 15:22:33 -07:00
Josh Gao
2ea46521f3 adb: properly calculate packet size on Mac.
OS X reports maxPacketSize as wMaxPacketSize * (bMaxBurst + 1) in the
deprecated GetPipeProperties function. Use the also-deprecated
GetPipePropetiesV2 API to get bMaxBurst and figure out what
wMaxPacketSize is. (This file is going to go away eventually, so don't
bother with switching to the recommended GetPipePropertiesV3, since
it would be a substantially larger charge.)

libusb is unaffected.

Bug: http://b/77733422
Test: python test_device.py
Change-Id: I66517d699a4f39b93ba5eb7882bd8ee6c70f3672
2018-04-10 14:46:34 -07:00
Josh Gao
2c621ae741 adb: fix unicode file path test.
This test is failing due to:

     UnicodeWarning: Unicode equal comparison failed to convert both
     arguments to Unicode - interpreting them as being unequal'

Both arguments are already unicode, so stop encoding one side.

Test: python -m unittest test_device.FileOperationsTest.test_unicode_paths
Change-Id: Iea8bf29845ab3008ccf4c7dbd6969196e57ea25d
2018-03-21 15:13:07 -07:00
Josh Gao
c970aefada adb: add adb shell exit 42 stress test.
Add a test to hammer on `adb shell exit $n` for flakiness.

Bug: http://b/74616284
Test: python test_device.py
Change-Id: I6a842960f5b55ff739044698f5c9683992fc42f1
2018-03-19 16:14:53 -07:00
Josh Gao
85d4789719 Move GetDeviceTest from adb's test_device.py to adb package.
This test actually belongs with the adb python wrapper, since it's not
affected by changes to adb itself.

Bug: http://b/64260633
Test: python test_device.py
Change-Id: I58e5dff760f35923f8dbbdc7de6ffd75254880dc
2017-11-08 14:39:06 -08:00
Josh Gao
33d14b8748 adb: partially revert b5e11415.
Revert the write_msg_lock part of commit b5e11415. A write which hangs
will hold onto the mutex, preventing the device kick from ever
happening, which also causes lots of other stuff to hang, due to Kick
being called with the transport lock taken.

Test: python test_devices.py
Change-Id: Ie7c958799c93cad287c32d6bbef30c07f40c2d51
2017-09-13 15:09:40 -07:00
Josh Gao
a019f78141 adb: increase the shell command length limit.
Relax the shell command length limits when talking to an adbd with the
shell protocol.

shell is pretty much the only service that takes an arbitrarily long
string, so this is somewhat safe.

Bug: http://b/37716055
Test: `adb shell $(python -c 'print "echo " + "f" * (32*1024)') | wc` on L and master
Change-Id: I0737fd2244530ef8080f300cd3a3549a1ab93465
2017-06-16 18:01:11 -07:00
Dan Albert
06b0d6b01b Add --sync support to push.
Passing --sync only copies files that are older on the device.

Test: nose2
Bug: None
Change-Id: I2ff6c3d1fe29262c8ee50db316aa92fc38dd7147
2017-05-19 11:09:58 -07:00
Dan Albert
def4aae26d Fix test following -p removal.
Just use the environment variable.

Test: nose2
Bug: None
Change-Id: I020c737f8aa7416b46794ce387a12f7959a9ca2a
2017-05-19 00:30:51 -07:00
Josh Gao
ef3d343254 adb: use the actual wMaxPacketSize for usb endpoints.
Previously, adb was assuming a fixed maximum packet size of 1024 bytes
(the value for an endpoint connected via USB 3.0). When connected to an
endpoint that has an actual maximum packet size of 512 bytes (i.e.
every single device over USB 2.0), the following could occur:

    device sends amessage with 512 byte payload
    client reads amessage
    client tries to read payload with a length of 1024

In this scenario, the kernel will block, waiting for an additional
packet which won't arrive until something else gets sent across the
wire, which will result in the previous read failing, and the new
packet being dropped.

Bug: http://b/37783561
Test: python test_device.py on linux/darwin, with native/libusb
Change-Id: I556f5344945e22dd1533b076f662a97eea24628e
2017-05-03 12:32:39 -07:00
Yabin Cui
b5e11415d9 adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.

1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.

The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.

2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.

The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.

To be safe, this patch doesn't change any logic on device.

Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-04-20 10:14:59 -07:00
Josh Gao
79ce3fe7db adb: be more permissive in test_push_error_reporting.
Be agnostic to whether /system is writable when testing push error
reporting.

Test: python test_device.py
Change-Id: I1d03564fa35442c20e2c96a7f5b56d39868efc52
2016-11-21 18:39:21 -08:00
Josh Gao
63660add3f Merge changes I34ba5757,Ie65a762a
* changes:
  adb: fix test_sighup.
  adb: fix race condition in test_non_interactive_sigint.
2016-10-24 21:13:18 +00:00
Josh Gao
470622f064 adb: fix test_sighup.
Bug: http://b/32336914
Test: python test_device.py
Change-Id: I34ba5757b5e650d79327dc6779064acd850ce28e
2016-10-24 13:34:20 -07:00
Josh Gao
e76b9f3dde adb: fix race condition in test_non_interactive_sigint.
Fix race condition in the test_non_interactive_sigint test by
looping for a while.

Bug: http://b/32336914
Test: python test_device.py
Change-Id: Ie65a762ad6f04815231add5444762c4c0ffd31cb
2016-10-24 13:34:17 -07:00
Elliott Hughes
cabfa1177f Move "adb shell" over to getopt(3), and allow -tt on old devices.
From the bug:

  Say we run a new adb against an old device (like KitKat). Even with a new
  client ADB, in this configuration, "adb shell" will create a remove tty
  unconditionally. So if the user runs "adb shell -t -t", we shouldn't fail
  with a message about the remote device not supporting -tT options --- the
  user asked to create a tty unconditionally, and since we're going to create
  a tty unconditionally, we should just succeed. (That it's going to succeed
  due to protocol inadequacy instead of succeeding on purpose is irrelevant.)

  That adb fails in this case makes scripts more complicated, since they can't
  just pass "-t -t" unconditionally if they want a tty and to work on all
  device versions, even if the script requires a new-ish adb locally.

Bug: http://b/32216152
Bug: http://b/32219151
Test: test_device.py
Change-Id: I8ab7c8dfa212209a7ab43c1f0832eeac26d2e42f
2016-10-21 14:22:40 -07:00
Josh Gao
94dc19ff57 adb: let adb push follow symlinks.
Bug: http://b/31491920
Test: touch foo; ln -s foo bar; adb push bar /data/local/tmp
Test: python test_device.py
Change-Id: I0a00b3d49fdf7206e27d66ac110b56e22449a1ad
2016-09-14 17:08:22 -07:00
Josh Gao
fe50bb713b adb: add test for SIGHUP behavior.
This keeps regressing, so add a test to keep this from happening.

Bug: http://b/23603716
Bug: http://b/25965770
Bug: http://b/29565233
Test: Ran test with/without commit cd5d737, fails before, passes after
Change-Id: I8c431e10fc76da5a9fd404dd70f17bb8a8df24e6
2016-06-23 15:01:50 -07:00
David Pursell
eaae97e127 adb: support forwarding TCP port 0.
This CL adds support to forward or reverse TCP port 0 to allow the
system to automatically select an open port. The resolved port number
will be printed to stdout:
  $ adb forward tcp:0 tcp:8000
  12345
  $ adb reverse tcp:0 tcp:9000
  23456
This allows testing to be more robust by not hardcoding TCP ports which
may already be in use.

Forwarding port 0 is a host-only change and will work with any device,
but reversing port 0 requires the device to be updated with a new adbd
binary.

This CL also does a little bit of cleanup such as moving the alistener
class out of adb.h, and adds some error checking and additional tests.

Bug: 28051746
Test: python -m unittest discover
Test: adb_test
Test: `adb forward` and `adb reverse` with tcp:0
Change-Id: Icaa87346685b403ab5da7f0e6aa186aa091da572
2016-05-09 16:55:10 -07:00
David Pursell
cf46741b4f adb: fix test_device.py shell protocol checks.
https://android-review.googlesource.com/#/c/210646/ added a
has_shell_protocol() function but the test_device.py tests were still
trying to use the now-missing SHELL_PROTOCOL_FEATURE constant.

This CL just switches test_device.py to correctly use the
has_shell_protocol() method.

Change-Id: Ie0a2f0dc07529843d25051a01e08fb677551a4e1
Test: `python -m unittest discover -v` on devices with and without
      the shell protocol.
2016-04-26 13:29:39 -07:00
Josh Gao
255c5c8077 adb: clean up quotes in test_device.py.
Change-Id: I7fe7724578ad89a004665d1bbff0d5c02c34c35e
2016-03-03 14:53:52 -08:00
Josh Gao
89ec3a8d0f adb: mkdir the correct directory name when pulling.
The directory name should be based off of the local path, not the remote
path.

Change-Id: I75b089b8734e9dbf8e466b1e00ea18549fd101bb
2016-03-03 14:53:06 -08:00
Josh Gao
1e611a33d5 adb: symlinks to dirs count as dirs for pull destination.
This matches scp's behavior when pulling a directory that collides
with a symlink to a directory.

Bug: http://b/27362811
Change-Id: I0936d1ad48f13e24cd382e8e8400cc752bac3b66
2016-03-02 15:29:02 -08:00
Josh Gao
afcdcd703e adb: check for an error response from adbd between each write.
When sending a file, do a 0-timeout poll to check to see if an error has
occurred, so that we can immediately report failure.

Bug: http://b/26816782
Change-Id: I4a8aa8408a36940bfda7b0ecfa5d13755f4aa14d
2016-02-19 18:01:09 -08:00
Josh Gao
f264224191 adb: make pulling symlinks and devices work.
Bug: http://b/25972989
Bug: http://b/26085751
Change-Id: I43842871522ea5f67a8c258dcb6ddafa8dd744c8
2015-12-11 12:51:38 -08:00
Josh Gao
ce8f2cdcd0 adb: make the test_pull_dir test actually test something.
Change-Id: I8b525377557528d5bc70c44d587891fad9f739bd
2015-12-09 14:41:33 -08:00
Josh Gao
191c154832 Move adb tests to system/core/adb.
Change-Id: If240f45817a46d1e055a8e5173ee7191b9d6c8ea
2015-12-09 11:26:11 -08:00
Dan Albert
8858883388 Move python-adb to development/python-packages.
We want to be able to use this in the NDK without having to pull in
all of system core.

Also, this clarifies the separation of adb and its python interface.

Bug: http://b/22881740
Change-Id: I0b437d9bf621e371d4698d7f8e8828072c7ff347
2015-09-18 13:39:13 -07:00
Elliott Hughes
1d758c9095 Merge "adb unittest: make test_sync properly cleanup after itself" 2015-09-17 03:03:31 +00:00
David Pursell
544e795fbb adb: Kill subprocess when the client exits.
When the client exits (e.g. with Ctrl+C) the subprocess should be
notified as well so it can cleanup if needed.

Bug: http://b/23825725
Change-Id: Idb771710b293e0a9f7bebc9e2814b3a816e2c50e
2015-09-15 10:16:24 -07:00
Spencer Low
80fdc0bf86 adb unittest: make test_sync properly cleanup after itself
It wasn't deleting the tempfile.mkdtemp() dir that it made.

Change-Id: I59c5f98aa8297c7b28d38799dd21ffe9566f2145
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-14 18:53:25 -07:00
David Pursell
606835ae5c adb: add client side shell protocol and enable.
Adds the shell protocol functionality to the client side and enables it
if the transport supports the feature.

Bug:http://b/23031026
Change-Id: I9abe1c8b1d39f8dd09666321b1c761ad708a8854
2015-09-11 13:02:17 -07:00
Elliott Hughes
a54f14eb95 Merge "adb unittest: get test_unicode_paths passing on win32" 2015-08-28 20:00:53 +00:00
Spencer Low
d8cce1817b adb: fix adb install and adb push exit code, error handling, unittest
adb push was not returning a bad exit code when write_data_file() or
write_data_link() failed. I encountered this when running the unittest
on Windows which can get into situations where stat() succeeds, but
open() fails due to pre-existing exclusive file access (which typically
doesn't exist on unix).

The same code is used by adb install, so this also fixes its error
handling.

Fixed some fd leaks and propagation of errors when reading a file.

Fixed a unittest to close temp files before reading them.

Change-Id: Ieba0026fa4c79eb0484676e4f2faaac9603ef584
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-28 11:38:28 -07:00
Spencer Low
de4505f819 adb unittest: get test_unicode_paths passing on win32
The Python 2 subprocess class doesn't use Unicode, so as a work-around
write the command line to a UTF-8 batch file and run that.

I modified the test to use u'blah' without .encode('utf-8') because the
Python docs recommend dealing with string variables like that. When
formatting a string with a unicode parameter, use u'foo' on the constant
string to make it unicode.

I also tested this on Linux and it seems to work fine (I did ls in the
middle of the test to make sure the filenames came out right, etc.).

I had to close the temporary files before adb tries to read/write them
because filesystem semantics are different on Windows (technically I
might be able to modify adb to try to open files with more permissive
share flags, but then I'm not sure if Python uses the right share flags.
Basically, I'd be opening another can of worms.).

Fixed the test to delete a temp file on the device once it is done.

Change-Id: Id0c34e26d7697fbbb47a44ae45298bed5e8c59d6
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-28 01:20:03 -07:00
David Pursell
d4093f191b adb: Fix PTY logic for non-interactive shells.
Change `adb shell` so that interactive sessions use a PTY but
non-interactive do not. This matches `ssh` functionality better
and also enables future work to split stdout/stderr for
non-interactive sessions.

A test to verify this behavior is added to test_device.py with
supporting modifications in device.py.

Bug: http://b/21215503
Change-Id: Ib4ba40df85f82ddef4e0dd557952271c859d1c7b
2015-08-12 14:16:22 -07:00
Elliott Hughes
3841a9f7cb Leave the evidence lying around if an adb test fails.
Not seeing the full output from the failed adb command is probably
the biggest issue when debugging a test failure, but this doesn't
help either.

Change-Id: Ic42cbced8be252185a799b27c210a744188a4201
2015-08-03 13:58:49 -07:00
Spencer Low
3e7feda3c5 adb/test_device.py fixes for win32 and no use of ANDROID_SERIAL
If ANDROID_SERIAL was not set, test_device.py was failing.

Use posixpath.join instead of os.path.join for make_random_device_files.

Change-Id: I24bfa43ba2a89a9a768f505fc0bba9d873082b2f
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-07-30 01:19:52 -07:00