Example #1
0
    def testInuseToDestSeed(self):
        """Tests the InuseToDest function of a CorpusManager object."""
        _corpus_manager = corpus_manager.CorpusManager({}, dut)
        _corpus_manager.enabled = True
        _corpus_manager._gcs_api_utils = mock.MagicMock()

        _corpus_manager.InuseToDest(
            'ILight',
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_inuse/corpus_number_1',
            'corpus_seed')
        _corpus_manager._gcs_api_utils.MoveFile.assert_called_with(
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_inuse/corpus_number_1',
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_seed/corpus_number_1',
            True)

        _corpus_manager.InuseToDest(
            'ILight',
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_inuse/corpus_number_1',
            'corpus_complete')
        _corpus_manager._gcs_api_utils.MoveFile.assert_called_with(
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_inuse/corpus_number_1',
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_complete/corpus_number_1',
            True)

        _corpus_manager.InuseToDest(
            'ILight',
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_inuse/corpus_number_1',
            'corpus_crash')
        _corpus_manager._gcs_api_utils.MoveFile.assert_called_with(
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_inuse/corpus_number_1',
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_crash/corpus_number_1',
            True)
Example #2
0
    def testInitializationEnabled(self):
        """Tests the enabled initilization of a CorpusManager object.

        If we initially begin with enabled=True, it will automatically
        attempt to connect GCS API.
        """
        _corpus_manager = corpus_manager.CorpusManager({}, dut)
        _corpus_manager.enabled = True
        self.assertEqual(_corpus_manager.enabled, True)
        self.assertEqual(_corpus_manager._gcs_path, 'corpus/Pie/Pixel3_XL')
        self.assertEqual(_corpus_manager._device_serial, 'HT1178BBZWQ')
Example #3
0
    def testFetchCorpusSeedEmpty_STAGE_3_LOCKED(self):
        """Tests the FetchCorpusSeed function of a CorpusManager object.

        This is tested with an empty seed directory for stage 3 algorithm.
        """
        corpus_manager.SCHEDULING_ALGORITHM = 3
        _corpus_manager = corpus_manager.CorpusManager({}, dut)
        _corpus_manager.enabled = True
        _corpus_manager._gcs_api_utils = mock.MagicMock()
        _corpus_manager._gcs_api_utils.PrefixExists_return_value = True
        _corpus_manager._gcs_api_utils.ListFilesWithPrefix.return_value = []
        res = _corpus_manager.FetchCorpusSeed('ILight', '/tmp/tmpDir1')
        self.assertEquals(res, 'locked')
Example #4
0
    def testFetchCorpusSeedEmpty_STAGE_1(self):
        """Tests the FetchCorpusSeed function of a CorpusManager object.

        This is tested with an empty seed directory for stage 1 algorithm.
        """
        corpus_manager.SCHEDULING_ALGORITHM = 1
        _corpus_manager = corpus_manager.CorpusManager({}, dut)
        _corpus_manager.enabled = True
        _corpus_manager._gcs_api_utils = mock.MagicMock()
        _corpus_manager._FetchCorpusSeedFromPriority = mock.MagicMock()
        _corpus_manager.FetchCorpusSeed('ILight', '/tmp/tmpDir1')
        _corpus_manager._FetchCorpusSeedFromPriority.assert_called_with(
            'ILight', '/tmp/tmpDir1', 'corpus_seed')
Example #5
0
 def test_MoveCorpusDirectory(self):
     """Tests the _MoveCorpusDirectory function of a CorpusManager object."""
     _corpus_manager = corpus_manager.CorpusManager({}, dut)
     _corpus_manager.enabled = True
     _corpus_manager._gcs_api_utils = mock.MagicMock()
     _corpus_manager._gcs_api_utils.ListFilesWithPrefix.return_value = [
         'dir/file1', 'dir/file2', 'dir/file3', 'dir/file4', 'dir/file5'
     ]
     _corpus_manager._MoveCorpusDirectory('ILight', '/tmp/tmpDir1',
                                          'corpus_seed', 'corpus_complete')
     _corpus_manager._gcs_api_utils.ListFilesWithPrefix.assert_called_with(
         'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_seed', strict=True)
     self.assertEquals(_corpus_manager._gcs_api_utils.MoveFile.call_count,
                       5)
