Skip to content

Commit

Permalink
test: Run fuzz tests on macOS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarcoFalke committed Jun 22, 2023
1 parent 0c84a0e commit fae7c50
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ci/test/00_setup_env_mac_native_arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/test/fuzz/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/config.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -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_SYSCALL_SANDBOX_TRUE@ENABLE_SYSCALL_SANDBOX=true
Expand Down
29 changes: 17 additions & 12 deletions test/fuzz/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -259,7 +261,7 @@ def job(t, args):
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
Expand All @@ -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

Expand All @@ -301,7 +306,7 @@ def job(t, args):
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)


Expand Down

0 comments on commit fae7c50

Please sign in to comment.