Example #1
0
  def setUp(self):
    test_helpers.patch(self, [
        'libs.access.get_access',
        'clusterfuzz._internal.base.external_users.allowed_jobs_for_user',
        'libs.helpers.get_user_email',
        'clusterfuzz._internal.google_cloud_utils.storage.read_data',
        'clusterfuzz._internal.google_cloud_utils.storage.exists'
    ])

    self.mock.read_data.return_value = ''
    self.mock.exists.return_value = False
    data_types.Job(
        name='libfuzzer_asan_lib',
        environment_string=('PROJECT_NAME = lib\n'
                            'CORPUS_PRUNE = True')).put()
    data_types.Job(
        name='afl_asan_lib', environment_string=('PROJECT_NAME = lib\n')).put()
    data_types.Job(
        name='libfuzzer_msan_lib',
        environment_string='PROJECT_NAME = lib').put()
    data_types.Job(
        name='afl_asan_lib2',
        environment_string=('PROJECT_NAME = lib2\n')).put()

    data_types.Job(
        name='libfuzzer_asan_lib2',
        environment_string=('PROJECT_NAME = lib2\n'
                            'CORPUS_PRUNE = True')).put()
    data_types.Job(
        name='libfuzzer_ubsan_lib2',
        environment_string='PROJECT_NAME = lib2').put()

    data_types.FuzzTarget(engine='afl', binary='fuzzer', project='lib2').put()
    data_types.FuzzTargetJob(
        fuzz_target_name='afl_lib2_fuzzer',
        job='afl_asan_lib2',
        last_run=datetime.datetime.utcnow()).put()
    data_types.FuzzTarget(
        engine='libFuzzer', binary='fuzzer', project='lib2').put()
    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_lib2_fuzzer',
        job='libfuzzer_asan_lib2',
        last_run=datetime.datetime.utcnow()).put()
    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_lib2_fuzzer',
        job='libfuzzer_ubsan_lib2',
        last_run=datetime.datetime.utcnow()).put()

    self.maxDiff = None  # pylint: disable=invalid-name
    def test_select_targets_with_tagged_cross_pollination(self):
        """Test that selecting targets with a given tag returns the right target."""
        data_types.CorpusTag(
            tag='test_tag',
            fully_qualified_fuzz_target_name='libFuzzer_test_fuzzer').put()

        data_types.CorpusTag(tag='test_tag',
                             fully_qualified_fuzz_target_name=
                             'libFuzzer_cross_pollination_test_fuzzer').put()

        similar_target = data_types.FuzzTarget(
            engine='libFuzzer',
            binary='cross_pollination_test_fuzzer',
            project='test-project')
        similar_target.put()

        similar_job = data_types.FuzzTargetJob(
            fuzz_target_name='libFuzzer_cross_pollination_test_fuzzer',
            engine='libFuzzer',
            job='libfuzzer_asan_job')
        similar_job.put()

        selected = corpus_pruning_task._select_targets_and_jobs_for_pollination(
            'libFuzzer', 'libFuzzer_test_fuzzer', 'tagged', 'test_tag')

        self.assertEqual([(similar_target, similar_job)], selected)
  def test_record_fuzz_target_existing(self):
    """Test that record_fuzz_target works when updating an existing entity."""
    data_types.FuzzTarget(
        binary='child', engine='libFuzzer', project='test-project').put()
    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_child',
        job='job',
        engine='libFuzzer',
        last_run=datetime.datetime(2017, 12, 31, 0, 0)).put()

    data_handler.record_fuzz_target('libFuzzer', 'child', 'job')
    fuzz_target = ndb.Key(data_types.FuzzTarget, 'libFuzzer_child').get()
    self.assertDictEqual({
        'binary': 'child',
        'engine': 'libFuzzer',
        'project': 'test-project',
    }, fuzz_target.to_dict())

    job_mapping = ndb.Key(data_types.FuzzTargetJob, 'libFuzzer_child/job').get()
    self.assertDictEqual({
        'fuzz_target_name': 'libFuzzer_child',
        'job': 'job',
        'engine': 'libFuzzer',
        'last_run': datetime.datetime(2018, 1, 1, 0, 0),
        'weight': 1.0,
    }, job_mapping.to_dict())

    self.assertEqual('libFuzzer_child', fuzz_target.fully_qualified_name())
    self.assertEqual('child', fuzz_target.project_qualified_name())
    def setUp(self):
        test_helpers.patch_environ(self)
        flaskapp = flask.Flask('testflask')
        flaskapp.add_url_rule(
            '/schedule-ml-train-tasks',
            view_func=ml_train.Handler.as_view('/schedule-ml-train-tasks'))
        self.app = webtest.TestApp(flaskapp)

        test_helpers.patch(self, [
            'clusterfuzz._internal.base.tasks.add_task',
            'handlers.base_handler.Handler.is_cron',
            'clusterfuzz._internal.metrics.logs.log_error'
        ])

        # Create fake jobs.
        data_types.Job(
            name='libfuzzer_asan',
            environment_string='ML_MODELS_TO_USE = rnn_generator').put()
        data_types.Job(name='libfuzzer_msan', environment_string='').put()
        data_types.Job(name='afl_asan', environment_string='').put()

        data_types.Job(
            name='libfuzzer_asan_invalid',
            environment_string='ML_MODELS_TO_USE = invalid_model\n').put()

        # Create fake fuzzers.
        data_types.Fuzzer(name='afl', jobs=['afl_asan']).put()

        # Create fake child fuzzers.
        data_types.FuzzTarget(engine='libFuzzer',
                              binary='fake_fuzzer',
                              project='test-project').put()
        data_types.FuzzTargetJob(fuzz_target_name='libFuzzer_fake_fuzzer',
                                 job='libfuzzer_asan').put()
        data_types.FuzzTarget(engine='afl',
                              binary='fake_fuzzer',
                              project='test-project').put()
        data_types.FuzzTargetJob(fuzz_target_name='afl_fake_fuzzer',
                                 job='afl_asan').put()