Example #6
0
 def testUploadCorpusOutDir(self):
     """Tests the UploadCorpusOutDir function of a CorpusManager object."""
     corpus_manager.MEASURE_CORPUS = False
     _corpus_manager = corpus_manager.CorpusManager({}, dut)
     _corpus_manager.enabled = True
     _corpus_manager._gcs_api_utils = mock.MagicMock()
     _corpus_manager._gcs_api_utils.UploadDir.return_value = True
     _corpus_manager._ClassifyPriority = mock.MagicMock()
     _corpus_manager.UploadCorpusOutDir('ILight', '/tmp/tmpDir1')
     _corpus_manager._gcs_api_utils.UploadDir.assert_called_with(
         '/tmp/tmpDir1/ILight_corpus_out',
         'corpus/Pie/Pixel3_XL/ILight/incoming/tmpDir1')
     _corpus_manager._ClassifyPriority.assert_called_with(
         'ILight', '/tmp/tmpDir1')
Example #7
0
 def test_GetDirPaths(self):
     """Tests the _GetDirPaths function of a CorpusManager object."""
     _corpus_manager = corpus_manager.CorpusManager({}, dut)
     self.assertEqual(_corpus_manager._GetDirPaths('corpus_seed', 'ILight'),
                      'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_seed')
     self.assertEqual(
         _corpus_manager._GetDirPaths('incoming_parent', 'ILight',
                                      '/tmp/tmpDir1'),
         'corpus/Pie/Pixel3_XL/ILight/incoming/tmpDir1')
     self.assertEqual(
         _corpus_manager._GetDirPaths('incoming_child', 'ILight',
                                      '/tmp/tmpDir1'),
         'corpus/Pie/Pixel3_XL/ILight/incoming/tmpDir1/ILight_corpus_out')
     self.assertEqual(_corpus_manager._GetDirPaths('corpus_seed', 'ILight'),
                      'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_seed')
Example #8
0
 def test_ClassifyPriority1(self):
     """Tests the _ClassifyPriority1 function of a CorpusManager object."""
     corpus_manager.SCHEDULING_ALGORITHM = 1
     _corpus_manager = corpus_manager.CorpusManager({}, dut)
     _corpus_manager.enabled = True
     _corpus_manager._gcs_api_utils = mock.MagicMock()
     _corpus_manager._gcs_api_utils.ListFilesWithPrefix.return_value = [
         'dir/file1', 'dir/file2', 'dir/file3', 'dir/file4', 'dir/file5'
     ]
     _corpus_manager._CorpusIsDuplicate = mock.MagicMock()
     _corpus_manager._CorpusIsDuplicate.return_value = False
     _corpus_manager._ClassifyPriority1('ILight', '/tmp/tmpDir1')
     _corpus_manager._gcs_api_utils.ListFilesWithPrefix.assert_called_with(
         'corpus/Pie/Pixel3_XL/ILight/incoming/tmpDir1/ILight_corpus_out')
     self.assertEquals(_corpus_manager._gcs_api_utils.MoveFile.call_count,
                       5)
