From efd8ae2d54a74c13144255954f71c845db48728b Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 16 Jul 2019 15:08:42 -0700 Subject: [PATCH 1/3] adb: win32: fix adb_test. At some point between Q and master, adb_test.exe stopped working because it wasn't being linked with -municode? Test: wine adb_test.exe Change-Id: I6c20f3b3241cee2052d31d1ca85b8a9738828f6e --- adb/Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/adb/Android.bp b/adb/Android.bp index f6aede818..ef5057aaf 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -221,6 +221,7 @@ cc_test_host { target: { windows: { enabled: true, + ldflags: ["-municode"], shared_libs: ["AdbWinApi"], }, }, From 2ad4c3696fd4b8957b31e33eebb2e0b8f4d167e9 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 16 Jul 2019 15:19:53 -0700 Subject: [PATCH 2/3] adb: win32: silence wine test failure. Wine implements sockets with their own internal socketpair, which results in the poll disconnect test failing. Bug: http://b/117568356 Test: wine adb_test.exe Change-Id: Icd2a94f8297fefd5c02e6517568fe288b168032c --- adb/sysdeps_test.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/adb/sysdeps_test.cpp b/adb/sysdeps_test.cpp index 79cebe6b5..0f4b39c1f 100644 --- a/adb/sysdeps_test.cpp +++ b/adb/sysdeps_test.cpp @@ -25,6 +25,21 @@ #include "sysdeps.h" #include "sysdeps/chrono.h" +#if defined(_WIN32) +#include +static bool IsWine() { + HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); + if (!ntdll) { + return false; + } + return GetProcAddress(ntdll, "wine_get_version") != nullptr; +} +#else +static bool IsWine() { + return false; +} +#endif + TEST(sysdeps_socketpair, smoke) { int fds[2]; ASSERT_EQ(0, adb_socketpair(fds)) << strerror(errno); @@ -182,8 +197,10 @@ TEST_F(sysdeps_poll, disconnect) { EXPECT_EQ(1, adb_poll(&pfd, 1, 100)); - // Linux returns POLLIN | POLLHUP, Windows returns just POLLHUP. - EXPECT_EQ(POLLHUP, pfd.revents & POLLHUP); + if (!IsWine()) { + // Linux returns POLLIN | POLLHUP, Windows returns just POLLHUP. + EXPECT_EQ(POLLHUP, pfd.revents & POLLHUP); + } } TEST_F(sysdeps_poll, fd_count) { From 08bd13eb3d2734dd6a418442295923074d5ce81b Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 16 Jul 2019 14:31:41 -0700 Subject: [PATCH 3/3] adb: win32: don't shutdown socket when closing. This appears to be an attempt to do orderly shutdown, but it doesn't wait until the socket becomes readable, so it doesn't actually work. We implement orderly shutdown elsewhere already, so delete this so that we don't accidentally shutdown a duped socket. Test: wine adb_test Change-Id: I35f8843e8e6dbc7886fd545f0e43375a005e160f --- adb/sysdeps_win32.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/adb/sysdeps_win32.cpp b/adb/sysdeps_win32.cpp index f86cd03b0..6372b3dc6 100644 --- a/adb/sysdeps_win32.cpp +++ b/adb/sysdeps_win32.cpp @@ -610,15 +610,6 @@ static void _fh_socket_init(FH f) { static int _fh_socket_close(FH f) { if (f->fh_socket != INVALID_SOCKET) { - /* gently tell any peer that we're closing the socket */ - if (shutdown(f->fh_socket, SD_BOTH) == SOCKET_ERROR) { - // If the socket is not connected, this returns an error. We want to - // minimize logging spam, so don't log these errors for now. -#if 0 - D("socket shutdown failed: %s", - android::base::SystemErrorCodeToString(WSAGetLastError()).c_str()); -#endif - } if (closesocket(f->fh_socket) == SOCKET_ERROR) { // Don't set errno here, since adb_close will ignore it. const DWORD err = WSAGetLastError();