Commit graph

60 commits

Author SHA1 Message Date
Josh Gao
e4d66fc678 adbd: add a perfunctory abb test.
Bug: http://b/148838069
Test: python3 -m unittest test_device.AbbTest
Change-Id: Ia8f83a535d4a513f4bdce5cfa4bfe69cd2dbb634
2020-02-07 15:59:49 -08:00
Josh Gao
93dee964d4 adb: switch tests to python3.
Test: treehugger
Change-Id: Ia1f6a659e23f5d9e63c9b106c60d56b5b954b19c
2020-02-07 15:59:49 -08:00
Josh Gao
63da8e6272 adb: use poll instead of select in shell_service.
Bug: http://b/141955761
Test: test_device.py
Test: adbd_test
Change-Id: I8976304a1011e81e85f8d90d95d36ecd82834f5f
2019-12-18 14:02:57 -08:00
Josh Gao
ea3f43ccf2 adb: disable failing test.
Bug: http://b/141943968
Bug: http://b/141923622
Test: python -m unittest test_device.FileOperationsTest
Change-Id: Ie384c71c3d6875db74982a398fb66f035ce9f408
2019-10-01 14:15:31 -07:00
Treehugger Robot
070c030289 Merge "adb: fix infinite loop when attempting to push to //foo." 2019-09-25 19:59:51 +00:00
Josh Gao
76b64ba826 adb: fix infinite loop when attempting to push to //foo.
dirname (on glibc, at least) preserves multiple leading slashes, and we
were looping until path != "/", which would lead to an infinite loop
when attempting to push to a path like //data/local/tmp.

Bug: http://b/141311284
Test: python -m unittest test_device.FileOperationsTest.test_push_multiple_slash_root
Change-Id: I182b3e89ef52579c716fdb525e9215f1fe822477
2019-09-26 01:56:58 +08:00
Josh Gao
727b07b260 adb: fix old host transport selection.
We regressed handling of the old host transport selection syntax, which
broke users that reimplement adb themselves (e.g. Studio via ddmlib).

Bug: https://issuetracker.google.com/140369526
Test: adb raw "host-serial:822X0028S:forward:tcp:42929;localabstract:/com.example.ndktest-0/platform-1568299082100.sock"
Test: ./test_device.py
Change-Id: Iaaec8fde952316fe9bf2a6f6c6c4a3bc9f74bf72
2019-09-13 00:26:37 +08:00
Josh Gao
74b7ec72f8 adb: don't close sockets before hitting EOF.
Reimplement commit ffc11d3cf3 using
fdevent. The previous attempt was reverted because we were blindly
continuing when revents & POLLIN == 0, which ignored POLLHUP/POLLERR,
leading to spinloops when the opposite end of the file descriptor was
shutdown when we had no data left to read.

This patch reimplements the functionality implemented by that commit
using fdevent, which gets us detection of spin loops for free.

Bug: http://b/74616284
Test: ./test_device.py
Change-Id: I1abd671fef4c29e99dad968aa66bb754ca382578
2019-01-31 23:36:41 -08:00
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