Example #9
0
 def test_ClassifyPriority3(self):
     """Tests the _ClassifyPriority3 function of a CorpusManager object."""
     corpus_manager.SCHEDULING_ALGORITHM = 3
     corpus_manager.REPEAT_TIMES = 5
     corpus_manager.os.path.exists = mock.MagicMock()
     corpus_manager.os.path.exists.return_value = True
     _corpus_manager = corpus_manager.CorpusManager({}, dut)
     _corpus_manager.enabled = True
     _corpus_manager._gcs_api_utils = mock.MagicMock()
     _corpus_manager._gcs_api_utils.ListFilesWithPrefix.return_value = [
         'dir/file1', 'dir/file2', 'dir/file3', 'dir/file4', 'dir/file5'
     ]
     _corpus_manager._gcs_api_utils.PrefixExists.return_value = True
     _corpus_manager._MoveCorpusDirectory = mock.MagicMock()
     _corpus_manager._ClassifyPriority3('ILight', '/tmp/tmpDir1')
     self.assertEquals(_corpus_manager._MoveCorpusDirectory.call_count, 2)
     _corpus_manager._MoveCorpusDirectory.assert_called_with(
         'ILight', '/tmp/tmpDir1', 'incoming_child', 'corpus_complete')
    def setUpClass(self):
        """Creates a remote shell instance, and copies data files."""
        required_params = [
            keys.ConfigKeys.IKEY_DATA_FILE_PATH,
            keys.ConfigKeys.IKEY_HAL_HIDL_PACKAGE_NAME,
        ]
        self.getUserParams(required_params)
        logging.info('%s: %s', keys.ConfigKeys.IKEY_DATA_FILE_PATH,
                     self.data_file_path)
        logging.info('%s: %s', keys.ConfigKeys.IKEY_HAL_HIDL_PACKAGE_NAME,
                     self.hal_hidl_package_name)

        self._dut = self.android_devices[0]
        self._dut.adb.shell('mkdir %s -p' % config.FUZZER_TEST_DIR)
        self._vts_spec_parser = vts_spec_utils.VtsSpecParser(
            self.data_file_path)
        self._temp_dir = tempfile.mkdtemp()
        self._corpus_manager = corpus_manager.CorpusManager(
            self.user_params, self._dut)
Example #11
0
 def test_GetFilePaths(self):
     """Tests the _GetFilePaths function of a CorpusManager object."""
     _corpus_manager = corpus_manager.CorpusManager({}, dut)
     self.assertEqual(
         _corpus_manager._GetFilePaths('corpus_seed', 'ILight',
                                       'some_dir/corpus_number_1'),
         'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_seed/corpus_number_1')
     self.assertEqual(
         _corpus_manager._GetFilePaths('corpus_inuse', 'ILight',
                                       'some_dir/corpus_number_1'),
         'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_inuse/corpus_number_1')
     self.assertEqual(
         _corpus_manager._GetFilePaths('corpus_complete', 'ILight',
                                       'somedir/corpus_number_1'),
         'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_complete/corpus_number_1'
     )
     self.assertEqual(
         _corpus_manager._GetFilePaths('corpus_crash', 'ILight',
                                       'somedir/corpus_number_1'),
         'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_crash/corpus_number_1')
Example #12
0
    def testFetchCorpusSeedValid_STAGE_2(self):
        """Tests the FetchCorpusSeed function of a CorpusManager object.

        This is tested with a valid seed directory for stage 2 algorithm.
        """
        corpus_manager.SCHEDULING_ALGORITHM = 2
        _corpus_manager = corpus_manager.CorpusManager({}, dut)
        _corpus_manager.enabled = True
        _corpus_manager._gcs_api_utils = mock.MagicMock()
        _corpus_manager._gcs_api_utils.ListFilesWithPrefix.return_value = [
            'dir/file1', 'dir/file2', 'dir/file3', 'dir/file4', 'dir/file5'
        ]
        _corpus_manager._gcs_api_utils.MoveFile.return_value = True
        _corpus_manager.FetchCorpusSeed('ILight', '/tmp/tmpDir1')
        _corpus_manager._gcs_api_utils.ListFilesWithPrefix.assert_called_with(
            'corpus/Pie/Pixel3_XL/ILight/ILight_corpus_seed_high')
        _corpus_manager._gcs_api_utils.MoveFile.assert_called()
        _corpus_manager._gcs_api_utils.PrepareDownloadDestination.assert_called(
        )
        _corpus_manager._gcs_api_utils.DownloadFile.assert_called()
Example #13
0
 def testInitializationDisabled(self):
     """Tests the disabled initilization of a CorpusManager object."""
     _corpus_manager = corpus_manager.CorpusManager({}, dut)
     self.assertEqual(_corpus_manager.enabled, False)