def testInitializeWithCrashData(self):
        """Tests ``Initialize`` initialize all properties from crash data."""
        predator = self.GetMockPredatorApp()
        regression_range = {
            'dep_path': 'v8',
            'repo_url': 'https://v8.git',
            'old_revision': '1',
            'new_revision': '9'
        }
        raw_crash_data = self.GetDummyClusterfuzzData(
            regression_range=regression_range)

        class MockClusterfuzzData(ClusterfuzzData):
            def __init__(self, raw_crash_data):
                super(MockClusterfuzzData, self).__init__(raw_crash_data, None)

            @property
            def stacktrace(self):
                return None

            @property
            def regression_range(self):
                return None

            @property
            def dependencies(self):
                return {}

            @property
            def dependency_rolls(self):
                return {}

            @property
            def commit_count_in_regression_range(self):
                return 5

        predator.GetCrashData = mock.Mock(
            return_value=MockClusterfuzzData(raw_crash_data))

        crash_data = predator.GetCrashData(raw_crash_data)

        analysis = ClusterfuzzAnalysis()
        analysis.Initialize(crash_data)
        self.assertEqual(analysis.crash_type, crash_data.crash_type)
        self.assertEqual(analysis.crash_address, crash_data.crash_address)
        self.assertEqual(analysis.job_type, crash_data.job_type)
        self.assertEqual(analysis.sanitizer, crash_data.sanitizer)
        self.assertEqual(analysis.security_flag, crash_data.security_flag)
        self.assertEqual(analysis.root_repo_url, 'https://v8.git')
        self.assertEqual(analysis.root_repo_path, 'v8')
    def testToJson(self):
        testcase_id = '1234'
        job_type = 'asan'
        analysis = ClusterfuzzAnalysis.Create(testcase_id)
        analysis.testcase_id = testcase_id
        analysis.job_type = job_type
        analysis.security_flag = True

        expected_json = {
            'regression_range': None,
            'dependencies': None,
            'dependency_rolls': None,
            'crash_type': None,
            'crash_address': None,
            'sanitizer': None,
            'job_type': job_type,
            'testcase_id': testcase_id,
            'security_flag': True,
        }

        self.assertDictEqual(
            analysis.ToJson(), {
                'customized_data': expected_json,
                'platform': None,
                'stack_trace': None,
                'crash_revision': None,
                'signature': None,
                'client_id': 'clusterfuzz',
                'crash_identifiers': None
            })
    def testProperties(self):
        testcase_id = '1232435'

        analysis = ClusterfuzzAnalysis.Create(testcase_id)
        analysis.identifiers = testcase_id

        self.assertEqual(analysis.identifiers, testcase_id)
 def testClusterfuzzAnalysisReset(self):
     """Tests ``Reset`` reset all properties."""
     analysis = ClusterfuzzAnalysis()
     analysis.crash_type = 'check'
     analysis.crash_address = '0x0000'
     analysis.sanitizer = 'ASAN'
     analysis.job_type = 'android_asan_win'
     analysis.security_flag = True
     analysis.Reset()
     self.assertIsNone(analysis.crash_type)
     self.assertIsNone(analysis.crash_address)
     self.assertIsNone(analysis.sanitizer)
     self.assertIsNone(analysis.job_type)
     self.assertFalse(analysis.security_flag)