Example #5
0
    def setUp(self):
        test_helpers.patch_environ(self)

        data_types.FuzzTarget(
            engine='engine',
            project='proj',
            binary='child_0',
        ).put()
        data_types.FuzzTargetJob(
            fuzz_target_name='engine_proj_child_0',
            engine='engine',
            job='some_job_engine',
            weight=1.5,
        ).put()

        data_types.FuzzTarget(
            engine='engine',
            project='proj',
            binary='child_1',
        ).put()
        data_types.FuzzTargetJob(
            fuzz_target_name='engine_proj_child_1',
            engine='engine',
            job='some_job_engine',
            weight=0.75,
        ).put()

        data_types.FuzzTarget(
            engine='different_fuzzer',
            binary='child_2',
            project='test-project',
        ).put()
        data_types.FuzzTargetJob(
            fuzz_target_name='different_fuzzer_child_2',
            engine='different_fuzzer',
            job='some_job_different_fuzzer',
            weight=3.0,
        ).put()
Example #6
0
    def setUp(self):
        """Set up."""
        super().setUp()
        environment.set_value('JOB_NAME', 'libfuzzer_asan_job')

        patcher = mock.patch(
            'clusterfuzz._internal.bot.fuzzers.libFuzzer.fuzzer.LibFuzzer.fuzzer_directory',
            new_callable=mock.PropertyMock)

        mock_fuzzer_directory = patcher.start()
        self.addCleanup(patcher.stop)

        mock_fuzzer_directory.return_value = os.path.join(
            environment.get_value('ROOT_DIR'), 'src', 'clusterfuzz',
            '_internal', 'bot', 'fuzzers', 'libFuzzer')

        job = data_types.Job(
            name='libfuzzer_asan_job',
            environment_string=(
                'RELEASE_BUILD_BUCKET_PATH = '
                'gs://clusterfuzz-test-data/test_libfuzzer_builds/'
                'test-libfuzzer-build-([0-9]+).zip\n'
                'REVISION_VARS_URL = https://commondatastorage.googleapis.com/'
                'clusterfuzz-test-data/test_libfuzzer_builds/'
                'test-libfuzzer-build-%s.srcmap.json\n'))
        job.put()

        data_types.FuzzTarget(engine='libFuzzer',
                              binary='test_fuzzer',
                              project='test-project').put()
        data_types.FuzzTargetJob(fuzz_target_name='libFuzzer_test_fuzzer',
                                 engine='libFuzzer',
                                 job='libfuzzer_asan_job').put()

        environment.set_value('USE_MINIJAIL', True)
        data_types.Fuzzer(revision=1,
                          file_size='builtin',
                          source='builtin',
                          name='libFuzzer',
                          max_testcases=4,
                          builtin=True).put()
        self.temp_dir = tempfile.mkdtemp(
            dir=environment.get_value('FUZZ_INPUTS'))
