Added Java tests support to run.py

pull/13383/head
Andrey Kamaev 13 years ago
parent ee682493fd
commit 74cc370c74
  1. 68
      modules/ts/misc/run.py

@ -272,6 +272,10 @@ class RunInfo(object):
self.adb = self.adb + ["-s", adb_serial]
print "adb command:", " ".join(self.adb)
if self.adb:
#construct name for aapt tool
self.aapt = [os.path.join(os.path.dirname(self.adb[0]), ("aapt","aapt.exe")[hostos == 'nt'])]
# fix has_perf_tests param
self.has_perf_tests = self.has_perf_tests == "ON"
self.has_accuracy_tests = self.has_accuracy_tests == "ON"
@ -379,13 +383,14 @@ class RunInfo(object):
return False
if hostos == self.targetos:
return os.access(fullpath, os.X_OK)
if self.targetos == "android" and fullpath.endswith(".apk"):
return True
return True
def getAvailableTestApps(self):
if self.tests_dir and os.path.isdir(self.tests_dir):
files = glob.glob(os.path.join(self.tests_dir, self.nameprefix + "*"))
if self.targetos == hostos:
files = [f for f in files if self.isTest(f)]
files = [f for f in files if self.isTest(f)]
return files
return []
@ -513,6 +518,10 @@ class RunInfo(object):
fullname += ".exe"
if self.isTest(fullname):
return fullname
if self.targetos == "android":
fullname += ".apk"
if self.isTest(fullname):
return fullname
# short name for OpenCV tests
for t in self.tests:
@ -521,7 +530,7 @@ class RunInfo(object):
fname = os.path.basename(t)
if fname == name:
return t
if fname.endswith(".exe"):
if fname.endswith(".exe") or (self.targetos == "android" and fname.endswith(".apk")):
fname = fname[:-4]
if fname == name:
return t
@ -583,7 +592,57 @@ class RunInfo(object):
else:
logfile = userlog[0][userlog[0].find(":")+1:]
if self.targetos == "android":
if self.targetos == "android" and exe.endswith(".apk"):
print "running", exe
try:
# get package info
output = Popen(self.aapt + ["dump", "xmltree", exe, "AndroidManifest.xml"], stdout=PIPE, stderr=_stderr).communicate()
if not output[0]:
print >> _stderr, "failed to get manifest info from", exe
return
tags = re.split(r"[ ]+E: ", output[0])
#get package name
manifest_tag = [t for t in tags if t.startswith("manifest ")]
if not manifest_tag:
print >> _stderr, "failed to get manifest info from", exe
return
pkg_name = re.search(r"^[ ]+A: package=\"(?P<pkg>.*?)\" \(Raw: \"(?P=pkg)\"\)$", manifest_tag[0], flags=re.MULTILINE).group("pkg")
#get test instrumentation info
instrumentation_tag = [t for t in tags if t.startswith("instrumentation ")]
if not instrumentation_tag:
print >> _stderr, "can not find instrumentation detials in", exe
return
pkg_runner = re.search(r"^[ ]+A: android:name\(0x[0-9a-f]{8}\)=\"(?P<runner>.*?)\" \(Raw: \"(?P=runner)\"\)$", instrumentation_tag[0], flags=re.MULTILINE).group("runner")
pkg_target = re.search(r"^[ ]+A: android:targetPackage\(0x[0-9a-f]{8}\)=\"(?P<pkg>.*?)\" \(Raw: \"(?P=pkg)\"\)$", instrumentation_tag[0], flags=re.MULTILINE).group("pkg")
if not pkg_name or not pkg_runner or not pkg_target:
print >> _stderr, "can not find instrumentation detials in", exe
return
if self.options.junit_package:
if self.options.junit_package.startswith("."):
pkg_target += self.options.junit_package
else:
pkg_target = self.options.junit_package
#uninstall already installed package
print >> _stderr, "Uninstalling old", pkg_name, "from device..."
output = Popen(self.adb + ["uninstall", pkg_name], stdout=_stdout, stderr=_stderr).wait()
if output != 0:
print >> _stderr, "failed to uninstall", pkg_name, "from device"
return
print >> _stderr, "Installing new", exe, "to device..."
output = Popen(self.adb + ["install", exe], stdout=_stdout, stderr=_stderr).wait()
if output != 0:
print >> _stderr, "failed to install", exe, "to device"
return
print >> _stderr, "Running jUnit tests for ", pkg_target
if self.setUp is not None:
self.setUp()
Popen(self.adb + ["shell", "am instrument -w -e package " + pkg_target + " " + pkg_name + "/" + pkg_runner], stdout=_stdout, stderr=_stderr).wait()
if self.tearDown is not None:
self.tearDown()
except OSError:
pass
return
elif self.targetos == "android":
hostlogpath = ""
try:
andoidcwd = "/data/bin/" + getpass.getuser().replace(" ","") + "_" + self.options.mode +"/"
@ -687,6 +746,7 @@ if __name__ == "__main__":
parser.add_option("", "--android_test_data_path", dest="test_data_path", help="OPENCV_TEST_DATA_PATH for Android run", metavar="PATH", default="/sdcard/opencv_testdata/")
parser.add_option("", "--configuration", dest="configuration", help="force Debug or Release donfiguration", metavar="CFG", default="")
parser.add_option("", "--serial", dest="adb_serial", help="Android: directs command to the USB device or emulator with the given serial number", metavar="serial number", default="")
parser.add_option("", "--package", dest="junit_package", help="Android: run jUnit tests for specified package", metavar="package", default="")
parser.add_option("", "--help-tests", dest="help", help="Show help for test executable", action="store_true", default=False)
(options, args) = parser.parse_args(argv)

Loading…
Cancel
Save