Beispiel #5
0
    def testInitializeWithCrashData(self):
        """Tests ``Initialize`` initialize all properties from crash data."""
        findit = self.GetMockFindit()
        raw_crash_data = self.GetDummyClusterfuzzData()

        class MockClusterfuzzData(ClusterfuzzData):
            def __init__(self, raw_crash_data):
                super(MockClusterfuzzData, self).__init__(raw_crash_data, None)

            @property
            def stacktrace(self):
                return None

            @property
            def regression_range(self):
                return None

            @property
            def dependencies(self):
                return {}

            @property
            def dependency_rolls(self):
                return {}

        self.mock(
            findit,
            'GetCrashData',
            lambda raw_crash_data:  # pylint: disable=W0108
            MockClusterfuzzData(raw_crash_data))

        crash_data = findit.GetCrashData(raw_crash_data)
        analysis = ClusterfuzzAnalysis()
        analysis.Initialize(crash_data)
        self.assertEqual(analysis.crashed_type, crash_data.crashed_type)
        self.assertEqual(analysis.crashed_address, crash_data.crashed_address)
        self.assertEqual(analysis.job_type, crash_data.job_type)
        self.assertEqual(analysis.sanitizer, crash_data.sanitizer)
    def testToJsonForNonEmptyDependencies(self):
        """Tests ``ToJson`` for non-empty self.dependencies."""
        testcase_id = '1234'
        job_type = 'asan'
        analysis = ClusterfuzzAnalysis.Create(testcase_id)
        analysis.testcase_id = testcase_id
        analysis.job_type = job_type
        analysis.dependencies = {
            'src': Dependency('src', 'https://repo', 'rev'),
            'src/v8': Dependency('src/v8', 'https://repo/v8', 'rev2')
        }

        dependencies_json = [{
            'dep_path': 'src',
            'repo_url': 'https://repo',
            'revision': 'rev'
        }, {
            'dep_path': 'src/v8',
            'repo_url': 'https://repo/v8',
            'revision': 'rev2'
        }]
        expected_json = {
            'regression_range': None,
            'dependencies': dependencies_json,
            'dependency_rolls': None,
            'crash_type': None,
            'crash_address': None,
            'sanitizer': None,
            'job_type': job_type,
            'security_flag': False,
            'testcase_id': testcase_id,
        }

        self.assertDictEqual(
            analysis.ToJson(), {
                'customized_data': expected_json,
                'platform': None,
                'stack_trace': None,
                'crash_revision': None,
                'signature': None,
                'crash_identifiers': None,
                'client_id': 'clusterfuzz'
            })
 def GetAnalysis(self, crash_identifiers):
     """Gets ``ClusterfuzzAnalysis`` using crash_identifiers."""
     return ClusterfuzzAnalysis.Get(crash_identifiers)
 def CreateAnalysis(self, crash_identifiers):
     """Creates ``ClusterfuzzAnalysis`` with crash_identifiers as key."""
     return ClusterfuzzAnalysis.Create(crash_identifiers)
    def testCrashDataToDisplayForFailedAnalysis(self):
        analysis = ClusterfuzzAnalysis()
        analysis.signature = 'sig'
        analysis.testcase_id = '123'
        analysis.crashed_version = '134abs'
        analysis.job_type = 'asan_job'
        analysis.crash_type = 'check'
        analysis.platform = 'win'
        analysis.commit_count_in_regression_range = 3
        analysis.put()

        expected_display_data = [{
            'signature': 'sig',
            'testcase_id': '123',
            'version': '134abs',
            'job_type': 'asan_job',
            'crash_type': 'check',
            'platform': 'win',
            'commits': 3,
            'log': [],
            'suspected_cls': [],
            'suspected_project': '',
            'suspected_components': [],
            'key': analysis.key.urlsafe(),
        }]

        self.assertListEqual(self.dashboard.CrashDataToDisplay([analysis]),
                             expected_display_data)
    def testCrashDataToDisplay(self):
        analysis = ClusterfuzzAnalysis()
        analysis.signature = 'sig'
        analysis.testcase_id = '123'
        analysis.crashed_version = '134abs'
        analysis.job_type = 'asan_job'
        analysis.crash_type = 'check'
        analysis.platform = 'win'
        analysis.commit_count_in_regression_range = 3
        analysis.result = {
            'suspected_cls': [{
                'author': 'someone'
            }],
            'suspected_project':
            'chromium',
            'suspected_components': ['Blink'],
            'log': [{
                'level': 'error',
                'name': 'FailedToParseStacktrace',
                'message': 'blabla...'
            }],
        }
        analysis.put()

        expected_display_data = [{
            'signature': 'sig',
            'testcase_id': '123',
            'version': '134abs',
            'job_type': 'asan_job',
            'crash_type': 'check',
            'platform': 'win',
            'commits': 3,
            'log': ['FailedToParseStacktrace'],
            'suspected_cls': [{
                'author': 'someone'
            }],
            'suspected_project': 'chromium',
            'suspected_components': ['Blink'],
            'key': analysis.key.urlsafe(),
        }]

        self.assertListEqual(self.dashboard.CrashDataToDisplay([analysis]),
                             expected_display_data)