diff --git a/infra/cifuzz/cifuzz.py b/infra/cifuzz/cifuzz.py index 69e92a4c0..06f95c665 100644 --- a/infra/cifuzz/cifuzz.py +++ b/infra/cifuzz/cifuzz.py @@ -427,8 +427,8 @@ def run_fuzzers( # pylint: disable=too-many-arguments,too-many-locals if not testcase or not stacktrace: logging.info('Fuzzer %s, finished running.', target.target_name) else: - logging.info(b'Fuzzer %s, detected error: %s.', target.target_name, - stacktrace) + utils.binary_print(b'Fuzzer %s, detected error: %s.' % + (target.target_name.encode(), stacktrace)) shutil.move(testcase, os.path.join(artifacts_dir, 'test_case')) parse_fuzzer_output(stacktrace, artifacts_dir) return True, True diff --git a/infra/utils.py b/infra/utils.py index 1cde40114..c99dabc73 100644 --- a/infra/utils.py +++ b/infra/utils.py @@ -18,6 +18,7 @@ import os import re import stat import subprocess +import sys import helper @@ -127,3 +128,13 @@ def is_fuzz_target_local(file_path): with open(file_path, 'rb') as file_handle: return file_handle.read().find(FUZZ_TARGET_SEARCH_STRING.encode()) != -1 + + +def binary_print(string): + """Print that can print a binary string.""" + if isinstance(string, bytes): + string += b'\n' + else: + string += '\n' + sys.stdout.buffer.write(string) + sys.stdout.flush() diff --git a/infra/utils_test.py b/infra/utils_test.py index 0fc614f86..a56295c93 100644 --- a/infra/utils_test.py +++ b/infra/utils_test.py @@ -16,6 +16,7 @@ import os import tempfile import unittest +from unittest import mock import utils import helper @@ -110,5 +111,25 @@ class ExecuteTest(unittest.TestCase): check_result=True) +class BinaryPrintTest(unittest.TestCase): + """Tests for utils.binary_print.""" + + @unittest.skip('Causes spurious failures because of side-effects.') + def test_string(self): # pylint: disable=no-self-use + """Tests that utils.binary_print can print a regular string.""" + # Should execute without raising any exceptions. + with mock.patch('sys.stdout.buffer.write') as mocked_write: + utils.binary_print('hello') + mocked_write.assert_called_with('hello\n') + + @unittest.skip('Causes spurious failures because of side-effects.') + def test_binary_string(self): # pylint: disable=no-self-use + """Tests that utils.binary_print can print a bianry string.""" + # Should execute without raising any exceptions. + with mock.patch('sys.stdout.buffer.write') as mocked_write: + utils.binary_print(b'hello') + mocked_write.assert_called_with(b'hello\n') + + if __name__ == '__main__': unittest.main()