Skip to content

Commit fae7c50

Browse files
author
MarcoFalke
committed
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
1 parent 0c84a0e commit fae7c50

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

ci/test/00_setup_env_mac_native_arm64.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ export CI_OS_NAME="macos"
1414
export NO_DEPENDS=1
1515
export OSX_SDK=""
1616
export CCACHE_SIZE=300M
17+
export RUN_FUZZ_TESTS=true
18+
export FUZZ_TESTS_CONFIG="--exclude banman" # https://github.com/bitcoin/bitcoin/issues/27924

src/test/fuzz/rpc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const std::vector<std::string> RPC_COMMANDS_NOT_SAFE_FOR_FUZZING{
7373
"addpeeraddress", // avoid DNS lookups
7474
"dumptxoutset", // avoid writing to disk
7575
"dumpwallet", // avoid writing to disk
76+
"enumeratesigners",
7677
"echoipc", // avoid assertion failure (Assertion `"EnsureAnyNodeContext(request.context).init" && check' failed.)
7778
"generatetoaddress", // avoid prohibitively slow execution (when `num_blocks` is large)
7879
"generatetodescriptor", // avoid prohibitively slow execution (when `nblocks` is large)

test/config.ini.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py
2222
@BUILD_BITCOIN_UTIL_TRUE@ENABLE_BITCOIN_UTIL=true
2323
@BUILD_BITCOIN_WALLET_TRUE@ENABLE_WALLET_TOOL=true
2424
@BUILD_BITCOIND_TRUE@ENABLE_BITCOIND=true
25-
@ENABLE_FUZZ_TRUE@ENABLE_FUZZ=true
25+
@ENABLE_FUZZ_BINARY_TRUE@ENABLE_FUZZ_BINARY=true
2626
@ENABLE_ZMQ_TRUE@ENABLE_ZMQ=true
2727
@ENABLE_EXTERNAL_SIGNER_TRUE@ENABLE_EXTERNAL_SIGNER=true
2828
@ENABLE_SYSCALL_SANDBOX_TRUE@ENABLE_SYSCALL_SANDBOX=true

test/fuzz/test_runner.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def main():
9595
configfile = os.path.abspath(os.path.dirname(__file__)) + "/../config.ini"
9696
config.read_file(open(configfile, encoding="utf8"))
9797

98-
if not config["components"].getboolean("ENABLE_FUZZ"):
99-
logging.error("Must have fuzz targets built")
98+
if not config["components"].getboolean("ENABLE_FUZZ_BINARY"):
99+
logging.error("Must have fuzz executable built")
100100
sys.exit(1)
101101

102102
# Build list of tests
@@ -148,11 +148,12 @@ def main():
148148
],
149149
env=get_fuzz_env(target=test_list_selection[0], source_dir=config['environment']['SRCDIR']),
150150
timeout=20,
151-
check=True,
151+
check=False,
152152
stderr=subprocess.PIPE,
153153
text=True,
154154
).stderr
155-
if "libFuzzer" not in help_output:
155+
using_libfuzzer = "libFuzzer" in help_output
156+
if (args.generate or args.m_dir) and not using_libfuzzer:
156157
logging.error("Must be built with libFuzzer")
157158
sys.exit(1)
158159
except subprocess.TimeoutExpired:
@@ -186,6 +187,7 @@ def main():
186187
test_list=test_list_selection,
187188
src_dir=config['environment']['SRCDIR'],
188189
build_dir=config["environment"]["BUILDDIR"],
190+
using_libfuzzer=using_libfuzzer,
189191
use_valgrind=args.valgrind,
190192
empty_min_time=args.empty_min_time,
191193
)
@@ -259,7 +261,7 @@ def job(t, args):
259261
future.result()
260262

261263

262-
def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, use_valgrind, empty_min_time):
264+
def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, using_libfuzzer, use_valgrind, empty_min_time):
263265
jobs = []
264266
for t in test_list:
265267
corpus_path = corpus / t
@@ -268,13 +270,16 @@ def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, use_valgrind,
268270
os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'),
269271
]
270272
empty_dir = not any(corpus_path.iterdir())
271-
if empty_min_time and empty_dir:
272-
args += [f"-max_total_time={empty_min_time}"]
273+
if using_libfuzzer:
274+
if empty_min_time and empty_dir:
275+
args += [f"-max_total_time={empty_min_time}"]
276+
else:
277+
args += [
278+
"-runs=1",
279+
corpus_path,
280+
]
273281
else:
274-
args += [
275-
"-runs=1",
276-
corpus_path,
277-
]
282+
args += [corpus_path]
278283
if use_valgrind:
279284
args = ['valgrind', '--quiet', '--error-exitcode=1'] + args
280285

@@ -301,7 +306,7 @@ def job(t, args):
301306
logging.info(e.stdout)
302307
if e.stderr:
303308
logging.info(e.stderr)
304-
logging.info("Target \"{}\" failed with exit code {}".format(" ".join(result.args), e.returncode))
309+
logging.info(f"Target {result.args} failed with exit code {e.returncode}")
305310
sys.exit(1)
306311

307312

0 commit comments

Comments
 (0)