def test_grab_data_with_download(self):
        """Ensures all method calls are made correctly when downloading."""
        self.definition.binary_name = 'defined_binary'
        self.testcase.stacktrace_lines = [{
            'content': 'incorrect'
        }, {
            'content': '[Environment] A = b'
        }, {
            'content':
            ('Running command: path/to/stacktrace_binary --args --arg2 '
             '/path/to/testcase')
        }]

        self.options.build = 'download'
        reproduce.execute(**vars(self.options))

        self.mock.get_testcase_and_identity.assert_called_once_with(
            self.testcase.id, False)
        self.builder.assert_called_once_with(testcase=self.testcase,
                                             definition=self.definition,
                                             options=self.options)
        self.definition.reproducer.assert_called_once_with(
            binary_provider=self.builder.return_value,
            definition=self.definition,
            testcase=self.testcase,
            sanitizer=self.definition.sanitizer,
            options=self.options)
        self.builder.return_value.build.assert_called_once_with()
        self.mock.ensure_important_dirs.assert_called_once_with()
Example #2
0
    def test_grab_data_with_download(self):
        """Ensures all method calls are made correctly when downloading."""
        self.definition.binary_name = 'defined_binary'
        self.testcase.stacktrace_lines = [{
            'content': 'incorrect'
        }, {
            'content': '[Environment] A = b'
        }, {
            'content':
            ('Running command: path/to/stacktrace_binary --args --arg2 '
             '/path/to/testcase')
        }]

        self.options.build = 'download'
        reproduce.execute(**vars(self.options))

        self.assert_exact_calls(self.mock.get_testcase_info,
                                [mock.call('1234')])
        self.assert_n_calls(0, [self.mock.ensure_goma])
        self.assert_exact_calls(self.mock.Testcase, [mock.call(self.response)])
        self.assert_exact_calls(
            self.mock.DownloadedBinary,
            [mock.call(1234, 'chrome_build_url', 'defined_binary')])
        self.assert_exact_calls(self.definition.reproducer, [
            mock.call(binary_provider=self.mock.DownloadedBinary.return_value,
                      definition=self.definition,
                      testcase=self.testcase,
                      sanitizer=self.definition.sanitizer,
                      options=self.options)
        ])
    def test_unsupported_job(self):
        """Tests to ensure an exception is thrown with an unsupported job type."""

        testcase = mock.Mock(id=1234,
                             build_url='chrome_build_url',
                             revision=123456,
                             job_type='fuzzlibber_xunil')
        self.mock.Testcase.return_value = testcase
        with self.assertRaises(common.JobTypeNotSupportedError):
            reproduce.execute('1234', False, 'standalone')
    def test_grab_data_with_download(self):
        """Ensures all method calls are made correctly when downloading."""

        helpers.patch(self,
                      ['clusterfuzz.commands.reproduce.get_binary_definition'])
        self.mock.get_binary_definition.return_value = mock.Mock(
            binary_name='binary', sanitizer='ASAN')
        self.mock.DownloadedBinary.return_value = mock.Mock(
            symbolizer_path=('/path/to/symbolizer'))
        self.mock.DownloadedBinary.return_value.get_binary_path.return_value = (
            '/path/to/binary')
        stacktrace = [{
            'content': 'incorrect'
        }, {
            'content': '[Environment] A = b'
        }, {
            'content': ('Running command: path/to/binary --args --arg2 '
                        '/path/to/testcase')
        }]
        testcase = mock.Mock(id=1234,
                             build_url='chrome_build_url',
                             revision=123456,
                             job_type='linux_asan_d8',
                             stacktrace_lines=stacktrace,
                             reproducible=True)
        self.mock.Testcase.return_value = testcase
        reproduce.execute(testcase_id='1234',
                          current=False,
                          build='download',
                          disable_goma=False,
                          j=None,
                          iterations=None,
                          disable_xvfb=False,
                          target_args='--test',
                          edit_mode=True)

        self.assert_exact_calls(self.mock.get_testcase_info,
                                [mock.call('1234')])
        self.assert_n_calls(0, [self.mock.ensure_goma])
        self.assert_exact_calls(self.mock.Testcase, [mock.call(self.response)])
        self.assert_exact_calls(
            self.mock.DownloadedBinary,
            [mock.call(1234, 'chrome_build_url', 'binary')])
        self.assert_exact_calls(
            self.mock.get_binary_definition.return_value.reproducer, [
                mock.call(self.mock.DownloadedBinary.return_value, testcase,
                          'ASAN', False, '--test', True)
            ])
    def test_grab_data_with_download(self):
        """Ensures all method calls are made correctly when downloading."""
        self.mock.V8DownloadedBinary.return_value.get_binary_path.return_value = (
            '/path/to/binary')
        reproduce.execute('1234', False, True)

        self.assert_exact_calls(self.mock.get_testcase_info,
                                [mock.call('1234')])
        self.assert_exact_calls(self.mock.ensure_goma, [mock.call()])
        self.assert_exact_calls(self.mock.Testcase, [mock.call(self.response)])
        self.assert_exact_calls(
            self.mock.V8DownloadedBinary.return_value.get_binary_path,
            [mock.call()])
        self.assert_exact_calls(self.mock.V8DownloadedBinary,
                                [mock.call(1234, 'chrome_build_url')])
        self.assert_exact_calls(self.mock.reproduce_crash,
                                [mock.call('/path/to/binary', self.testcase)])
    def test_grab_data_no_download(self):
        """Ensures all method calls are made correctly when building locally."""
        self.mock.V8Builder.return_value.get_binary_path.return_value = (
            '/path/to/binary')
        reproduce.execute('1234', False, False)

        self.assert_exact_calls(self.mock.get_testcase_info,
                                [mock.call('1234')])
        self.assert_exact_calls(self.mock.ensure_goma, [mock.call()])
        self.assert_exact_calls(self.mock.Testcase, [mock.call(self.response)])
        self.assert_exact_calls(
            self.mock.V8Builder.return_value.get_binary_path, [mock.call()])
        self.assert_exact_calls(self.mock.V8Builder, [
            mock.call(1234, 'chrome_build_url', 123456, False, '/goma/dir',
                      '/v8/src')
        ])
        self.assert_exact_calls(self.mock.reproduce_crash,
                                [mock.call('/path/to/binary', self.testcase)])
    def test_grab_data_standalone(self):
        """Ensures all method calls are made correctly when building locally."""
        self.options.build = 'standalone'
        reproduce.execute(**vars(self.options))

        self.mock.get_testcase_and_identity.assert_called_once_with(
            self.testcase.id, False)
        self.builder.assert_called_once_with(testcase=self.testcase,
                                             definition=self.definition,
                                             options=self.options)
        self.definition.reproducer.assert_called_once_with(
            binary_provider=self.builder.return_value,
            definition=self.definition,
            testcase=self.testcase,
            sanitizer=self.definition.sanitizer,
            options=self.options)
        self.builder.return_value.build.assert_called_once_with()
        self.mock.ensure_important_dirs.assert_called_once_with()
    def test_grab_data_standalone(self):
        """Ensures all method calls are made correctly when building locally."""

        helpers.patch(self,
                      ['clusterfuzz.commands.reproduce.get_binary_definition'])
        self.mock.get_binary_definition.return_value = mock.Mock(
            kwargs={}, source_var='V8_SRC', sanitizer='ASAN')
        (self.mock.get_binary_definition.return_value.builder.return_value.
         get_binary_path.return_value) = '/path/to/binary'
        (self.mock.get_binary_definition.return_value.builder.return_value.
         symbolizer_path) = '/path/to/symbolizer'
        testcase = mock.Mock(id=1234,
                             build_url='chrome_build_url',
                             revision=123456,
                             job_type='linux_asan_d8',
                             reproducible=True,
                             reproduction_args='--always-opt')
        self.mock.Testcase.return_value = testcase
        reproduce.execute(testcase_id='1234',
                          current=False,
                          build='standalone',
                          disable_goma=False,
                          j=22,
                          iterations=None,
                          disable_xvfb=False,
                          target_args='--test',
                          edit_mode=True)

        self.assert_exact_calls(self.mock.get_testcase_info,
                                [mock.call('1234')])
        self.assert_exact_calls(self.mock.ensure_goma, [mock.call()])
        self.assert_exact_calls(self.mock.Testcase, [mock.call(self.response)])
        self.assert_exact_calls(
            self.mock.get_binary_definition.return_value.builder, [
                mock.call(testcase,
                          self.mock.get_binary_definition.return_value, False,
                          '/goma/dir', 22, True)
            ])
        self.assert_exact_calls(
            self.mock.get_binary_definition.return_value.reproducer, [
                mock.call(
                    self.mock.get_binary_definition.return_value.builder.
                    return_value, testcase, 'ASAN', False, '--test', True)
            ])
    def test_unsupported_job(self):
        """Tests to ensure an exception is thrown with an unsupported job type."""

        self.mock.get_testcase_info.return_value = {'testcase': {}}
        testcase = mock.Mock(id=1234,
                             build_url='chrome_build_url',
                             revision=123456,
                             job_type='fuzzlibber_xunil')
        self.mock.Testcase.return_value = testcase
        with self.assertRaises(SystemExit):
            reproduce.execute(testcase_id='1234',
                              current=False,
                              build='standalone',
                              disable_goma=False,
                              j=None,
                              iterations=None,
                              disable_xvfb=False,
                              target_args='--test',
                              edit_mode=True)
    def test_gesture_job(self):
        """Ensures an excpetion is thrown when running a job with gestures."""

        self.mock.get_testcase_info.return_value = {
            'testcase': {
                'gestures': 'yes'
            }
        }
        self.mock.Testcase.return_value = mock.Mock(job_type='good_job')

        with self.assertRaises(SystemExit):
            reproduce.execute(testcase_id='1234',
                              current=False,
                              build='standalone',
                              disable_goma=False,
                              j=None,
                              iterations=None,
                              disable_xvfb=False,
                              target_args='--test',
                              edit_mode=True)
    def test_download_no_defined_binary(self):
        """Test what happens when no binary name is defined."""
        helpers.patch(self,
                      ['clusterfuzz.commands.reproduce.get_binary_definition'])
        self.mock.get_binary_definition.return_value = mock.Mock(
            binary_name=None, sanitizer='ASAN')
        self.mock.DownloadedBinary.return_value = mock.Mock(
            symbolizer_path=('/path/to/symbolizer'))
        self.mock.DownloadedBinary.return_value.get_binary_path.return_value = (
            '/path/to/binary')
        stacktrace = [{
            'content': 'incorrect'
        }, {
            'content': '[Environment] A = b'
        }, {
            'content': ('Running command: path/to/binary --args --arg2 '
                        '/path/to/testcase')
        }]
        testcase = mock.Mock(id=1234,
                             build_url='chrome_build_url',
                             revision=123456,
                             job_type='linux_asan_d8',
                             stacktrace_lines=stacktrace,
                             reproducible=True)
        self.mock.Testcase.return_value = testcase
        reproduce.execute('1234', False, 'download')

        self.assert_exact_calls(self.mock.get_testcase_info,
                                [mock.call('1234')])
        self.assert_exact_calls(self.mock.ensure_goma, [mock.call()])
        self.assert_exact_calls(self.mock.Testcase, [mock.call(self.response)])
        self.assert_exact_calls(
            self.mock.DownloadedBinary.return_value.get_binary_path,
            [mock.call()])
        self.assert_exact_calls(
            self.mock.DownloadedBinary,
            [mock.call(1234, 'chrome_build_url', 'binary')])
        self.assert_exact_calls(self.mock.reproduce_crash, [
            mock.call('/path/to/binary', '/path/to/symbolizer', testcase,
                      'ASAN')
        ])