Example #7
0
    def setUp(self):
        helpers.patch_environ(self)

        # Fake permissions.
        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='fuzzer',
            entity_kind=data_types.PermissionEntityKind.FUZZER,
            auto_cc=data_types.AutoCCType.ALL).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='fuzz',
            entity_kind=data_types.PermissionEntityKind.FUZZER,
            is_prefix=True,
            auto_cc=data_types.AutoCCType.SECURITY).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='parent_',
            entity_kind=data_types.PermissionEntityKind.FUZZER,
            is_prefix=True,
            auto_cc=data_types.AutoCCType.NONE).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='parent',
            entity_kind=data_types.PermissionEntityKind.FUZZER,
            auto_cc=data_types.AutoCCType.NONE).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='parent_cg',
            entity_kind=data_types.PermissionEntityKind.FUZZER,
            is_prefix=True,
            auto_cc=data_types.AutoCCType.NONE).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='parens',
            entity_kind=data_types.PermissionEntityKind.FUZZER,
            is_prefix=True,
            auto_cc=data_types.AutoCCType.NONE).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='parent',
            entity_kind=data_types.PermissionEntityKind.FUZZER,
            is_prefix=True,
            auto_cc=data_types.AutoCCType.ALL).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='job',
            entity_kind=data_types.PermissionEntityKind.JOB,
            is_prefix=False,
            auto_cc=data_types.AutoCCType.ALL).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='job',
            entity_kind=data_types.PermissionEntityKind.JOB,
            is_prefix=True,
            auto_cc=data_types.AutoCCType.ALL).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='job2',
            entity_kind=data_types.PermissionEntityKind.JOB,
            is_prefix=False,
            auto_cc=data_types.AutoCCType.ALL).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='job',
            entity_kind=data_types.PermissionEntityKind.JOB,
            is_prefix=False,
            auto_cc=data_types.AutoCCType.NONE).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='job2',
            entity_kind=data_types.PermissionEntityKind.JOB,
            is_prefix=False,
            auto_cc=data_types.AutoCCType.NONE).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='job',
            entity_kind=data_types.PermissionEntityKind.JOB,
            is_prefix=False,
            auto_cc=data_types.AutoCCType.NONE).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name='job3',
            entity_kind=data_types.PermissionEntityKind.JOB,
            is_prefix=False,
            auto_cc=data_types.AutoCCType.NONE).put()

        data_types.ExternalUserPermission(
            email='*****@*****.**',
            entity_name=None,
            entity_kind=data_types.PermissionEntityKind.UPLOADER,
            is_prefix=False,
            auto_cc=data_types.AutoCCType.NONE).put()

        # Fake fuzzers.
        data_types.Fuzzer(name='fuzzer').put()
        data_types.Fuzzer(name='parent', jobs=['job', 'job2', 'job3']).put()

        data_types.Job(name='job').put()
        data_types.Job(name='job2').put()
        data_types.Job(name='job3').put()

        data_types.FuzzTarget(engine='parent',
                              binary='child',
                              project='test-project').put()
        data_types.FuzzTargetJob(fuzz_target_name='parent_child',
                                 job='job',
                                 last_run=datetime.datetime.utcnow()).put()

        data_types.FuzzTarget(engine='parent',
                              binary='child2',
                              project='test-project').put()
        data_types.FuzzTargetJob(fuzz_target_name='parent_child2',
                                 job='job',
                                 last_run=datetime.datetime.utcnow()).put()

        data_types.FuzzTarget(engine='parent',
                              binary='child',
                              project='test-project').put()
        data_types.FuzzTargetJob(fuzz_target_name='parent_child',
                                 job='job3',
                                 last_run=datetime.datetime.utcnow()).put()
  def setUp(self):
    helpers.patch_environ(self)

    # Two fuzz targets with two jobs enabled, one with and one without pruning.
    data_types.FuzzTarget(
        engine='libFuzzer', binary='test_fuzzer_1', project='project_1').put()
    data_types.FuzzTarget(
        engine='libFuzzer', binary='test_fuzzer_2', project='project_1').put()

    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_test_fuzzer_1',
        engine='libFuzzer',
        job='continuous_fuzzing_job_with_pruning').put()
    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_test_fuzzer_2',
        engine='libFuzzer',
        job='continuous_fuzzing_job_with_pruning').put()
    data_types.Job(
        name='continuous_fuzzing_job_with_pruning',
        platform='LINUX',
        environment_string=('CORPUS_PRUNE = True\n'
                            'RELEASE_BUILD_BUCKET_PATH=DOES_NOT_MATTER')).put()

    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_test_fuzzer_1',
        engine='libFuzzer',
        job='continuous_fuzzing_job_without_pruning').put()
    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_test_fuzzer_2',
        engine='libFuzzer',
        job='continuous_fuzzing_job_without_pruning').put()
    data_types.Job(
        name='continuous_fuzzing_job_without_pruning',
        platform='LINUX',
        environment_string=('CORPUS_PRUNE = False\n'
                            'RELEASE_BUILD_BUCKET_PATH=DOES_NOT_MATTER')).put()

    # Two fuzz targets with two CUSTOM_BINARY jobs, with and without pruning.
    data_types.FuzzTarget(
        engine='libFuzzer', binary='test_fuzzer_a', project='project_1').put()
    data_types.FuzzTarget(
        engine='libFuzzer', binary='test_fuzzer_b', project='project_1').put()

    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_test_fuzzer_a',
        engine='libFuzzer',
        job='custom_binary_job_with_pruning').put()
    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_test_fuzzer_b',
        engine='libFuzzer',
        job='custom_binary_job_with_pruning').put()
    data_types.Job(
        name='custom_binary_job_with_pruning',
        platform='LINUX',
        environment_string=('CORPUS_PRUNE = True\n'
                            'CUSTOM_BINARY = True')).put()

    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_test_fuzzer_a',
        engine='libFuzzer',
        job='custom_binary_job_without_pruning').put()
    data_types.FuzzTargetJob(
        fuzz_target_name='libFuzzer_test_fuzzer_b',
        engine='libFuzzer',
        job='custom_binary_job_without_pruning').put()
    data_types.Job(
        name='custom_binary_job_without_pruning',
        platform='LINUX',
        environment_string=('CORPUS_PRUNE = False\n'
                            'CUSTOM_BINARY = True')).put()
    def setUp(self):
        """Setup."""
        helpers.patch_environ(self)
        helpers.patch(self, [
            'clusterfuzz._internal.bot.fuzzers.engine_common.unpack_seed_corpus_if_needed',
            'clusterfuzz._internal.bot.tasks.corpus_pruning_task.'
            'choose_cross_pollination_strategy',
            'clusterfuzz._internal.bot.tasks.task_creation.create_tasks',
            'clusterfuzz._internal.bot.tasks.setup.update_fuzzer_and_data_bundles',
            'clusterfuzz._internal.fuzzing.corpus_manager.backup_corpus',
            'clusterfuzz._internal.fuzzing.corpus_manager.GcsCorpus.rsync_to_disk',
            'clusterfuzz._internal.fuzzing.corpus_manager.FuzzTargetCorpus.rsync_from_disk',
            'clusterfuzz._internal.google_cloud_utils.blobs.write_blob',
            'clusterfuzz._internal.google_cloud_utils.storage.write_data',
            'clusterfuzz.fuzz.engine.get',
        ])
        self.mock.get.return_value = libFuzzer_engine.Engine()
        self.mock.rsync_to_disk.side_effect = self._mock_rsync_to_disk
        self.mock.rsync_from_disk.side_effect = self._mock_rsync_from_disk
        self.mock.update_fuzzer_and_data_bundles.return_value = True
        self.mock.write_blob.return_value = 'key'
        self.mock.backup_corpus.return_value = 'backup_link'
        self.mock.choose_cross_pollination_strategy.return_value = ('random',
                                                                    None)

        def mocked_unpack_seed_corpus_if_needed(*args, **kwargs):
            """Mock's assert called methods are not powerful enough to ensure that
      unpack_seed_corpus_if_needed was called once with force_unpack=True.
      Instead, just assert that it was called once and during the call assert
      that it was called correctly.
      """
            self.assertTrue(kwargs.get('force_unpack', False))

        self.mock.unpack_seed_corpus_if_needed.side_effect = (
            mocked_unpack_seed_corpus_if_needed)

        data_types.FuzzTarget(engine='libFuzzer',
                              binary='test_fuzzer',
                              project='test-project').put()
        data_types.FuzzTargetJob(fuzz_target_name='libFuzzer_test_fuzzer',
                                 engine='libFuzzer',
                                 job='libfuzzer_asan_job').put()

        self.fuzz_inputs_disk = tempfile.mkdtemp()
        self.bot_tmpdir = tempfile.mkdtemp()
        self.build_dir = os.path.join(TEST_DIR, 'build')
        self.corpus_bucket = tempfile.mkdtemp()
        self.corpus_dir = os.path.join(self.corpus_bucket, 'corpus')
        self.quarantine_dir = os.path.join(self.corpus_bucket, 'quarantine')
        self.shared_corpus_dir = os.path.join(self.corpus_bucket, 'shared')

        shutil.copytree(os.path.join(TEST_DIR, 'corpus'), self.corpus_dir)
        shutil.copytree(os.path.join(TEST_DIR, 'quarantine'),
                        self.quarantine_dir)
        shutil.copytree(os.path.join(TEST_DIR, 'shared'),
                        self.shared_corpus_dir)

        os.environ['BOT_TMPDIR'] = self.bot_tmpdir
        os.environ['FUZZ_INPUTS'] = self.fuzz_inputs_disk
        os.environ['FUZZ_INPUTS_DISK'] = self.fuzz_inputs_disk
        os.environ['CORPUS_BUCKET'] = 'bucket'
        os.environ['QUARANTINE_BUCKET'] = 'bucket-quarantine'
        os.environ['SHARED_CORPUS_BUCKET'] = 'bucket-shared'
        os.environ['JOB_NAME'] = 'libfuzzer_asan_job'
        os.environ['FAIL_RETRIES'] = '1'
        os.environ['APP_REVISION'] = '1337'
    def setUp(self):
        """Set up."""
        super(CorpusPruningTestUntrusted, self).setUp()
        environment.set_value('JOB_NAME', 'libfuzzer_asan_job')

        helpers.patch(self, [
            'clusterfuzz._internal.bot.tasks.setup.get_fuzzer_directory',
            'clusterfuzz._internal.base.tasks.add_task',
            'clusterfuzz._internal.bot.tasks.corpus_pruning_task.'
            '_record_cross_pollination_stats',
            'clusterfuzz.fuzz.engine.get',
        ])

        self.mock.get.return_value = libFuzzer_engine.Engine()
        self.mock.get_fuzzer_directory.return_value = os.path.join(
            environment.get_value('ROOT_DIR'), 'src', 'clusterfuzz',
            '_internal', 'bot', 'fuzzers', 'libFuzzer')
        self.corpus_bucket = os.environ['CORPUS_BUCKET']
        self.quarantine_bucket = os.environ['QUARANTINE_BUCKET']
        self.backup_bucket = os.environ['BACKUP_BUCKET']

        job = data_types.Job(
            name='libfuzzer_asan_job',
            environment_string=(
                'APP_NAME = test_fuzzer\n'
                'CORPUS_BUCKET = {corpus_bucket}\n'
                'QUARANTINE_BUCKET = {quarantine_bucket}\n'
                'BACKUP_BUCKET={backup_bucket}\n'
                'RELEASE_BUILD_BUCKET_PATH = '
                'gs://clusterfuzz-test-data/test_libfuzzer_builds/'
                'test-libfuzzer-build-([0-9]+).zip\n'
                'REVISION_VARS_URL = gs://clusterfuzz-test-data/'
                'test_libfuzzer_builds/'
                'test-libfuzzer-build-%s.srcmap.json\n'.format(
                    corpus_bucket=self.corpus_bucket,
                    quarantine_bucket=self.quarantine_bucket,
                    backup_bucket=self.backup_bucket)))
        job.put()

        job = data_types.Job(
            name='libfuzzer_asan_job2',
            environment_string=(
                'APP_NAME = test2_fuzzer\n'
                'BACKUP_BUCKET = {backup_bucket}\n'
                'CORPUS_FUZZER_NAME_OVERRIDE = libfuzzer\n'.format(
                    backup_bucket=self.backup_bucket)))
        job.put()

        os.environ['PROJECT_NAME'] = 'oss-fuzz'
        data_types.FuzzTarget(engine='libFuzzer',
                              project='test',
                              binary='test_fuzzer').put()
        data_types.FuzzTargetJob(fuzz_target_name='libFuzzer_test_fuzzer',
                                 engine='libFuzzer',
                                 job='libfuzzer_asan_job',
                                 last_run=datetime.datetime.now()).put()

        data_types.FuzzTarget(engine='libFuzzer',
                              project='test2',
                              binary='fuzzer').put()
        data_types.FuzzTargetJob(fuzz_target_name='libFuzzer_test2_fuzzer',
                                 engine='libFuzzer',
                                 job='libfuzzer_asan_job2',
                                 last_run=datetime.datetime.now()).put()

        environment.set_value('USE_MINIJAIL', True)
        environment.set_value('SHARED_CORPUS_BUCKET', TEST_SHARED_BUCKET)

        # Set up remote corpora.
        self.corpus = corpus_manager.FuzzTargetCorpus('libFuzzer',
                                                      'test_fuzzer')
        self.corpus.rsync_from_disk(os.path.join(TEST_DIR, 'corpus'),
                                    delete=True)

        self.quarantine_corpus = corpus_manager.FuzzTargetCorpus(
            'libFuzzer', 'test_fuzzer', quarantine=True)
        self.quarantine_corpus.rsync_from_disk(os.path.join(
            TEST_DIR, 'quarantine'),
                                               delete=True)

        self.mock.get_data_bundle_bucket_name.return_value = TEST_GLOBAL_BUCKET
        data_types.DataBundle(name='bundle',
                              is_local=True,
                              sync_to_worker=True).put()

        data_types.Fuzzer(revision=1,
                          file_size='builtin',
                          source='builtin',
                          name='libFuzzer',
                          max_testcases=4,
                          builtin=True,
                          data_bundle_name='bundle').put()

        self.temp_dir = tempfile.mkdtemp()

        # Copy corpus backup in the older date format.
        corpus_backup_date = (
            datetime.datetime.utcnow().date() - datetime.timedelta(
                days=data_types.CORPUS_BACKUP_PUBLIC_LOOKBACK_DAYS))
        corpus_backup_dir = ('gs://{bucket}/corpus/libfuzzer/test2_fuzzer/')
        gsutil.GSUtilRunner().run_gsutil([
            'cp', (corpus_backup_dir +
                   'backup.zip').format(bucket=TEST2_BACKUP_BUCKET),
            (corpus_backup_dir +
             '%s.zip' % corpus_backup_date).format(bucket=self.backup_bucket)
        ])
