aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--infra/cifuzz/cifuzz.py5
-rw-r--r--infra/utils.py11
-rw-r--r--infra/utils_test.py19
3 files changed, 33 insertions, 2 deletions
diff --git a/infra/cifuzz/cifuzz.py b/infra/cifuzz/cifuzz.py
index 69e92a4c0..4a4c42a1c 100644
--- a/infra/cifuzz/cifuzz.py
+++ b/infra/cifuzz/cifuzz.py
@@ -427,8 +427,9 @@ 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.print(b'Fuzzer %s, detected error: %s.' % (
+ bytes(target.target_name, 'utf-8'),
+ 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..0b35d7970 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 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..3f7885d93 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,23 @@ class ExecuteTest(unittest.TestCase):
check_result=True)
+class PrintTest(unittest.TestCase):
+ """Tests for utils.print."""
+
+ @mock.patch('sys.stdout.buffer.write')
+ def test_string(self, mocked_write):
+ """Tests that utils.print can print a regular string."""
+ # Should execute without raising any exceptions.
+ utils.print('hello')
+ mocked_write.assert_called_with('hello\n')
+
+
+ @mock.patch('sys.stdout.buffer.write')
+ def test_binary_string(self, mocked_write):
+ """Tests that utils.print can print a binary string."""
+ # Should execute without raising any exceptions.
+ utils.print(b'hello')
+ mocked_write.assert_called_with(b'hello\n')
+
if __name__ == '__main__':
unittest.main()