Example #12
0
    def test_grab_data_standalone(self):
        """Ensures all method calls are made correctly when building locally."""
        self.options.build = 'standalone'
        reproduce.execute(**vars(self.options))
        self.options.goma_dir = '/goma/dir'

        self.assert_exact_calls(self.mock.get_testcase_info,
                                [mock.call('1234')])
        self.assert_exact_calls(self.mock.ensure_goma, [mock.call()])
        self.assert_exact_calls(self.mock.Testcase, [mock.call(self.response)])
        self.assert_exact_calls(self.definition.builder, [
            mock.call(testcase=self.testcase,
                      definition=self.definition,
                      options=self.options)
        ])
        self.assert_exact_calls(self.definition.reproducer, [
            mock.call(binary_provider=self.builder,
                      definition=self.definition,
                      testcase=self.testcase,
                      sanitizer=self.definition.sanitizer,
                      options=self.options)
        ])
    def test_grab_data_standalone(self):
        """Ensures all method calls are made correctly when building locally."""

        helpers.patch(self,
                      ['clusterfuzz.commands.reproduce.get_binary_definition'])
        self.mock.get_binary_definition.return_value = mock.Mock(
            kwargs={}, source_var='V8_SRC', sanitizer='ASAN')
        (self.mock.get_binary_definition.return_value.builder.return_value.
         get_binary_path.return_value) = '/path/to/binary'
        (self.mock.get_binary_definition.return_value.builder.return_value.
         symbolizer_path) = '/path/to/symbolizer'
        testcase = mock.Mock(id=1234,
                             build_url='chrome_build_url',
                             revision=123456,
                             job_type='linux_asan_d8',
                             reproducible=True)
        self.mock.Testcase.return_value = testcase
        reproduce.execute('1234', False, 'standalone')

        self.assert_exact_calls(self.mock.get_testcase_info,
                                [mock.call('1234')])
        self.assert_exact_calls(self.mock.ensure_goma, [mock.call()])
        self.assert_exact_calls(self.mock.Testcase, [mock.call(self.response)])
        self.assert_exact_calls((self.mock.get_binary_definition.return_value.
                                 builder.return_value.get_binary_path),
                                [mock.call()])
        self.assert_exact_calls(
            self.mock.get_binary_definition.return_value.builder, [
                mock.call(testcase,
                          self.mock.get_binary_definition.return_value, False,
                          '/goma/dir')
            ])
        self.assert_exact_calls(self.mock.reproduce_crash, [
            mock.call('/path/to/binary', '/path/to/symbolizer', testcase,
                      'ASAN')
        ])
    def test_grab_data_with_download(self):
        """Ensures all method calls are made correctly when downloading."""
        self.mock.DownloadedBinary.return_value = mock.Mock(
            symbolizer_path=('/path/to/symbolizer'))
        self.mock.DownloadedBinary.return_value.get_binary_path.return_value = (
            '/path/to/binary')
        stacktrace = [{
            'content': 'incorrect'
        }, {
            'content': '[Environment] A = b'
        }, {
            'content': ('Running command: path/to/binary --args --arg2 '
                        '/path/to/testcase')
        }]
        testcase = mock.Mock(id=1234,
                             build_url='chrome_build_url',
                             revision=123456,
                             job_type='linux_asan_d8',
                             stacktrace_lines=stacktrace,
                             reproducible=True)
        self.mock.Testcase.return_value = testcase
        reproduce.execute('1234', False, 'download')

        self.assert_exact_calls(self.mock.get_testcase_info,
                                [mock.call('1234')])
        self.assert_exact_calls(self.mock.ensure_goma, [mock.call()])
        self.assert_exact_calls(self.mock.Testcase, [mock.call(self.response)])
        self.assert_exact_calls(
            self.mock.DownloadedBinary.return_value.get_binary_path,
            [mock.call()])
        self.assert_exact_calls(self.mock.DownloadedBinary,
                                [mock.call(1234, 'chrome_build_url', 'd8')])
        self.assert_exact_calls(self.mock.reproduce_crash, [
            mock.call('/path/to/binary', '/path/to/symbolizer', testcase,
                      'ASAN')
        ])