Example #11
0
    def setUp(self):
        test_helpers.patch_environ(self)
        self.maxDiff = None  # pylint: disable=invalid-name

        data_types.Fuzzer(
            name='testFuzzer',
            stats_columns=('sum(t.blah) as blah, custom(j.new_crashes) '
                           'as new_crashes, _EDGE_COV as edge_coverage, '
                           '_FUNC_COV as func_coverage, '
                           '_CORPUS_SIZE as corpus_size, '
                           '_CORPUS_BACKUP as corpus_backup, '
                           '_QUARANTINE_SIZE as quarantine_size, '
                           '_COV_REPORT as coverage_report, '
                           '_FUZZER_RUN_LOGS as fuzzer_logs,'
                           '_PERFORMANCE_REPORT as performance_report'),
            stats_column_descriptions=(
                'blah: "blah description"\n'
                'func_coverage: "func coverage description"\n')).put()

        data_types.Fuzzer(
            name='testFuzzer2',
            stats_columns=('sum(t.blah) as blah, custom(j.new_crashes) '
                           'as new_crashes, _EDGE_COV as edge_coverage, '
                           '_FUNC_COV as func_coverage, '
                           '_CORPUS_SIZE as corpus_size, '
                           '_CORPUS_BACKUP as corpus_backup, '
                           '_QUARANTINE_SIZE as quarantine_size, '
                           '_COV_REPORT as coverage_report, '
                           '_FUZZER_RUN_LOGS as fuzzer_logs,'
                           '_PERFORMANCE_REPORT as performance_report'),
            stats_column_descriptions=(
                'blah: "blah description"\n'
                'func_coverage: "func coverage description"\n')).put()

        data_types.Job(name='job',
                       environment_string='FUZZ_LOGS_BUCKET = bucket').put()

        now = datetime.datetime.utcnow()

        data_types.FuzzTarget(engine='testFuzzer',
                              project='test-project',
                              binary='1_fuzzer').put()
        data_types.FuzzTargetJob(fuzz_target_name='testFuzzer_1_fuzzer',
                                 job='job',
                                 last_run=now).put()

        data_types.FuzzTarget(engine='testFuzzer',
                              project='test-project',
                              binary='2_fuzzer').put()
        data_types.FuzzTargetJob(fuzz_target_name='testFuzzer_2_fuzzer',
                                 job='job',
                                 last_run=now).put()

        data_types.FuzzTarget(engine='testFuzzer',
                              project='test-project',
                              binary='3_fuzzer').put()
        data_types.FuzzTargetJob(fuzz_target_name='testFuzzer_3_fuzzer',
                                 job='job',
                                 last_run=now).put()

        data_types.FuzzTarget(engine='testFuzzer2',
                              project='test-project',
                              binary='1_fuzzer').put()
        data_types.FuzzTargetJob(fuzz_target_name='testFuzzer2_1_fuzzer',
                                 job='job',
                                 last_run=now).put()

        cov_info = data_types.CoverageInformation(fuzzer='2_fuzzer',
                                                  date=datetime.date(
                                                      2016, 10, 19))
        cov_info.edges_covered = 11
        cov_info.edges_total = 30
        cov_info.functions_covered = 10
        cov_info.functions_total = 15
        cov_info.html_report_url = 'https://report_for_2_fuzzer/20161019'
        cov_info.corpus_size_units = 20
        cov_info.corpus_size_bytes = 200
        cov_info.quarantine_size_units = 0
        cov_info.quarantine_size_bytes = 0
        cov_info.corpus_location = 'gs://corpus'
        cov_info.corpus_backup_location = 'gs://corpus-backup/file.zip'
        cov_info.quarantine_location = 'gs://quarantine'
        cov_info.put()

        cov_info = data_types.CoverageInformation(fuzzer='2_fuzzer',
                                                  date=datetime.date(
                                                      2016, 10, 21))
        cov_info.edges_covered = 15
        cov_info.edges_total = 30
        cov_info.functions_covered = 11
        cov_info.functions_total = 15
        cov_info.html_report_url = 'https://report_for_2_fuzzer/20161021'
        cov_info.corpus_size_units = 40
        cov_info.corpus_size_bytes = 400
        cov_info.quarantine_size_units = 8
        cov_info.quarantine_size_bytes = 80
        cov_info.corpus_location = 'gs://corpus'
        cov_info.corpus_backup_location = 'gs://corpus-backup/file.zip'
        cov_info.quarantine_location = 'gs://quarantine'
        cov_info.put()

        cov_info = data_types.CoverageInformation(fuzzer='1_fuzzer',
                                                  date=datetime.date(
                                                      2016, 10, 20))
        cov_info.edges_covered = 17
        cov_info.edges_total = 38
        cov_info.functions_covered = 12
        cov_info.functions_total = 19
        cov_info.html_report_url = 'https://report_for_1_fuzzer/20161020'
        cov_info.corpus_size_units = 47
        cov_info.corpus_size_bytes = 480
        cov_info.quarantine_size_units = 3
        cov_info.quarantine_size_bytes = 8
        cov_info.corpus_location = 'gs://corpus'
        cov_info.corpus_backup_location = 'gs://corpus-backup/file.zip'
        cov_info.quarantine_location = 'gs://quarantine'
        cov_info.put()

        self.client = mock.Mock(spec_set=big_query.Client)
        test_helpers.patch(self, [
            'clusterfuzz._internal.google_cloud_utils.big_query.Client',
        ])
        self.mock.Client.return_value = self.client