Exemplo n.º 1
0
    def getIOSPlatforms(self, tempdir):
        platforms = []
        if self.args.device:
            device_str = self.args.device
            assert device_str[0] == '{', "device must be a json string"
            device = json.loads(device_str)
            idb = IDB(device["hash"], tempdir)
            platform = IOSPlatform(tempdir, idb, self.args)
            platform.setPlatform(device["kind"])
            platforms.append(platform)
            return platforms

        if self.devices is None:
            self.devices = self.getDevices()
        if self.args.excluded_devices:
            excluded_devices = \
                set(self.args.excluded_devices.strip().split(','))
            self.devices = self.devices.difference(excluded_devices)

        if self.args.devices:
            supported_devices = set(self.args.devices.strip().split(','))
            if supported_devices.issubset(self.devices):
                self.devices = supported_devices

        for device in self.devices:
            model = self.devices[device]
            idb = IDB(device, tempdir)
            platform = IOSPlatform(tempdir, idb, self.args)
            platform.setPlatform(model)
            platforms.append(platform)

        return platforms
Exemplo n.º 2
0
 def test_run(self):
     idb = IDB()
     with patch(
             "platforms.platform_util_base.PlatformUtilBase.run",
             side_effect=self._util_base_run,
     ):
         idb.run()
Exemplo n.º 3
0
 def test_reboot(self):
     idb = IDB(device="TEST_DEVICE")
     with patch(
             "platforms.platform_util_base.PlatformUtilBase.run",
             side_effect=self._ios_run_for_reboot,
     ):
         push_res = idb.reboot()
         self.assertTrue(push_res)
Exemplo n.º 4
0
    def test_push(self):
        src = os.path.abspath(
            os.path.join(
                BENCHMARK_DIR, os.pardir,
                "specifications/models/caffe2/squeezenet/squeezenet.json"))
        tgt = "TEST_TGT"
        idb = IDB()

        with patch("platforms.ios.idb.IDB.run",
                   side_effect=self._ios_run_for_push):
            push_res = idb.push(src, tgt)
            self.assertEqual(push_res, ("--upload", src, "--to", tgt))
Exemplo n.º 5
0
def reboot():
    parse()
    device = getArgs().device
    platform = getArgs().platform
    if platform.startswith("ios"):
        util = IDB(device)
    elif platform.startswith("android"):
        util = ADB(device)
    else:
        assert False, "Platform {} not recognized".format(platform)
    util.reboot()
    print("Reboot Success")
Exemplo n.º 6
0
def reboot(**kwargs):
    raw_args = kwargs.get("raw_args", None)
    args, _ = parser.parse_known_args(raw_args)
    device = args.device
    platform = args.platform
    if platform.startswith("ios"):
        util = IDB(device)
    elif platform.startswith("android"):
        util = ADB(device, args.android_dir)
    else:
        raise AssertionError("Platform {} not recognized".format(platform))
    util.reboot()
    print("Reboot Success")
Exemplo n.º 7
0
 def getDevices(self):
     idb = IDB()
     rows = idb.run("--detect")
     if len(rows) == 0:
         return {}
     rows.pop(0)
     pattern = re.compile(".* Found ([\d|a-f]+) \((\w+), .+\) a\.k\.a\. .*")
     devices = {}
     for row in rows:
         match = pattern.match(row)
         if match:
             hash = match.group(1)
             model = match.group(2)
             devices[hash] = model
     return devices
Exemplo n.º 8
0
    def getIOSPlatforms(self, tempdir, usb_controller):
        platforms = []
        if self.args.device:
            device_str = self.args.device
            assert device_str[0] == "{", "device must be a json string"
            device = json.loads(device_str)
            hash = device["hash"]
            idb = IDB(hash, tempdir)
            platform_meta = {
                "os_version": self.devices[hash]["os_version"],
                "model": self.devices[hash]["model"],
                "abi": self.devices[hash]["abi"],
            }
            platform = IOSPlatform(
                tempdir, idb, self.args, platform_meta, usb_controller
            )
            platform.setPlatform(self.devices[hash]["model"])
            platforms.append(platform)
            return platforms

        if self.args.excluded_devices:
            self.devices = {
                d: self.devices[d]
                for d in self.devices
                if d not in self.args.excluded_devices
            }

        if self.args.devices:
            self.devices = {
                d: self.devices[d] for d in self.devices if d in self.args.devices
            }

        for device in self.devices:
            idb = IDB(device, tempdir)
            platform_meta = {
                "os_version": self.devices[device]["os_version"],
                "model": self.devices[device]["model"],
                "abi": self.devices[device]["abi"],
            }
            platform = IOSPlatform(tempdir, idb, self.args, platform_meta)
            platform.setPlatform(self.devices[device]["model"])
            platforms.append(platform)

        return platforms
Exemplo n.º 9
0
 def getDevices(self, silent=True, retry=1):
     idb = IDB()
     rows = idb.run(["--detect", "--timeout", "1"], silent=silent, retry=1)
     if len(rows) == 0:
         return {}
     rows.pop(0)
     pattern = re.compile(
         r".* Found ([\d|a-f|\-|A-F]+) \((\w+), .+, .+, (.+), (.+), .+\) a\.k\.a\. .*"
     )
     devices = {}
     for row in rows:
         match = pattern.match(row)
         if match:
             hash = match.group(1)
             model = match.group(2)
             abi = match.group(3)
             os_version = match.group(4)
             devices[hash] = {"model": model, "abi": abi, "os_version": os_version}
     return devices
Exemplo n.º 10
0
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        device = {"12345678-9012345678AB901C": "A012BC"}
        idb = IDB(device, self.tempdir)
        with patch("platforms.ios.ios_platform.IOSPlatform.setPlatformHash"),\
             patch("platforms.ios.ios_platform.getArgs",
                   return_value=argparse.Namespace(ios_dir=self.tempdir)),\
             patch("platforms.platform_base.getArgs",
                   return_value=argparse.Namespace(hash_platform_mapping=None)):

            self.platform = IOSPlatform(self.tempdir, idb)
Exemplo n.º 11
0
    def getIOSPlatforms(self, tempdir):
        platforms = []
        if self.args.device:
            device_str = self.args.device
            assert device_str[0] == '{', "device must be a json string"
            device = json.loads(device_str)
            hash = device["hash"]
            idb = IDB(hash, tempdir)
            platform_meta = {
                "os_version": self.devices[hash]["os_version"],
                "model": self.devices[hash]["model"],
                "abi": self.devices[hash]["abi"]
            }
            platform = IOSPlatform(tempdir, idb, self.args, platform_meta)
            platform.setPlatform(self.devices[hash]["model"])
            platforms.append(platform)
            return platforms

        if self.args.excluded_devices:
            excluded_devices = \
                set(self.args.excluded_devices.strip().split(','))
            self.devices = self.devices.difference(excluded_devices)

        if self.args.devices:
            supported_devices = set(self.args.devices.strip().split(','))
            if supported_devices.issubset(self.devices):
                self.devices = supported_devices

        for device in self.devices:
            idb = IDB(device, tempdir)
            platform_meta = {
                "os_version": self.devices[device]["os_version"],
                "model": self.devices[device]["model"],
                "abi": self.devices[device]["abi"]
            }
            platform = IOSPlatform(tempdir, idb, self.args, platform_meta)
            platform.setPlatform(self.devices[device]["model"])
            platforms.append(platform)

        return platforms
Exemplo n.º 12
0
 def test_set_bundle_id(self):
     idb = IDB()
     idb.setBundleId("TEST")
     self.assertEqual(idb.bundle_id, "TEST")