mirror of
https://github.com/opencv/opencv.git
synced 2025-06-15 22:20:58 +08:00
ts: update run.py
Add information about python bindings
This commit is contained in:
parent
a901cc542b
commit
c57f145e90
@ -85,8 +85,8 @@ class TestSuite(object):
|
|||||||
return set(res)
|
return set(res)
|
||||||
|
|
||||||
def isTest(self, fullpath):
|
def isTest(self, fullpath):
|
||||||
if fullpath == "java":
|
if fullpath in ['java', 'python2', 'python3']:
|
||||||
return True
|
return self.options.mode == 'test'
|
||||||
if not os.path.isfile(fullpath):
|
if not os.path.isfile(fullpath):
|
||||||
return False
|
return False
|
||||||
if self.cache.getOS() == "nt" and not fullpath.endswith(".exe"):
|
if self.cache.getOS() == "nt" and not fullpath.endswith(".exe"):
|
||||||
@ -102,6 +102,14 @@ class TestSuite(object):
|
|||||||
return res + cmd
|
return res + cmd
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
def tryCommand(self, cmd):
|
||||||
|
try:
|
||||||
|
if 0 == execute(cmd, cwd = workingDir):
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
def runTest(self, path, logfile, workingDir, args = []):
|
def runTest(self, path, logfile, workingDir, args = []):
|
||||||
args = args[:]
|
args = args[:]
|
||||||
exe = os.path.abspath(path)
|
exe = os.path.abspath(path)
|
||||||
@ -109,6 +117,22 @@ class TestSuite(object):
|
|||||||
cmd = [self.cache.ant_executable, "-Dopencv.build.type=%s" % self.cache.build_type, "buildAndTest"]
|
cmd = [self.cache.ant_executable, "-Dopencv.build.type=%s" % self.cache.build_type, "buildAndTest"]
|
||||||
ret = execute(cmd, cwd = self.cache.java_test_binary_dir + "/.build")
|
ret = execute(cmd, cwd = self.cache.java_test_binary_dir + "/.build")
|
||||||
return None, ret
|
return None, ret
|
||||||
|
elif path in ['python2', 'python3']:
|
||||||
|
executable = os.getenv('OPENCV_PYTHON_BINARY', None)
|
||||||
|
if executable is None:
|
||||||
|
executable = path
|
||||||
|
if not self.tryCommand([executable, '--version']):
|
||||||
|
executable = 'python'
|
||||||
|
cmd = [executable, self.cache.opencv_home + '/modules/python/test/test.py', '--repo', self.cache.opencv_home, '-v'] + args
|
||||||
|
module_suffix = '' if not 'Visual Studio' in self.cache.cmake_generator else '/' + self.cache.build_type
|
||||||
|
env = {}
|
||||||
|
env['PYTHONPATH'] = self.cache.opencv_build + '/lib' + module_suffix + os.pathsep + os.getenv('PYTHONPATH', '')
|
||||||
|
if self.cache.getOS() == 'nt':
|
||||||
|
env['PATH'] = self.cache.opencv_build + '/bin' + module_suffix + os.pathsep + os.getenv('PATH', '')
|
||||||
|
else:
|
||||||
|
env['LD_LIBRARY_PATH'] = self.cache.opencv_build + '/bin' + os.pathsep + os.getenv('LD_LIBRARY_PATH', '')
|
||||||
|
ret = execute(cmd, cwd = workingDir, env = env)
|
||||||
|
return None, ret
|
||||||
else:
|
else:
|
||||||
if isColorEnabled(args):
|
if isColorEnabled(args):
|
||||||
args.append("--gtest_color=yes")
|
args.append("--gtest_color=yes")
|
||||||
@ -140,6 +164,9 @@ class TestSuite(object):
|
|||||||
more_args = []
|
more_args = []
|
||||||
exe = self.getTest(test)
|
exe = self.getTest(test)
|
||||||
|
|
||||||
|
if exe in ["java", "python2", "python3"]:
|
||||||
|
logname = None
|
||||||
|
else:
|
||||||
userlog = [a for a in args if a.startswith("--gtest_output=")]
|
userlog = [a for a in args if a.startswith("--gtest_output=")]
|
||||||
if len(userlog) == 0:
|
if len(userlog) == 0:
|
||||||
logname = self.getLogName(exe, date)
|
logname = self.getLogName(exe, date)
|
||||||
|
@ -22,13 +22,17 @@ class Err(Exception):
|
|||||||
def __init__(self, msg, *args):
|
def __init__(self, msg, *args):
|
||||||
self.msg = msg % args
|
self.msg = msg % args
|
||||||
|
|
||||||
def execute(cmd, silent = False, cwd = "."):
|
def execute(cmd, silent = False, cwd = ".", env = None):
|
||||||
try:
|
try:
|
||||||
log.debug("Run: %s", cmd)
|
log.debug("Run: %s", cmd)
|
||||||
|
if env:
|
||||||
|
for k in env:
|
||||||
|
log.debug(" Environ: %s=%s", k, env[k])
|
||||||
|
env = os.environ.update(env)
|
||||||
if silent:
|
if silent:
|
||||||
return check_output(cmd, stderr = STDOUT, cwd = cwd).decode("latin-1")
|
return check_output(cmd, stderr = STDOUT, cwd = cwd, env = env).decode("latin-1")
|
||||||
else:
|
else:
|
||||||
return check_call(cmd, cwd = cwd)
|
return check_call(cmd, cwd = cwd, env = env)
|
||||||
except CalledProcessError as e:
|
except CalledProcessError as e:
|
||||||
if silent:
|
if silent:
|
||||||
log.debug("Process returned: %d", e.returncode)
|
log.debug("Process returned: %d", e.returncode)
|
||||||
@ -171,6 +175,8 @@ parse_patterns = (
|
|||||||
{'name': "cuda_library", 'default': None, 'pattern': re.compile(r"^CUDA_CUDA_LIBRARY:FILEPATH=(.+)$")},
|
{'name': "cuda_library", 'default': None, 'pattern': re.compile(r"^CUDA_CUDA_LIBRARY:FILEPATH=(.+)$")},
|
||||||
{'name': "cuda_version", 'default': None, 'pattern': re.compile(r"^CUDA_VERSION:STRING=(.+)$")},
|
{'name': "cuda_version", 'default': None, 'pattern': re.compile(r"^CUDA_VERSION:STRING=(.+)$")},
|
||||||
{'name': "core_dependencies", 'default': None, 'pattern': re.compile(r"^opencv_core_LIB_DEPENDS:STATIC=(.+)$")},
|
{'name': "core_dependencies", 'default': None, 'pattern': re.compile(r"^opencv_core_LIB_DEPENDS:STATIC=(.+)$")},
|
||||||
|
{'name': "python2", 'default': None, 'pattern': re.compile(r"^BUILD_opencv_python2:BOOL=(.*)$")},
|
||||||
|
{'name': "python3", 'default': None, 'pattern': re.compile(r"^BUILD_opencv_python3:BOOL=(.*)$")},
|
||||||
)
|
)
|
||||||
|
|
||||||
class CMakeCache:
|
class CMakeCache:
|
||||||
@ -247,11 +253,15 @@ class CMakeCache:
|
|||||||
files = glob.glob(os.path.join(d, mask))
|
files = glob.glob(os.path.join(d, mask))
|
||||||
if not self.getOS() == "android" and self.withJava():
|
if not self.getOS() == "android" and self.withJava():
|
||||||
files.append("java")
|
files.append("java")
|
||||||
|
if self.withPython2():
|
||||||
|
files.append("python2")
|
||||||
|
if self.withPython3():
|
||||||
|
files.append("python3")
|
||||||
return [f for f in files if isGood(f)]
|
return [f for f in files if isGood(f)]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def isMainModule(self, name):
|
def isMainModule(self, name):
|
||||||
return name in self.main_modules
|
return name in self.main_modules + ['python2', 'python3']
|
||||||
|
|
||||||
def withCuda(self):
|
def withCuda(self):
|
||||||
return self.cuda_version and self.with_cuda == "ON" and self.cuda_library and not self.cuda_library.endswith("-NOTFOUND")
|
return self.cuda_version and self.with_cuda == "ON" and self.cuda_library and not self.cuda_library.endswith("-NOTFOUND")
|
||||||
@ -259,6 +269,12 @@ class CMakeCache:
|
|||||||
def withJava(self):
|
def withJava(self):
|
||||||
return self.ant_executable and self.java_test_binary_dir
|
return self.ant_executable and self.java_test_binary_dir
|
||||||
|
|
||||||
|
def withPython2(self):
|
||||||
|
return self.python2 == 'ON'
|
||||||
|
|
||||||
|
def withPython3(self):
|
||||||
|
return self.python3 == 'ON'
|
||||||
|
|
||||||
def getGitVersion(self):
|
def getGitVersion(self):
|
||||||
if self.cmake_home_vcver:
|
if self.cmake_home_vcver:
|
||||||
if self.cmake_home_vcver == self.opencv_home_vcver:
|
if self.cmake_home_vcver == self.opencv_home_vcver:
|
||||||
|
Loading…
Reference in New Issue
Block a user