From 676f375d9b3a8fa74149dd511f38884e0887ce5c Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 7 Aug 2018 16:07:25 -0700 Subject: [PATCH] adb: make test_adb.py work on windows. Switch from os.pipe to socket.socketpair for the fake adbd termination termination signaller, that we can select on it on windows. Test: test_adb.py on windows (2 failures on windows) Change-Id: I37df06e465ec8be28cfb18a5c21ef30125195004 --- adb/test_adb.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/adb/test_adb.py b/adb/test_adb.py index 173251a2f..f82617a9b 100755 --- a/adb/test_adb.py +++ b/adb/test_adb.py @@ -44,7 +44,7 @@ def fake_adbd(protocol=socket.AF_INET, port=0): serversock.listen(1) # A pipe that is used to signal the thread that it should terminate. - readpipe, writepipe = os.pipe() + readsock, writesock = socket.socketpair() def _adb_packet(command: bytes, arg0: int, arg1: int, data: bytes) -> bytes: bin_command = struct.unpack('I', command)[0] @@ -55,19 +55,15 @@ def fake_adbd(protocol=socket.AF_INET, port=0): def _handle(sock): with contextlib.closing(sock) as serversock: - rlist = [readpipe, serversock] + rlist = [readsock, serversock] cnxn_sent = {} while True: read_ready, _, _ = select.select(rlist, [], []) for ready in read_ready: - if ready == readpipe: + if ready == readsock: # Closure pipe - serversock.shutdown(socket.SHUT_RDWR) for f in rlist: - if isinstance(f, int): - os.close(f) - else: - f.close() + f.close() return elif ready == serversock: # Server socket @@ -96,7 +92,7 @@ def fake_adbd(protocol=socket.AF_INET, port=0): try: yield port finally: - os.close(writepipe) + writesock.close() server_thread.join()