mirror of https://github.com/google/oss-fuzz.git
Use print for printing stacktrace instead of using log. (#4799)
Use print for printing stacktrace instead of using log. This makes stacktrace more legible. Fixes https://github.com/google/oss-fuzz/issues/4649
This commit is contained in:
parent
edd0c5d5ef
commit
301ed831be
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue