test: Run fuzz tests on macOS

Also, fix a few bugs:

* Error: RPC command "enumeratesigners" not found in RPC_COMMANDS_SAFE_FOR_FUZZING or RPC_COMMANDS_NOT_SAFE_FOR_FUZZING. Please update test/fuzz/rpc.cpp.
* in run_once: ...format(" ".join(result.args), ... TypeError: sequence item 2: expected str instance, PosixPath found
This commit is contained in:
MarcoFalke 2023-06-22 11:49:28 +02:00
parent 0c84a0e484
commit fae7c50d20
No known key found for this signature in database
4 changed files with 21 additions and 13 deletions

View file

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

View file

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

View file

@ -22,7 +22,7 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py
@BUILD_BITCOIN_UTIL_TRUE@ENABLE_BITCOIN_UTIL=true @BUILD_BITCOIN_UTIL_TRUE@ENABLE_BITCOIN_UTIL=true
@BUILD_BITCOIN_WALLET_TRUE@ENABLE_WALLET_TOOL=true @BUILD_BITCOIN_WALLET_TRUE@ENABLE_WALLET_TOOL=true
@BUILD_BITCOIND_TRUE@ENABLE_BITCOIND=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_ZMQ_TRUE@ENABLE_ZMQ=true
@ENABLE_EXTERNAL_SIGNER_TRUE@ENABLE_EXTERNAL_SIGNER=true @ENABLE_EXTERNAL_SIGNER_TRUE@ENABLE_EXTERNAL_SIGNER=true
@ENABLE_SYSCALL_SANDBOX_TRUE@ENABLE_SYSCALL_SANDBOX=true @ENABLE_SYSCALL_SANDBOX_TRUE@ENABLE_SYSCALL_SANDBOX=true

View file

@ -95,8 +95,8 @@ def main():
configfile = os.path.abspath(os.path.dirname(__file__)) + "/../config.ini" configfile = os.path.abspath(os.path.dirname(__file__)) + "/../config.ini"
config.read_file(open(configfile, encoding="utf8")) config.read_file(open(configfile, encoding="utf8"))
if not config["components"].getboolean("ENABLE_FUZZ"): if not config["components"].getboolean("ENABLE_FUZZ_BINARY"):
logging.error("Must have fuzz targets built") logging.error("Must have fuzz executable built")
sys.exit(1) sys.exit(1)
# Build list of tests # Build list of tests
@ -148,11 +148,12 @@ def main():
], ],
env=get_fuzz_env(target=test_list_selection[0], source_dir=config['environment']['SRCDIR']), env=get_fuzz_env(target=test_list_selection[0], source_dir=config['environment']['SRCDIR']),
timeout=20, timeout=20,
check=True, check=False,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True, text=True,
).stderr ).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") logging.error("Must be built with libFuzzer")
sys.exit(1) sys.exit(1)
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
@ -186,6 +187,7 @@ def main():
test_list=test_list_selection, test_list=test_list_selection,
src_dir=config['environment']['SRCDIR'], src_dir=config['environment']['SRCDIR'],
build_dir=config["environment"]["BUILDDIR"], build_dir=config["environment"]["BUILDDIR"],
using_libfuzzer=using_libfuzzer,
use_valgrind=args.valgrind, use_valgrind=args.valgrind,
empty_min_time=args.empty_min_time, 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() 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 = [] jobs = []
for t in test_list: for t in test_list:
corpus_path = corpus / t 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'), os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'),
] ]
empty_dir = not any(corpus_path.iterdir()) empty_dir = not any(corpus_path.iterdir())
if empty_min_time and empty_dir: if using_libfuzzer:
args += [f"-max_total_time={empty_min_time}"] if empty_min_time and empty_dir:
args += [f"-max_total_time={empty_min_time}"]
else:
args += [
"-runs=1",
corpus_path,
]
else: else:
args += [ args += [corpus_path]
"-runs=1",
corpus_path,
]
if use_valgrind: if use_valgrind:
args = ['valgrind', '--quiet', '--error-exitcode=1'] + args 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) logging.info(e.stdout)
if e.stderr: if e.stderr:
logging.info(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) sys.exit(1)