コード例 #1
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)
コード例 #2
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
コード例 #3
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
コード例 #4
0
ファイル: ios_driver.py プロジェクト: rashirungta/FAI-PEP
    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
コード例 #5
0
class IOSPlatformTest(unittest.TestCase):
    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)

    def _list_dir_for_preprocess(self, app_dir):
        self.assertEqual(app_dir, self.tempdir + "/Payload")
        return ["TestDir.app"]

    def _process_run_for_preprocess(self, args):
        app = self.tempdir + "/Payload/TestDir.app"
        self.assertTrue(
            args == ["osascript", "-e", "id of app \"" + app + "\""]
            or args == ["unzip", "-o", "-d", self.tempdir, "test_program.ipa"])
        return ["com.facebook.test"], ""

    def _set_bundle_id_for_preprocess(self, bundle_id):
        self.assertEqual(bundle_id, "com.facebook.test")

    def _idb_run_for_preprocess(self, args):
        app = self.tempdir + "/Payload/TestDir.app"
        self.assertEqual(args, ["--bundle", app, "--uninstall"])

    def test_preprocess(self):
        programs = {"program": "test_program.ipa"}
        with patch("platforms.ios.ios_platform.processRun",
                   side_effect=self._process_run_for_preprocess),\
             patch("os.listdir", side_effect=self._list_dir_for_preprocess),\
             patch("os.path.isdir", return_value=True),\
             patch("platforms.ios.idb.IDB.run",
                   side_effect=self._idb_run_for_preprocess),\
             patch("platforms.ios.idb.IDB.setBundleId",
                   side_effect=self._set_bundle_id_for_preprocess):
            self.platform.preprocess(programs=programs)

    def _push_for_run_benchmark(self, src, tgt):
        sample = open("test_argument_file.json")
        sample_data = json.load(sample)

        test = open(src)
        test_data = json.load(test)

        self.assertEqual(sample_data, test_data)

        sample.close()
        test.close()

    def _idb_run_for_run_benchmark(self, *args, **kwargs):
        expected_cmd = [
            '--bundle', None, '--noninteractive', '--noinstall',
            '--unbuffered', '--args',
            "--input_dims 1,3,224,224 --warmup 1 --input_type "
            "float --iter 50 --run_individual true --init_net "
            "/tmp/init_net.pb --input data --net "
            "/tmp/predict_net.pb"
        ]
        self.assertEqual(args[0], expected_cmd)
        return True

    def test_run_benchmark(self):
        self.platform.util.setBundleId("com.facebook.test")
        cmd = "{program} --net /tmp/predict_net.pb --init_net /tmp/init_net.pb "\
              "--warmup 1 --iter 50 --input \"data\" --input_dims \"1,3,224,224\" "\
              "--input_type float --run_individual true"

        with patch("platforms.ios.idb.IDB.push",
                   side_effect=self._push_for_run_benchmark),\
             patch("platforms.ios.idb.IDB.run",
                   side_effect=self._idb_run_for_run_benchmark):
            res = self.platform.runBenchmark(cmd,
                                             platfor_args={'timeout': 300.0})
            self.assertTrue(res)