提交 2e3b2be6 编写于 作者: L Liangliang He

Prefer to select unlocked devices in CI

上级 7d53c473
...@@ -9,3 +9,4 @@ mace/codegen/opencl_bin/ ...@@ -9,3 +9,4 @@ mace/codegen/opencl_bin/
mace/codegen/tuning/ mace/codegen/tuning/
mace/codegen/version/ mace/codegen/version/
build/ build/
docs/_build/
...@@ -86,6 +86,11 @@ def main(unused_args): ...@@ -86,6 +86,11 @@ def main(unused_args):
target_socs = set(FLAGS.target_socs.split(',')) target_socs = set(FLAGS.target_socs.split(','))
target_devices = sh_commands.adb_devices(target_socs=target_socs) target_devices = sh_commands.adb_devices(target_socs=target_socs)
if FLAGS.target_socs == "random": if FLAGS.target_socs == "random":
unlocked_devices = \
[d for d in target_devices if not sh_commands.is_device_locked(d)]
if len(unlocked_devices) > 0:
target_devices = [random.choice(unlocked_devices)]
else:
target_devices = [random.choice(target_devices)] target_devices = [random.choice(target_devices)]
target = FLAGS.target target = FLAGS.target
......
...@@ -20,6 +20,22 @@ def make_output_processor(buff): ...@@ -20,6 +20,22 @@ def make_output_processor(buff):
return process_output return process_output
def device_lock_path(serialno):
return "/tmp/device-lock-%s" % serialno
def device_lock(serialno, timeout=3600):
return filelock.FileLock(device_lock_path(serialno), timeout=timeout)
def is_device_locked(serialno):
try:
with device_lock(serialno, timeout=0.000001):
return False
except filelock.Timeout:
return True
################################ ################################
# adb commands # adb commands
################################ ################################
...@@ -90,11 +106,10 @@ def adb_run(serialno, ...@@ -90,11 +106,10 @@ def adb_run(serialno,
print( print(
"=====================================================================" "====================================================================="
) )
lock_path = "/tmp/device-lock-%s" % serialno print("Trying to lock device", serialno)
print("Try to lock ", lock_path) with device_lock(serialno):
with filelock.FileLock(lock_path, timeout=3600): print("Run on device: %s, %s, %s" %
print("Run on device: %s, %s, %s" % (serialno, (serialno, props["ro.board.platform"],
props["ro.board.platform"],
props["ro.product.model"])) props["ro.product.model"]))
sh.adb("-s", serialno, "shell", "rm -rf %s" % device_bin_path) sh.adb("-s", serialno, "shell", "rm -rf %s" % device_bin_path)
sh.adb("-s", serialno, "shell", "mkdir -p %s" % device_bin_path) sh.adb("-s", serialno, "shell", "mkdir -p %s" % device_bin_path)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册