Path: blob/master/platforms/android/build-tests/test_ant_build.py
16337 views
#!/usr/bin/env python12import unittest3import os, sys, subprocess, argparse, shutil, re4from os.path import abspath56class TestAntBuild(unittest.TestCase):7pass89def __init__(self, target, workdir, lib_dir, sample_dir, *args, **kwargs):10unittest.TestCase.__init__(self, *args, **kwargs)11self.target = target12self.workdir = workdir13self.src_lib_dir = lib_dir14self.src_sample_dir = sample_dir15self.lib_dir = os.path.join(self.workdir, "opencv")16self.sample_dir = os.path.join(self.workdir, "project")1718def shortDescription(self):19return "TARGET: %r, SAMPLE: %s" % (self.target, os.path.basename(self.src_sample_dir))2021def setUp(self):22if os.path.exists(self.workdir):23shutil.rmtree(self.workdir)24os.mkdir(self.workdir)25shutil.copytree(self.src_lib_dir, self.lib_dir)26shutil.copytree(self.src_sample_dir, self.sample_dir)27os.remove(os.path.join(self.sample_dir, "project.properties"))2829def tearDown(self):30if os.path.exists(self.workdir):31shutil.rmtree(self.workdir)3233def runTest(self):34cmd = [os.path.join(os.environ["ANDROID_SDK"], "tools", "android"), "update", "project", "-p", self.lib_dir, "-t", self.target[0]]35retcode = subprocess.call(cmd)36self.assertEqual(retcode, 0, "android update opencv project failed")3738cmd = ["ant", "-f", os.path.join(self.lib_dir, "build.xml"), "debug"]39retcode = subprocess.call(cmd)40self.assertEqual(retcode, 0, "opencv ant build failed")4142cmd = [os.path.join(os.environ["ANDROID_SDK"], "tools", "android"), "update", "project", "-p", self.sample_dir, "-t", self.target[1], "-l", os.path.relpath(self.lib_dir, self.sample_dir)]43retcode = subprocess.call(cmd)44self.assertEqual(retcode, 0, "android update sample project failed")4546cmd = ["ant", "-f", os.path.join(self.sample_dir, "build.xml"), "debug"]47retcode = subprocess.call(cmd)48self.assertEqual(retcode, 0, "sample ant build failed")4950def suite(workdir, opencv_lib_path, opencv_samples_path):51suite = unittest.TestSuite()52for target in [("android-21", "android-14"), ("android-21", "android-17")]:53for item in os.listdir(opencv_samples_path):54item = os.path.join(opencv_samples_path, item)55if (os.path.exists(os.path.join(item, "AndroidManifest.xml"))):56suite.addTest(TestAntBuild(target, workdir, opencv_lib_path, item))57return suite5859if __name__ == '__main__':60parser = argparse.ArgumentParser(description='Test OpenCV for Android SDK with ant')61parser.add_argument('--sdk_path', help="Path to Android SDK to use for build")62parser.add_argument("--workdir", default="testspace", help="Working directory (and output)")63parser.add_argument("opencv_lib_path", help="Path to folder with SDK java library (usually <SDK>/sdk/java/)")64parser.add_argument("opencv_samples_path", help="Path to folder with SDK samples (usually <SDK>/samples/)")6566args = parser.parse_args()6768if args.sdk_path is not None:69os.environ["ANDROID_SDK"] = os.path.abspath(args.sdk_path)7071print("Using SDK: %s" % os.environ["ANDROID_SDK"])7273s = suite(abspath(args.workdir), abspath(args.opencv_lib_path), abspath(args.opencv_samples_path))74res = unittest.TextTestRunner(verbosity=3).run(s)75if not res.wasSuccessful():76sys.exit(res)777879