def setUp(self): helpers.patch(self, ['daemon.main.load_sanity_check_testcases', 'daemon.main.reset_and_run_testcase', 'daemon.main.update_auth_header', 'daemon.main.load_new_testcases', 'time.sleep']) self.setup_fake_filesystem() self.mock.load_sanity_check_testcases.return_value = [1, 2] self.mock.load_new_testcases.side_effect = [[3, 4], [5]] self.mock.reset_and_run_testcase.side_effect = [None, None, None, None, SystemExit]
def setUp(self): helpers.patch(self, [ 'clusterfuzz.common.execute', 'clusterfuzz.binary_providers.sha_from_revision', 'clusterfuzz.binary_providers.ChromiumBuilder.pre_build_steps']) testcase = mock.Mock(id=12345, build_url='', revision=4567) self.mock_os_environment({'V8_SRC': '/chrome/src'}) binary_definition = mock.Mock(source_var='V8_SRC', binary_name='binary') self.builder = binary_providers.CfiChromiumBuilder( testcase, binary_definition, False, '/goma/dir', None, False)
def setUp(self): self.setup_fake_filesystem() os.makedirs(main.CLUSTERFUZZ_CACHE_DIR) with open(main.AUTH_FILE_LOCATION, 'w') as f: f.write('Bearer xyzabc') helpers.patch(self, ['daemon.main.get_supported_jobtypes', 'requests.post', 'random.randint']) self.mock.randint.return_value = 6 self.mock.get_supported_jobtypes.return_value = {'chromium': [ 'supported', 'support']}
def setUp(self): helpers.patch(self, [ 'clusterfuzz.binary_providers.install_build_deps_32bit', 'clusterfuzz.binary_providers.sha_from_revision', 'clusterfuzz.binary_providers.V8Builder.pre_build_steps' ]) testcase = mock.Mock(id=12345, build_url='', revision=4567) self.mock_os_environment({'V8_SRC': '/chrome/src'}) definition = mock.Mock(source_var='V8_SRC', binary_name='binary') self.builder = binary_providers.V8Builder32Bit(testcase, definition, libs.make_options())
def setUp(self): self.setup_fake_filesystem() helpers.patch(self, [ 'clusterfuzz.common.get_stored_auth_header', 'clusterfuzz.common.execute', 'clusterfuzz.common.delete_if_exists', 'os.listdir', 'clusterfuzz.testcase.Testcase.get_true_testcase_path' ]) self.mock.get_stored_auth_header.return_value = 'Bearer 1a2s3d4f' self.testcase_dir = os.path.join(common.CLUSTERFUZZ_TESTCASES_DIR, '12345_testcase') self.test = build_base_testcase()
def setUp(self): self.mock_os_environment({'TEST': '1'}) self.popen = mock.Mock(spec=subprocess.Popen) helpers.patch(self, [ 'daemon.process.kill_last_pid', 'daemon.process.store_last_pid', 'os.setsid', 'subprocess.Popen', ]) self.mock.Popen.return_value = self.popen self.popen.pid = 123
def setUp(self): self.setup_fake_filesystem() os.makedirs(main.CHROMIUM_OUT) os.makedirs(main.CLUSTERFUZZ_CACHE_DIR) helpers.patch(self, [ 'daemon.main.call', 'daemon.stackdriver_logging.send_run', 'daemon.main.update_auth_header', 'daemon.main.run_testcase', 'daemon.main.prepare_binary_and_get_version' ]) self.mock.prepare_binary_and_get_version.return_value = '0.2.2rc10' self.mock.run_testcase.return_value = 'run_testcase'
def setUp(self): helpers.patch(self, [ 'clusterfuzz.common.execute', 'clusterfuzz.binary_providers.sha_from_revision', 'clusterfuzz.binary_providers.V8Builder.setup_gn_args']) testcase = mock.Mock(id=12345, build_url='', revision=4567, gn_args='msan_track_origins=2\n') self.mock_os_environment({'V8_SRC': '/chrome/src'}) binary_definition = mock.Mock(source_var='V8_SRC', binary_name='binary') self.builder = binary_providers.MsanV8Builder( testcase, binary_definition, False, '/goma/dir', None, False)
def setUp(self): self.setup_fake_filesystem() helpers.patch(self, [ 'clusterfuzz.reproducers.BaseReproducer.pre_build_steps', 'clusterfuzz.common.get_resource', 'pyfakefs.fake_filesystem.FakeFilesystem.RenameObject', ]) self.mock.get_resource.return_value = 'llvm' os.makedirs('/tmp/clusterfuzz-user-profile-data') patch_stacktrace_info(self) self.reproducer = create_reproducer( reproducers.LinuxChromeJobReproducer) self.reproducer.original_testcase_path = '/fake/LayoutTests/testcase'
def setUp(self): helpers.patch(self, ['clusterfuzz.commands.reproduce.get_supported_jobs']) self.mock.get_supported_jobs.return_value = { 'chromium': { 'libfuzzer_chrome_msan': common.BinaryDefinition(binary_providers.ChromiumBuilder, 'CHROMIUM_SRC', reproducers.BaseReproducer, sanitizer='MSAN') }, 'standalone': {} }
def setUp(self): helpers.patch(self, [ 'subprocess.Popen', 'logging.getLogger', 'logging.config.dictConfig', 'clusterfuzz.common.check_binary', 'clusterfuzz.common.wait_timeout', 'clusterfuzz.common.interpret_ninja_output', 'os.environ.copy' ]) self.mock.copy.return_value = {'OS': 'ENVIRON'} self.mock.dictConfig.return_value = {} from clusterfuzz import local_logging local_logging.start_loggers() self.lines = 'Line 1\nLine 2\nLine 3'
def setUp(self): patch_stacktrace_info(self) self.reproducer = create_reproducer( reproducers.LinuxChromeJobReproducer) helpers.patch(self, [ 'clusterfuzz.reproducers.LinuxChromeJobReproducer.reproduce_crash', 'clusterfuzz.reproducers.LinuxChromeJobReproducer.post_run_symbolize', 'requests.post', 'time.sleep' ]) self.mock.reproduce_crash.return_value = (0, ['stuff']) self.mock.post_run_symbolize.return_value = 'stuff' self.reproducer.crash_type = 'original_type' self.reproducer.crash_state = ['original', 'state'] self.reproducer.job_type = 'linux_ubsan_chrome'
def setUp(self): helpers.patch(self, [ 'clusterfuzz.binary_providers.PdfiumBuilder.setup_gn_args', 'clusterfuzz.common.execute', 'clusterfuzz.binary_providers.PdfiumBuilder.get_goma_cores', 'clusterfuzz.binary_providers.sha_from_revision', 'clusterfuzz.binary_providers.get_pdfium_sha']) self.mock.get_goma_cores.return_value = 120 self.mock.sha_from_revision.return_value = 'chrome_sha' testcase = mock.Mock(id=1234, build_url='', revision=54321) self.mock_os_environment({'V8_SRC': '/chrome/source/dir'}) binary_definition = mock.Mock(source_var='V8_SRC') self.builder = binary_providers.PdfiumBuilder( testcase, binary_definition, False, '/goma/dir', None, False)
def setUp(self): helpers.patch(self, [ 'clusterfuzz.binary_providers.sha_from_revision', 'clusterfuzz.common.execute', 'clusterfuzz.binary_providers.ChromiumBuilder.setup_gn_args', 'clusterfuzz.binary_providers.ChromiumBuilder.get_build_directory']) self.mock.sha_from_revision.return_value = '1a2s3d4f5g' self.mock.get_build_directory.return_value = '/chromium/build/dir' self.testcase = mock.Mock(id=12345, build_url='', revision=4567) self.mock_os_environment({'V8_SRC': '/chrome/src'}) self.binary_definition = mock.Mock( source_var='V8_SRC', binary_name='binary', target='target') self.builder = binary_providers.ChromiumBuilder( self.testcase, self.binary_definition, False, '/goma/dir', None, False) self.builder.build_directory = '/chrome/src/out/clusterfuzz_builds'
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 setUp(self): helpers.patch(self, [ 'clusterfuzz.binary_providers.V8Builder.download_build_data', 'clusterfuzz.binary_providers.sha_from_revision', 'clusterfuzz.binary_providers.V8Builder.checkout_source_by_sha', 'clusterfuzz.binary_providers.V8Builder.build_target', 'clusterfuzz.common.ask', 'clusterfuzz.binary_providers.V8Builder.get_current_sha', 'clusterfuzz.common.execute', 'clusterfuzz.common.get_source_directory']) self.setup_fake_filesystem() self.build_url = 'https://storage.cloud.google.com/abc.zip' self.mock.get_current_sha.return_value = '1a2s3d4f5g6h' self.mock.execute.return_value = [0, ''] self.chrome_source = os.path.join('chrome', 'src', 'dir')
def test_no_binary_name(self): """Test the functionality when no binary name is provided.""" helpers.patch(self, [ 'clusterfuzz.binary_providers.ChromiumBuilder.get_goma_cores']) self.mock.get_goma_cores.return_value = 120 stacktrace = [ {'content': 'not correct'}, {'content': '[Environment] A = b'}, {'content': ('Running command: path/to/binary --flag-1 --flag2 opt' ' /testcase/path')}] testcase = mock.Mock(id=12345, build_url='', revision=4567, stacktrace_lines=stacktrace) binary_definition = mock.Mock(source_var='V8_SRC', binary_name=None) builder = binary_providers.ChromiumBuilder( testcase, binary_definition, False, '/goma/dir', None, False) self.assertEqual(builder.binary_name, 'binary')
def test_get_goma_cores(self): """Ensure goma_cores is calculated correctly.""" helpers.patch(self, ['multiprocessing.cpu_count']) self.mock.cpu_count.return_value = 12 builder = binary_providers.ChromiumBuilder( self.testcase, self.binary_definition, False, '/goma/dir', None, False) builder.goma_dir = False result = builder.get_goma_cores() self.assertEqual(result, 9) builder.goma_dir = True result = builder.get_goma_cores() self.assertEqual(result, 600)
def setUp(self): helpers.patch(self, [ 'clusterfuzz.common.execute', 'clusterfuzz.common.check_confirm', 'clusterfuzz.binary_providers.ensure_sha', 'clusterfuzz.binary_providers.get_current_sha', 'clusterfuzz.binary_providers.sha_from_revision', 'clusterfuzz.binary_providers.is_repo_dirty', ]) self.chrome_source = '/usr/local/google/home/user/repos/chromium/src' self.testcase = mock.Mock(id=12345, build_url='', revision=4567) self.mock_os_environment({'V8_SRC': self.chrome_source}) definition = mock.Mock(source_var='V8_SRC', binary_name='binary') self.builder = binary_providers.ChromiumBuilder( self.testcase, definition, libs.make_options()) self.builder.git_sha = '1a2s3d4f'
def setUp(self): self.setup_fake_filesystem() helpers.patch(self, ['clusterfuzz.common.execute', 'clusterfuzz.binary_providers.sha_from_revision', 'clusterfuzz.binary_providers.get_pdfium_sha']) self.sha = '1a2s3d4f5g' self.mock.sha_from_revision.return_value = 'chrome_sha' self.mock.get_pdfium_sha = self.sha testcase = mock.Mock(id=1234, build_url='', revision=54321, gn_args='use_goma = true') self.mock_os_environment({'V8_SRC': '/chrome/source/dir'}) binary_definition = mock.Mock(source_var='V8_SRC') self.builder = binary_providers.PdfiumBuilder( testcase, binary_definition, False, '/goma/dir', None, False) self.testcase_dir = os.path.expanduser(os.path.join('~', 'test_dir')) self.mock.execute.return_value = (0, '12345')
def test_print_supported_jobs(self): """Tests that printing is formatted correctly.""" helpers.patch(self, ['logging.getLogger']) reload(supported_job_types) supported_job_types.execute() printed = yaml.dump({ 'chromium': ['chromium_job'], 'standalone': ['pdfium_job'] }) self.assert_exact_calls(self.mock.getLogger.return_value.debug, [mock.call('Printing supported job types')]) self.assert_exact_calls(self.mock.getLogger.return_value.info, [mock.call(printed)])
def setUp(self): helpers.patch(self, ['cmd_editor.editor.edit']) self.testcase = mock.Mock(id=1234, reproduction_args='--repro', environment={'ASAN_OPTIONS': 'test-asan'}, gestures=None, stacktrace_lines=[{ 'content': 'line' }], job_type='job_type') self.testcase_path = os.path.expanduser( os.path.join('~', '.clusterfuzz', '1234_testcase', 'testcase.js')) self.testcase.get_testcase_path.return_value = self.testcase_path self.provider = mock.Mock( symbolizer_path='/chrome/source/folder/llvm-symbolizer') self.provider.get_binary_path.return_value = '/chrome/source/folder/d8' self.provider.get_build_directory.return_value = '/chrome/source/folder'
def setUp(self): self.setup_fake_filesystem() helpers.patch(self, [ 'clusterfuzz.common.execute', 'clusterfuzz.binary_providers.sha_from_revision', 'cmd_editor.editor.edit' ]) self.testcase_dir = os.path.expanduser(os.path.join('~', 'test_dir')) testcase = mock.Mock(id=1234, build_url='', revision=54321, gn_args=None) self.mock_os_environment({'V8_SRC': '/chrome/source/dir'}) binary_definition = mock.Mock(source_var='V8_SRC') self.builder = binary_providers.V8Builder( testcase, binary_definition, False, '/goma/dir', None, True) def edit(content, prefix, comment): # pylint: disable=unused-argument return content + '\nedited' self.mock.edit.side_effect = edit
def setUp(self): helpers.patch(self, [ 'clusterfuzz.common.check_binary', 'clusterfuzz.common.kill', 'clusterfuzz.common.wait_timeout', 'clusterfuzz.common.get_stdin_handler', 'logging.config.dictConfig', 'logging.getLogger', 'os.environ.copy', 'subprocess.Popen', 'time.sleep' ]) self.mock.copy.return_value = {'OS': 'ENVIRON'} self.mock.dictConfig.return_value = {} self.mock.get_stdin_handler.return_value = ('input_str', '') from clusterfuzz import local_logging local_logging.start_loggers() self.stdout = 'Line 1\nLine 2\nLine 3\n' self.residue_stdout = 'residue' self.stderr = 'Err 1\nErr 2\nErr 3'
def setUp(self): helpers.patch(self, [ 'clusterfuzz.reproducers.BaseReproducer.pre_build_steps', 'clusterfuzz.reproducers.ensure_user_data_dir_if_needed', 'clusterfuzz.reproducers.update_testcase_path_in_layout_test', 'clusterfuzz.common.get_resource', 'pyfakefs.fake_filesystem.FakeFilesystem.RenameObject', ]) self.mock.get_resource.return_value = 'llvm' self.mock.ensure_user_data_dir_if_needed.side_effect = ( lambda args, require_user_data_dir: args + ' --test-user-data-dir') self.mock.update_testcase_path_in_layout_test.return_value = '/new-path' patch_stacktrace_info(self) self.reproducer = create_reproducer( reproducers.LinuxChromeJobReproducer) self.reproducer.definition.require_user_data_dir = False self.reproducer.original_testcase_path = '/fake/LayoutTests/testcase'
def setUp(self): helpers.patch(self, [ 'clusterfuzz.common.execute', 'clusterfuzz.common.check_confirm', 'clusterfuzz.binary_providers.sha_exists', 'clusterfuzz.binary_providers.sha_from_revision', 'clusterfuzz.binary_providers.GenericBuilder.source_dir_is_dirty', ]) self.mock.sha_exists.return_value = False self.chrome_source = '/usr/local/google/home/user/repos/chromium/src' self.command = 'git checkout 1a2s3d4f in %s' % self.chrome_source testcase = mock.Mock(id=12345, build_url='', revision=4567) self.mock_os_environment({'V8_SRC': self.chrome_source}) binary_definition = mock.Mock(source_var='V8_SRC', binary_name='binary') self.builder = binary_providers.ChromiumBuilder( testcase, binary_definition, False, '/goma/dir', None, False) self.builder.git_sha = '1a2s3d4f'
def setUp(self): self.setup_fake_filesystem() helpers.patch(self, [ 'clusterfuzz.common.start_execute', 'clusterfuzz.common.wait_execute', 'clusterfuzz.common.execute', 'clusterfuzz.reproducers.LinuxChromeJobReproducer.run_gestures', 'clusterfuzz.reproducers.Xvfb.__enter__', 'clusterfuzz.reproducers.Xvfb.__exit__', 'clusterfuzz.common.get_resource', 'clusterfuzz.reproducers.LinuxChromeJobReproducer.post_run_symbolize' ]) self.mock.get_resource.return_value = ( '/chrome/source/folder/llvm-symbolizer') self.mock.wait_execute.return_value = (0, 'lines') self.mock.post_run_symbolize.return_value = 'symbolized' self.app_directory = '/chrome/source/folder' self.testcase_path = os.path.expanduser( os.path.join('~', '.clusterfuzz', '1234_testcase', 'testcase.js'))
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_init_device_not_found(): port = 200 address = 0x710 path_name = '/dev/i2c-{}'.format(port) fake_open = i2c_error(path_name, errno.ENOENT) with patch('os.open', fake_open): with pytest.raises(luma.core.error.DeviceNotFoundError) as ex: i2c(port=port, address=address) assert str(ex.value) == 'I2C device not found: {}'.format(path_name)
def setUp(self): helpers.patch(self, [ 'time.sleep', ('clusterfuzz.reproducers.LinuxChromeJobReproducer.get_gesture_start_' 'time'), ('clusterfuzz.reproducers.LinuxChromeJobReproducer.find_windows_for' '_process'), 'clusterfuzz.reproducers.LinuxChromeJobReproducer.xdotool_command', 'clusterfuzz.reproducers.LinuxChromeJobReproducer.execute_gesture' ]) patch_stacktrace_info(self) self.reproducer = create_reproducer( reproducers.LinuxChromeJobReproducer) self.mock.get_gesture_start_time.return_value = 5 self.mock.find_windows_for_process.return_value = ['123'] self.reproducer.gestures = [ 'windowsize,2', 'type,\'ValeM1khbW4Gt!\'', 'Trigger:2' ] self.reproducer.gesture_start_time = 5