def checkout_source_by_sha(self): """Checks out the correct revision.""" if self.get_current_sha() == self.git_sha: return command = 'git fetch && git checkout %s' % self.git_sha common.check_confirm('Proceed with the following command:\n%s in %s?' % (command, self.source_directory)) common.execute(command, self.source_directory)
def checkout_source_by_sha(self): """Checks out the correct revision.""" _, current_sha = common.execute('git rev-parse HEAD', self.source_directory, print_output=False) if current_sha.strip() == self.git_sha: return command = 'git fetch && git checkout %s' % self.git_sha common.check_confirm('Proceed with the following command:\n%s in %s?' % (command, self.source_directory)) common.execute(command, self.source_directory)
def git_checkout(sha, revision, source_dir_path): """Checks out the correct revision.""" if get_current_sha(source_dir_path) == sha: logger.info( 'The current state of %s is already on the revision %s (commit=%s). ' 'No action needed.', source_dir_path, revision, sha) return binary = 'git' args = 'checkout %s' % sha common.check_confirm(CHECKOUT_MESSAGE.format( revision=revision, cmd='%s %s' % (binary, args), source_dir=source_dir_path)) if is_repo_dirty(source_dir_path): raise error.DirtyRepoError(source_dir_path) ensure_sha(sha, source_dir_path) common.execute(binary, args, source_dir_path)
def checkout_source_by_sha(self): """Checks out the correct revision.""" if self.get_current_sha() == self.git_sha: return if not sha_exists(self.git_sha, self.source_directory): common.execute( 'git', 'fetch origin %s' % self.git_sha, self.source_directory) binary = 'git' args = 'checkout %s' % self.git_sha common.check_confirm( 'Proceed with the following command:\n' '%s %s in %s?' % (binary, args, self.source_directory)) if self.source_dir_is_dirty(): logger.info('Your source directory has uncommitted changes: please ' 'commit or stash these changes and re-run this tool.') sys.exit(1) common.execute(binary, args, self.source_directory)
def checkout_source_by_sha(self): """Checks out the correct revision.""" if get_current_sha(self.source_directory) == self.git_sha: logger.info( 'The current state of %s is already on the revision %s (commit=%s). ' 'No action needed.', self.source_directory, self.testcase.revision, self.git_sha) return binary = 'git' args = 'checkout %s' % self.git_sha common.check_confirm( CHECKOUT_MESSAGE.format(revision=self.testcase.revision, cmd='%s %s' % (binary, args), source_dir=self.source_directory)) if is_repo_dirty(self.source_directory): raise common.DirtyRepoError(self.source_directory) ensure_sha(self.git_sha, self.source_directory) common.execute(binary, args, self.source_directory)
def ensure_asan(android_libclang_dir_path, device_id): """Ensures ASan is installed on Android.""" logger.info( 'The testcase needs ASAN. After installing ASAN, the device might be ' 'restarted.') common.check_confirm( 'Are you sure you want to install ASAN on the device %s?' % device_id) _, output = common.execute( common.get_resource(0755, 'resources', 'asan_device_setup.sh'), '--lib %s --device %s' % (android_libclang_dir_path, device_id), env={'ADB_PATH': common.check_binary('adb', cwd='.')}, redirect_stderr_to_stdout=True, cwd='.') # tool/clusterfuzz/resources/asan_device_setup.sh prints the below string # when it modifies asan configuration on device. So, wait for the reboot to # be complete. if ASAN_BEING_INSTALLED_SEARCH_STRING in output: wait_until_fully_booted()
def test_answer_no(self): self.mock.confirm.return_value = False with self.assertRaises(error.UserRespondingNoError): common.check_confirm('Question?') self.assert_exact_calls(self.mock.confirm, [mock.call('Question?')])
def test_answer_yes(self): self.mock.confirm.return_value = True common.check_confirm('Question?') self.assert_exact_calls(self.mock.confirm, [mock.call('Question?')])
def test_answer_no(self): self.mock.confirm.return_value = False with self.assertRaises(SystemExit): common.check_confirm('Question?') self.assert_exact_calls(self.mock.confirm, [mock.call('Question?')])