Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make default result reporting more intuitive #404

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions grizzly/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def __init__(self):
" only applies to OOMs detected by Grizzly. (default: %(default)s)",
)
self.reporter_grp.add_argument(
"-l",
"--logs",
"-o",
"--output",
default=Path.cwd(),
type=Path,
help="Location to save logs and test cases. (default: %(default)s)",
Expand Down Expand Up @@ -287,14 +287,14 @@ def sanity_check(self, args):
self.parser.error("--log-limit must be >= 0")
args.log_limit *= 1_048_576

# if logs is specified, we need it to be a directory (whether existent or not)
if args.logs and args.logs.is_file():
self.parser.error("--logs cannot be a file")

if args.memory < 0:
self.parser.error("--memory must be >= 0")
args.memory *= 1_048_576

# if output is specified, it must be a directory (if it exists)
if args.output and args.output.is_file():
self.parser.error("--output cannot be a file")

if args.no_harness:
if args.time_limit is not None:
self.parser.error("--time-limit cannot be used with --no-harness")
Expand Down
16 changes: 0 additions & 16 deletions grizzly/common/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,22 +350,6 @@ def _find_entry_point(path):
raise TestCaseLoadFailure("Could not determine entry point")
return entry_point

@property
def landing_page(self):
"""TestCase.landing_page is deprecated!
Should be replaced with TestCase.entry_point.

Args:
None

Returns:
str: TestCase.entry_point.
"""
LOG.warning(
"'TestCase.landing_page' deprecated, use 'TestCase.entry_point' in adapter"
)
return self.entry_point

@classmethod
def load(cls, path, entry_point=None, catalog=False):
"""Load a TestCase.
Expand Down
2 changes: 1 addition & 1 deletion grizzly/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def main(args):
reporter = FuzzManagerReporter(args.tool or f"grizzly-{adapter.name}")
LOG.info("Results will be reported via FuzzManager (%s)", reporter.tool)
else:
reporter = FilesystemReporter(args.logs / "results")
reporter = FilesystemReporter(args.output / "results")
LOG.info("Results will be stored in '%s'", reporter.report_path)
reporter.display_logs = args.smoke_test or reporter.display_logs

Expand Down
11 changes: 7 additions & 4 deletions grizzly/reduce/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self):
super().__init__()

# these arguments have defaults that vary from ReplayCommonArgs
self.parser.set_defaults(include_test=True, logs=Path.cwd())
self.parser.set_defaults(output=Path.cwd())

reduce_args = self.parser.add_argument_group("Reduce Arguments")
reduce_args.add_argument(
Expand Down Expand Up @@ -112,7 +112,7 @@ class ReduceFuzzManagerIDArgs(ReduceCommonArgs):
def __init__(self):
"""Initialize argument parser."""
super().__init__()
self.parser.add_argument("input", type=int, help="FuzzManager ID to replay")
self.parser.add_argument("input", type=int, help="FuzzManager ID to reduce")

self.parser.add_argument(
"--no-repro-quality",
Expand All @@ -125,6 +125,7 @@ def __init__(self):

self.parser.add_argument(
"--test-index",
default=[],
type=int,
nargs="+",
help="Select a testcase to run when multiple testcases are loaded. "
Expand All @@ -135,8 +136,10 @@ def __init__(self):
def sanity_check(self, args):
super().sanity_check(args)

if args.no_harness and not args.test_index:
self.parser.error("'--no-harness' requires '--test-index'")
if args.no_harness and len(args.test_index) > 1:
self.parser.error(
"'--test-index' only supports a single value with '--no-harness'"
)


class ReduceFuzzManagerIDQualityArgs(ReduceFuzzManagerIDArgs):
Expand Down
2 changes: 1 addition & 1 deletion grizzly/reduce/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ def main(cls, args):
target,
testcases,
args.strategies,
args.logs,
args.output,
any_crash=args.any_crash,
expect_hang=expect_hang,
idle_delay=args.idle_delay,
Expand Down
15 changes: 10 additions & 5 deletions grizzly/reduce/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ def test_args_03(tmp_path, capsys):
ReduceFuzzManagerIDArgs().parse_args([str(exe), "123"])
# error cases
with raises(SystemExit):
ReduceFuzzManagerIDArgs().parse_args([str(exe), "123", "--no-harness"])
assert "error: '--no-harness' requires '--test-index'" in capsys.readouterr()[-1]
ReduceFuzzManagerIDArgs().parse_args(
[str(exe), "123", "--no-harness", "--test-index", "0", "1"]
)
assert (
"error: '--test-index' only supports a single value with '--no-harness'"
in capsys.readouterr()[-1]
)


def test_args_04(tmp_path):
Expand Down Expand Up @@ -169,7 +174,7 @@ def test_main_exit(
relaunch=1,
repeat=1,
sig=sig,
test_index=None,
test_index=[],
timeout=10,
**kwargs
)
Expand Down Expand Up @@ -243,7 +248,7 @@ def test_main_https_support(mocker, tmp_path, https_supported):
relaunch=1,
repeat=1,
sig=None,
test_index=None,
test_index=[],
use_http=False,
time_limit=1,
timeout=1,
Expand Down Expand Up @@ -277,7 +282,7 @@ def test_main_load_assets_and_env(mocker, tmp_path):
relaunch=1,
repeat=1,
sig=None,
test_index=None,
test_index=[],
time_limit=1,
timeout=1,
)
Expand Down
19 changes: 8 additions & 11 deletions grizzly/replay/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class ReplayCommonArgs(CommonArgs):
def __init__(self):
super().__init__()
self.parser.set_defaults(logs=None)
self.parser.set_defaults(output=None)

replay_args = self.parser.add_argument_group("Replay Arguments")
replay_args.set_defaults(entry_point=None)
Expand Down Expand Up @@ -57,12 +57,6 @@ def __init__(self):
"--sig", type=Path, help="Signature (JSON) file to match."
)

self.reporter_grp.add_argument(
"--include-test",
action="store_true",
help="Include the testcase when reporting results.",
)

def sanity_check(self, args):
super().sanity_check(args)

Expand All @@ -72,8 +66,8 @@ def sanity_check(self, args):
if args.idle_threshold and args.idle_delay <= 0:
self.parser.error("--idle-delay value must be positive")

if args.logs is None and (args.pernosco or args.rr):
self.parser.error("--logs must be set when using rr")
if args.output is None and (args.pernosco or args.rr):
self.parser.error("--output must be set when using rr")

if args.min_crashes < 1:
self.parser.error("--min-crashes value must be positive")
Expand Down Expand Up @@ -124,6 +118,7 @@ def __init__(self):

self.parser.add_argument(
"--test-index",
default=[],
type=int,
nargs="+",
help="Select a testcase to run when multiple testcases are loaded. "
Expand All @@ -134,8 +129,10 @@ def __init__(self):
def sanity_check(self, args):
super().sanity_check(args)

if args.no_harness and not args.test_index:
self.parser.error("'--no-harness' requires '--test-index'")
if args.no_harness and len(args.test_index) > 1:
self.parser.error(
"'--test-index' only supports a single value with '--no-harness'"
)


class ReplayFuzzManagerIDQualityArgs(ReplayFuzzManagerIDArgs):
Expand Down
5 changes: 4 additions & 1 deletion grizzly/replay/crash.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ def modify_args(args, crash, bucket):
LOG.warning("Failed to generate signature from crash data: %s", exc)

args.original_crash_id = args.input
# use the newest test case when not using a harness and test_index is not specified
if args.no_harness and not args.test_index:
args.test_index = [-1]
args.input = crash.testcases(subset=args.test_index)
# set tool name using crash entry
if args.tool is None:
LOG.info("Setting default --tool=%s from CrashEntry", crash.tool)
args.tool = crash.tool

# load signature if needed
if bucket is not None:
args.sig = bucket.signature_path()
Expand Down
6 changes: 2 additions & 4 deletions grizzly/replay/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def main(cls, args):
LOG.info("Results detected, signature does not match")
else:
LOG.info("No results detected")
if results and (args.logs or args.fuzzmanager):
if results and (args.output or args.fuzzmanager):
# add target assets to test cases
if not target.asset_mgr.is_empty():
for test in testcases:
Expand All @@ -708,9 +708,7 @@ def main(cls, args):
if args.fuzzmanager:
cls.report_to_fuzzmanager(results, testcases, args.tool)
else:
cls.report_to_filesystem(
args.logs, results, testcases if args.include_test else None
)
cls.report_to_filesystem(args.output, results, testcases)
return Exit.SUCCESS if success else Exit.FAILURE

except ConfigError as exc:
Expand Down
13 changes: 9 additions & 4 deletions grizzly/replay/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def test_replay_args_01(capsys, mocker, tmp_path):
(["--min-crashes", "0"], "error: --min-crashes value must be positive", 1),
# test invalid repeat value
(["--repeat", "-1"], "error: --repeat value must be positive", 1),
# test running with rr without --logs set
# test running with rr without --output set
param(
["--rr"],
"error: --logs must be set when using rr",
"error: --output must be set when using rr",
1,
marks=[mark.skipif(system() != "Linux", reason="Linux only")],
),
Expand Down Expand Up @@ -88,8 +88,13 @@ def test_replay_args_03(tmp_path, capsys):
ReplayFuzzManagerIDArgs().parse_args([str(exe), "123"])
# error cases
with raises(SystemExit):
ReplayFuzzManagerIDArgs().parse_args([str(exe), "123", "--no-harness"])
assert "error: '--no-harness' requires '--test-index'" in capsys.readouterr()[-1]
ReplayFuzzManagerIDArgs().parse_args(
[str(exe), "123", "--no-harness", "--test-index", "0", "1"]
)
assert (
"error: '--test-index' only supports a single value with '--no-harness'"
in capsys.readouterr()[-1]
)


def test_replay_args_04(capsys, tmp_path):
Expand Down
Loading
Loading