Ejemplo n.º 1
0
 def dump(self, exe):
     res = ApkInfo()
     output = self.run(["dump", "xmltree", exe, "AndroidManifest.xml"],
                       silent=True)
     if not output:
         raise Err("Can not dump manifest from %s", exe)
     tags = re.split(r"[ ]+E: ", output)
     # get package name
     manifest_tag = [t for t in tags if t.startswith("manifest ")]
     if not manifest_tag:
         raise Err("Can not read package name from: %s", exe)
     res.pkg_name = re.search(
         r"^[ ]+A: package=\"(?P<pkg>.*?)\" \(Raw: \"(?P=pkg)\"\)\r?$",
         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:
         raise Err("Can not find instrumentation detials in: %s", exe)
     res.pkg_runner = re.search(
         r"^[ ]+A: android:name\(0x[0-9a-f]{8}\)=\"(?P<runner>.*?)\" \(Raw: \"(?P=runner)\"\)\r?$",
         instrumentation_tag[0],
         flags=re.MULTILINE).group("runner")
     res.pkg_target = re.search(
         r"^[ ]+A: android:targetPackage\(0x[0-9a-f]{8}\)=\"(?P<pkg>.*?)\" \(Raw: \"(?P=pkg)\"\)\r?$",
         instrumentation_tag[0],
         flags=re.MULTILINE).group("pkg")
     if not res.pkg_name or not res.pkg_runner or not res.pkg_target:
         raise Err("Can not find instrumentation detials in: %s", exe)
     return res
Ejemplo n.º 2
0
 def detectSerial(self):
     adb_res = self.run(["devices"], silent=True)
     # 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)
     if not connected_devices:
         raise Err("Can not find Android device")
     elif len(connected_devices) != 1:
         raise Err("Too many (%s) devices are connected. Please specify single device using --serial option:\n\n%s", len(connected_devices), adb_res)
     else:
         return connected_devices[0].split("\t")[0]
Ejemplo n.º 3
0
    def runTest(self, path, logfile, workingDir, args=[]):
        args = args[:]
        exe = os.path.abspath(path)

        if exe.endswith(".apk"):
            info = self.aapt.dump(exe)
            if not info:
                raise Err("Can not read info from test package: %s", exe)
            info.forcePackage(self.options.package)
            self.adb.run(["uninstall", info.pkg_name])

            output = self.adb.run(["install", exe], silent=True)
            if not (output and "Success" in output):
                raise Err("Can not install package: %s", exe)

            params = ["-e package %s" % info.pkg_target]
            ret = self.adb.run([
                "shell",
                "am instrument -w %s %s/%s" %
                (" ".join(params), info.pkg_name, info.pkg_runner)
            ])
            return None, ret
        else:
            device_dir = getpass.getuser().replace(
                " ", "") + "_" + self.options.mode + "/"
            if isColorEnabled(args):
                args.append("--gtest_color=yes")
            tempdir = "/data/local/tmp/"
            android_dir = tempdir + device_dir
            exename = os.path.basename(exe)
            android_exe = android_dir + exename
            self.adb.run(["push", exe, android_exe])
            self.adb.run(["shell", "chmod 777 " + android_exe])
            env_pieces = ["export %s=%s" % (a, b) for a, b in self.env.items()]
            pieces = [
                "cd %s" % android_dir,
                "./%s %s" % (exename, " ".join(args))
            ]
            log.warning("Run: %s" % " && ".join(pieces))
            ret = self.adb.run(["shell", " && ".join(env_pieces + pieces)])
            # try get log
            hostlogpath = os.path.join(workingDir, logfile)
            self.adb.run(["pull", android_dir + logfile, hostlogpath])
            # cleanup
            self.adb.run(["shell", "rm " + android_dir + logfile])
            self.adb.run(["shell", "rm " + tempdir + "__opencv_temp.*"],
                         silent=True)
            if os.path.isfile(hostlogpath):
                return hostlogpath, ret
            return None, ret
Ejemplo n.º 4
0
 def listTests(self, short=False, main=False):
     if len(self.tests) == 0:
         raise Err("No tests found")
     for t in self.tests:
         if short:
             t = self.getAlias(t)
         if not main or self.cache.isMainModule(t):
             log.info("%s", t)
Ejemplo n.º 5
0
 def __init__(self, sdk_dir):
     Tool.__init__(self)
     aapt_fn = exe("aapt")
     aapt = None
     for r, ds, fs in os.walk(os.path.join(sdk_dir, 'build-tools')):
         if aapt_fn in fs:
             aapt = os.path.join(r, aapt_fn)
             break
     if not aapt:
         raise Err("Can not find aapt tool: %s", aapt_fn)
     self.cmd = [aapt]
Ejemplo n.º 6
0
    if args.check:
        if not [a for a in test_args if a.startswith("--perf_min_samples=")]:
            test_args.extend(["--perf_min_samples=1"])
        if not [a for a in test_args if a.startswith("--perf_force_samples=")]:
            test_args.extend(["--perf_force_samples=1"])
        if not [a for a in test_args if a.startswith("--perf_verify_sanity")]:
            test_args.extend(["--perf_verify_sanity"])

    ret = 0
    logs = []
    for path in args.build_path:
        try:
            if not os.path.isdir(path):
                raise Err(
                    "Not a directory (should contain CMakeCache.txt ot test executables)"
                )
            cache = CMakeCache(args.configuration)
            fname = os.path.join(path, "CMakeCache.txt")

            if os.path.isfile(fname):
                log.debug("Reading cmake cache file: %s", fname)
                cache.read(path, fname)
            else:
                log.debug("Assuming folder contains tests: %s", path)
                cache.setDummy(path)

            if args.android or cache.getOS() == "android":
                log.debug("Creating Android test runner")
                suite = AndroidTestSuite(args, cache, android_env)
            else:
Ejemplo n.º 7
0
 def getTestList(self, white, black):
     res = [t for t in white or self.tests if self.getAlias(t) not in black]
     if len(res) == 0:
         raise Err("No tests found")
     return set(res)
Ejemplo n.º 8
0
 def getTest(self, name):
     # return stored test name by provided alias
     for t in self.tests:
         if name in self.getAliases(t):
             return t
     raise Err("Can not find test: %s", name)