Merge bitcoin/bitcoin#27932: test: Fuzz on macOS

fae7c50d20 test: Run fuzz tests on macOS (MarcoFalke)

Pull request description:

  Any reason not to?

ACKs for top commit:
  jamesob:
    Github ACK fae7c50d20
  dergoegge:
    utACK fae7c50d20

Tree-SHA512: e45122d73fafb17cea312258314b826cb0745e08daadd28465f687ec02d4c127d2f8cbe20179a9fff5712038850c02c968abb4838fa088b7555e28709317d3a3
pull/28002/head
fanquake 10 months ago
commit 3d51f7c9a8
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

@ -14,3 +14,5 @@ export CI_OS_NAME="macos"
export NO_DEPENDS=1
export OSX_SDK=""
export CCACHE_SIZE=300M
export RUN_FUZZ_TESTS=true
export FUZZ_TESTS_CONFIG="--exclude banman" # https://github.com/bitcoin/bitcoin/issues/27924

@ -73,6 +73,7 @@ const std::vector<std::string> RPC_COMMANDS_NOT_SAFE_FOR_FUZZING{
"addpeeraddress", // avoid DNS lookups
"dumptxoutset", // avoid writing to disk
"dumpwallet", // avoid writing to disk
"enumeratesigners",
"echoipc", // avoid assertion failure (Assertion `"EnsureAnyNodeContext(request.context).init" && check' failed.)
"generatetoaddress", // avoid prohibitively slow execution (when `num_blocks` is large)
"generatetodescriptor", // avoid prohibitively slow execution (when `nblocks` is large)

@ -22,7 +22,7 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py
@BUILD_BITCOIN_UTIL_TRUE@ENABLE_BITCOIN_UTIL=true
@BUILD_BITCOIN_WALLET_TRUE@ENABLE_WALLET_TOOL=true
@BUILD_BITCOIND_TRUE@ENABLE_BITCOIND=true
@ENABLE_FUZZ_TRUE@ENABLE_FUZZ=true
@ENABLE_FUZZ_BINARY_TRUE@ENABLE_FUZZ_BINARY=true
@ENABLE_ZMQ_TRUE@ENABLE_ZMQ=true
@ENABLE_EXTERNAL_SIGNER_TRUE@ENABLE_EXTERNAL_SIGNER=true
@ENABLE_USDT_TRACEPOINTS_TRUE@ENABLE_USDT_TRACEPOINTS=true

@ -95,8 +95,8 @@ def main():
configfile = os.path.abspath(os.path.dirname(__file__)) + "/../config.ini"
config.read_file(open(configfile, encoding="utf8"))
if not config["components"].getboolean("ENABLE_FUZZ"):
logging.error("Must have fuzz targets built")
if not config["components"].getboolean("ENABLE_FUZZ_BINARY"):
logging.error("Must have fuzz executable built")
sys.exit(1)
# Build list of tests
@ -148,11 +148,12 @@ def main():
],
env=get_fuzz_env(target=test_list_selection[0], source_dir=config['environment']['SRCDIR']),
timeout=20,
check=True,
check=False,
stderr=subprocess.PIPE,
text=True,
).stderr
if "libFuzzer" not in help_output:
using_libfuzzer = "libFuzzer" in help_output
if (args.generate or args.m_dir) and not using_libfuzzer:
logging.error("Must be built with libFuzzer")
sys.exit(1)
except subprocess.TimeoutExpired:
@ -186,6 +187,7 @@ def main():
test_list=test_list_selection,
src_dir=config['environment']['SRCDIR'],
build_dir=config["environment"]["BUILDDIR"],
using_libfuzzer=using_libfuzzer,
use_valgrind=args.valgrind,
empty_min_time=args.empty_min_time,
)
@ -259,7 +261,7 @@ def merge_inputs(*, fuzz_pool, corpus, test_list, src_dir, build_dir, merge_dir)
future.result()
def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, use_valgrind, empty_min_time):
def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, using_libfuzzer, use_valgrind, empty_min_time):
jobs = []
for t in test_list:
corpus_path = corpus / t
@ -268,13 +270,16 @@ def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, use_valgrind,
os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'),
]
empty_dir = not any(corpus_path.iterdir())
if empty_min_time and empty_dir:
args += [f"-max_total_time={empty_min_time}"]
if using_libfuzzer:
if empty_min_time and empty_dir:
args += [f"-max_total_time={empty_min_time}"]
else:
args += [
"-runs=1",
corpus_path,
]
else:
args += [
"-runs=1",
corpus_path,
]
args += [corpus_path]
if use_valgrind:
args = ['valgrind', '--quiet', '--error-exitcode=1'] + args
@ -301,7 +306,7 @@ def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, use_valgrind,
logging.info(e.stdout)
if e.stderr:
logging.info(e.stderr)
logging.info("Target \"{}\" failed with exit code {}".format(" ".join(result.args), e.returncode))
logging.info(f"Target {result.args} failed with exit code {e.returncode}")
sys.exit(1)

Loading…
Cancel
Save