def testPrefixExists(self, simple__init__, simple_ListFilesWithPrefix): """Tests the PrefixExists function.""" _gcs_api_utils = gcs_api_utils.GcsApiUtils('key/path', 'vts-fuzz') dir_exist = _gcs_api_utils.PrefixExists( 'corpus/ILight/ILight_corpus_seed') simple_ListFilesWithPrefix.assert_called() self.assertEqual(dir_exist, True)
def setUpClass(self): """Creates a remote shell instance, and copies data files. Attributes: _env: dict, a mapping from key to environment path of this test. _gcs_api_utils: a GcsApiUtils object used for uploading logs. _dut: an android device controller object used for getting device info. """ required_params = [ keys.ConfigKeys.IKEY_SERVICE_JSON_PATH, keys.ConfigKeys.IKEY_FUZZING_GCS_BUCKET_NAME, keys.ConfigKeys.IKEY_SYZKALLER_PACKAGES_PATH, keys.ConfigKeys.IKEY_SYZKALLER_TEMPLATE_PATH ] self.getUserParams(required_params) _temp_dir = tempfile.mkdtemp() self._env = dict() self._env['temp_dir'] = _temp_dir self._env['syzkaller_dir'] = os.path.join(_temp_dir, env.syzkaller_dir) self._env['syzkaller_bin_dir'] = os.path.join(_temp_dir, env.syzkaller_bin_dir) self._env['syzkaller_work_dir'] = os.path.join(_temp_dir, env.syzkaller_work_dir) self._env['template_cfg'] = os.path.join(_temp_dir, env.template_cfg) self._gcs_api_utils = gcs_api_utils.GcsApiUtils( self.service_key_json_path, self.fuzzing_gcs_bucket_name) self._dut = self.android_devices[0]
def __init__(self, flatten_source_dir=False, use_destination_date_dir=False, source_dir=None, destination_dir=None, url_prefix=None, gcs_key_path=None): """Initializes the ReportFileUtils object. Args: flatten_source_dir: bool, whether or not flatten the directory structure. use_destination_date_dir: bool, whether or not use date as part of name, source_dir: string, path to the source directory. destination_dir: string, path to the destination directory. url_prefix: string, prefix of the url used to upload the link to dashboard. gcs_key_path: string, path to the GCS key file. """ source_dir = NotNoneStr(source_dir) destination_dir = NotNoneStr(destination_dir) url_prefix = NotNoneStr(url_prefix) self._flatten_source_dir = flatten_source_dir self._use_destination_date_dir = use_destination_date_dir self._source_dir = source_dir self._destination_dir = destination_dir self._url_prefix = url_prefix self._use_gcs = False if gcs_key_path is not None: self._use_gcs = True self._gcs_api_utils = gcs_api_utils.GcsApiUtils( gcs_key_path, destination_dir) self._gcs_available = self._gcs_api_utils.Enabled
def testPrepareDownloadDestination(self, simple__init__, simple_os_path_exists): """Tests the PrepareDownloadDestination function.""" _gcs_api_utils = gcs_api_utils.GcsApiUtils('key/path', 'vts-fuzz') local_dest_folder = _gcs_api_utils.PrepareDownloadDestination( 'corpus/ILight/ILight_corpus_seed', 'tmp/tmp4772') self.assertEqual(local_dest_folder, 'tmp/tmp4772/ILight_corpus_seed')
def testDownloadDir(self, simple__init__, simple_PrepareDownloadDestination, simple_ListFilesWithPrefix, simple_PrefixExists, simple_DownloadFile): """Tests the DownloadDir function""" _gcs_api_utils = gcs_api_utils.GcsApiUtils('key/path', 'vts-fuzz') _gcs_api_utils.DownloadDir('valid_source_dir', 'local_destination/dest') num_DownloadFile_called = simple_DownloadFile.call_count self.assertEqual(num_DownloadFile_called, 4) local_dest_folder = simple_PrepareDownloadDestination.return_value
def __init__(self, user_params, dut): """Initializes the gcs util provider. Args: user_params: A dictionary from parameter name (String) to parameter value. dut: The Android device we are testing against. """ self.ParseParameters( toggle_param_name=self._TOGGLE_PARAM, required_param_names=self._REQUIRED_PARAMS, optional_param_names=self._OPTIONAL_PARAMS, user_params=user_params) if self.enabled: self._key_path = self.service_key_json_path self._bucket_name = self.fuzzing_gcs_bucket_name self._gcs_api_utils = gcs_api_utils.GcsApiUtils( self._key_path, self._bucket_name) self.enabled = self._gcs_api_utils.Enabled branch = dut.build_alias.split('.')[0] model = dut.product_type self._gcs_path = os.path.join('corpus', branch, model) self._device_serial = dut.serial
def testCountFiles(self, simple__init__, simple_ListFilesWithPrefix): """Tests the CountFiles function.""" _gcs_api_utils = gcs_api_utils.GcsApiUtils('key/path', 'vts-fuzz') length = _gcs_api_utils.CountFiles('corpus/ILight/ILight_corpus_seed') simple_ListFilesWithPrefix.assert_called() self.assertEqual(length, 4)
def testCredentialsError(self, mock_default): """Tests authentication failure in __init__.""" _gcs_api_utils = gcs_api_utils.GcsApiUtils('key/path', 'vts-fuzz') self.assertFalse(_gcs_api_utils.Enabled) mock_default.assert_called()
def testUploadDir(self, simple__init__, simple_ListFilesWithPrefix, simple_os_path_exists, simple_UploadFile): _gcs_api_utils = gcs_api_utils.GcsApiUtils('key/path', 'vts-fuzz') _gcs_api_utils.UploadDir('valid_source_dir', 'GCS_destination/dest') num_UploadFile_called = simple_UploadFile.call_count self.assertEqual(num_UploadFile_called, 4)