run.py: improve handling of multiple Android devices
* do not lose auto-selected device while running several tests * reduce output noise * list available devices if unable to auto-select device * fix error message when no devices connected
This commit is contained in:
parent
f45b5b13f1
commit
9db1d9ba13
@ -267,17 +267,21 @@ class RunInfo(object):
|
|||||||
else:
|
else:
|
||||||
# assume here that device name may consists of any characters except newline
|
# assume here that device name may consists of any characters except newline
|
||||||
connected_devices = re.findall(r"^[^\n]+[ \t]+device\r?$", adb_res, re.MULTILINE)
|
connected_devices = re.findall(r"^[^\n]+[ \t]+device\r?$", adb_res, re.MULTILINE)
|
||||||
if len(connected_devices) != 1:
|
if not connected_devices:
|
||||||
self.error = "Too many (%s) devices are connected. Please specify single device using --serial option" % (len(connected_devices))
|
self.error = "Android device not found"
|
||||||
|
self.adb = []
|
||||||
|
elif len(connected_devices) != 1:
|
||||||
|
self.error = "Too many (%s) devices are connected. Please specify single device using --serial option:\n\n" % (len(connected_devices)) + adb_res
|
||||||
self.adb = []
|
self.adb = []
|
||||||
else:
|
else:
|
||||||
adb_serial = connected_devices[0].split("\t")[0]
|
options.adb_serial = connected_devices[0].split("\t")[0]
|
||||||
self.adb = self.adb + ["-s", adb_serial]
|
self.adb = self.adb + ["-s", options.adb_serial]
|
||||||
print "adb command:", " ".join(self.adb)
|
if self.adb:
|
||||||
|
print "adb command:", " ".join(self.adb)
|
||||||
|
|
||||||
if self.adb:
|
if self.adb:
|
||||||
#construct name for aapt tool
|
#construct name for aapt tool
|
||||||
self.aapt = [os.path.join(os.path.dirname(self.adb[0]), ("aapt","aapt.exe")[hostos == 'nt'])]
|
self.aapt = [os.path.join(os.path.dirname(self.adb[0]), ("aapt","aapt.exe")[hostos == 'nt'])]
|
||||||
|
|
||||||
# fix has_perf_tests param
|
# fix has_perf_tests param
|
||||||
self.has_perf_tests = self.has_perf_tests == "ON"
|
self.has_perf_tests = self.has_perf_tests == "ON"
|
||||||
@ -688,13 +692,12 @@ class RunInfo(object):
|
|||||||
exename = os.path.basename(exe)
|
exename = os.path.basename(exe)
|
||||||
androidexe = andoidcwd + exename
|
androidexe = andoidcwd + exename
|
||||||
#upload
|
#upload
|
||||||
print >> _stderr, "Uploading", exename, "to device..."
|
_stderr.write("Uploading... ")
|
||||||
output = Popen(self.adb + ["push", exe, androidexe], stdout=_stdout, stderr=_stderr).wait()
|
output = Popen(self.adb + ["push", exe, androidexe], stdout=_stdout, stderr=_stderr).wait()
|
||||||
if output != 0:
|
if output != 0:
|
||||||
print >> _stderr, "adb finishes unexpectedly with error code", output
|
print >> _stderr, "adb finishes unexpectedly with error code", output
|
||||||
return
|
return
|
||||||
#chmod
|
#chmod
|
||||||
print >> _stderr, "Changing mode of ", androidexe
|
|
||||||
output = Popen(self.adb + ["shell", "chmod 777 " + androidexe], stdout=_stdout, stderr=_stderr).wait()
|
output = Popen(self.adb + ["shell", "chmod 777 " + androidexe], stdout=_stdout, stderr=_stderr).wait()
|
||||||
if output != 0:
|
if output != 0:
|
||||||
print >> _stderr, "adb finishes unexpectedly with error code", output
|
print >> _stderr, "adb finishes unexpectedly with error code", output
|
||||||
@ -704,7 +707,7 @@ class RunInfo(object):
|
|||||||
command = exename + " --help"
|
command = exename + " --help"
|
||||||
else:
|
else:
|
||||||
command = exename + " " + " ".join(args)
|
command = exename + " " + " ".join(args)
|
||||||
print >> _stderr, "Running:", command
|
print >> _stderr, "Run command:", command
|
||||||
if self.setUp is not None:
|
if self.setUp is not None:
|
||||||
self.setUp()
|
self.setUp()
|
||||||
Popen(self.adb + ["shell", "export OPENCV_TEST_DATA_PATH=" + self.test_data_path + "&& cd " + andoidcwd + "&& ./" + command], stdout=_stdout, stderr=_stderr).wait()
|
Popen(self.adb + ["shell", "export OPENCV_TEST_DATA_PATH=" + self.test_data_path + "&& cd " + andoidcwd + "&& ./" + command], stdout=_stdout, stderr=_stderr).wait()
|
||||||
@ -712,17 +715,17 @@ class RunInfo(object):
|
|||||||
self.tearDown()
|
self.tearDown()
|
||||||
# try get log
|
# try get log
|
||||||
if not self.options.help:
|
if not self.options.help:
|
||||||
print >> _stderr, "Pulling", logfile, "from device..."
|
#_stderr.write("Pull log... ")
|
||||||
hostlogpath = os.path.join(workingDir, logfile)
|
hostlogpath = os.path.join(workingDir, logfile)
|
||||||
output = Popen(self.adb + ["pull", andoidcwd + logfile, hostlogpath], stdout=_stdout, stderr=_stderr).wait()
|
output = Popen(self.adb + ["pull", andoidcwd + logfile, hostlogpath], stdout=_stdout, stderr=PIPE).wait()
|
||||||
if output != 0:
|
if output != 0:
|
||||||
print >> _stderr, "adb finishes unexpectedly with error code", output
|
print >> _stderr, "adb finishes unexpectedly with error code", output
|
||||||
return
|
return
|
||||||
#rm log
|
#rm log
|
||||||
Popen(self.adb + ["shell", "rm " + andoidcwd + logfile], stdout=_stdout, stderr=_stderr).wait()
|
Popen(self.adb + ["shell", "rm " + andoidcwd + logfile], stdout=PIPE, stderr=PIPE).wait()
|
||||||
|
|
||||||
# clean temporary files
|
# clean temporary files
|
||||||
Popen(self.adb + ["shell", "rm " + tempdir + "__opencv_temp.*"], stdout=_stdout, stderr=_stderr).wait()
|
Popen(self.adb + ["shell", "rm " + tempdir + "__opencv_temp.*"], stdout=PIPE, stderr=PIPE).wait()
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
if os.path.isfile(hostlogpath):
|
if os.path.isfile(hostlogpath):
|
||||||
@ -739,7 +742,7 @@ class RunInfo(object):
|
|||||||
temp_path = tempfile.mkdtemp(prefix="__opencv_temp.", dir=orig_temp_path or None)
|
temp_path = tempfile.mkdtemp(prefix="__opencv_temp.", dir=orig_temp_path or None)
|
||||||
os.environ['OPENCV_TEMP_PATH'] = temp_path
|
os.environ['OPENCV_TEMP_PATH'] = temp_path
|
||||||
|
|
||||||
print >> _stderr, "Running:", " ".join(cmd)
|
print >> _stderr, "Run command:", " ".join(cmd)
|
||||||
try:
|
try:
|
||||||
Popen(cmd, stdout=_stdout, stderr=_stderr, cwd = workingDir).wait()
|
Popen(cmd, stdout=_stdout, stderr=_stderr, cwd = workingDir).wait()
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -823,7 +826,7 @@ if __name__ == "__main__":
|
|||||||
tests = [s.strip() for s in options.tests.split(",") if s]
|
tests = [s.strip() for s in options.tests.split(",") if s]
|
||||||
|
|
||||||
if len(tests) != 1 or len(run_args) != 1:
|
if len(tests) != 1 or len(run_args) != 1:
|
||||||
#remove --gtest_output from params
|
# remove --gtest_output from params
|
||||||
test_args = [a for a in test_args if not a.startswith("--gtest_output=")]
|
test_args = [a for a in test_args if not a.startswith("--gtest_output=")]
|
||||||
|
|
||||||
logs = []
|
logs = []
|
||||||
@ -837,4 +840,4 @@ if __name__ == "__main__":
|
|||||||
logs.extend(info.runTests(tests, sys.stdout, sys.stderr, options.cwd, test_args))
|
logs.extend(info.runTests(tests, sys.stdout, sys.stderr, options.cwd, test_args))
|
||||||
|
|
||||||
if logs:
|
if logs:
|
||||||
print >> sys.stderr, "Collected:", " ".join(logs)
|
print >> sys.stderr, "Collected: ", " ".join(logs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user