1*d173ce4aSRyan Prichard#!/usr/bin/env bash 2*d173ce4aSRyan Prichard# ===----------------------------------------------------------------------===## 3*d173ce4aSRyan Prichard# 4*d173ce4aSRyan Prichard# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*d173ce4aSRyan Prichard# See https://llvm.org/LICENSE.txt for license information. 6*d173ce4aSRyan Prichard# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*d173ce4aSRyan Prichard# 8*d173ce4aSRyan Prichard# ===----------------------------------------------------------------------===## 9*d173ce4aSRyan Prichard 10*d173ce4aSRyan Prichardset -ex 11*d173ce4aSRyan Prichard 12*d173ce4aSRyan Prichard# Time to wait in seconds. The emulator ought to start in 5-15 seconds or so, 13*d173ce4aSRyan Prichard# so add a safety factor in case something takes longer in CI. 14*d173ce4aSRyan PrichardTIMEOUT=${1-300} 15*d173ce4aSRyan Prichard 16*d173ce4aSRyan Prichard# This syntax (using an IP address of 127.0.0.1 rather than localhost) seems to 17*d173ce4aSRyan Prichard# prevent the adb client from ever spawning an adb host server. 18*d173ce4aSRyan Prichardexport ADB_SERVER_SOCKET=tcp:127.0.0.1:5037 19*d173ce4aSRyan Prichard 20*d173ce4aSRyan Prichard# Invoke nc first to ensure that something is listening to port 5037. Otherwise, 21*d173ce4aSRyan Prichard# invoking adb might fork an adb server. 22*d173ce4aSRyan Prichard# 23*d173ce4aSRyan Prichard# TODO: Consider waiting for `adb shell getprop dev.bootcomplete 2>/dev/null 24*d173ce4aSRyan Prichard# | grep 1 >/dev/null` as well. It adds ~4 seconds to 21-def-x86 and ~15 seconds 25*d173ce4aSRyan Prichard# to 33-goog-x86_64 and doesn't seem to be necessary for running libc++ tests. 26*d173ce4aSRyan Prichardtimeout ${TIMEOUT} bash -c ' 27*d173ce4aSRyan Pricharduntil (nc -z localhost 5037 && adb wait-for-device); do 28*d173ce4aSRyan Prichard sleep 0.5 29*d173ce4aSRyan Pricharddone 30*d173ce4aSRyan Prichard' 31