Skip to content

Commit

Permalink
✏️ fix path
Browse files Browse the repository at this point in the history
  • Loading branch information
MeditationDuck committed Dec 17, 2024
1 parent 13e5c29 commit 0799d0d
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions wake/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def extract_crash_log_dict(crash_log_file_path: Path) -> dict:
except json.JSONDecodeError:
raise ValueError(f"Invalid JSON format in crash log file: {crash_log_file_path}")

def get_shrink_argument_path(shrink_path_str: str) -> Path:
def get_shrink_argument_path(shrink_path_str: str, dir_name: str) -> Path:
try:
path = Path(shrink_path_str)
if not path.exists():
Expand All @@ -273,7 +273,7 @@ def get_shrink_argument_path(shrink_path_str: str) -> Path:
pass

crash_logs_dir = (
get_config().project_root_path / ".wake" / "logs" / "crashes"
get_config().project_root_path / ".wake" / "logs" / dir_name
)
if not crash_logs_dir.exists():
raise click.BadParameter(
Expand All @@ -287,30 +287,6 @@ def get_shrink_argument_path(shrink_path_str: str) -> Path:
raise click.BadParameter(f"Invalid crash log index: {index}")
return Path(crash_logs[index])

def get_shrank_argument_path(shrank_path_str: str) -> Path:
try:
shrank_path = Path(shrank_path_str)
if not shrank_path.exists():
raise ValueError(f"Shrank data file not found: {shrank_path}")
return shrank_path
except ValueError:
pass
shrank_data_path = (
get_config().project_root_path / ".wake" / "logs" / "shrank"
)
if not shrank_data_path.exists():
raise click.BadParameter(
f"Shrank data file not found: {shrank_data_path}"
)

index = int(shrank_path_str)
shrank_files = sorted(
shrank_data_path.glob("*.bin"), key=os.path.getmtime, reverse=True
)
if abs(index) > len(shrank_files):
raise click.BadParameter(f"Invalid crash log index: {index}")
return Path(shrank_files[index])

if shrank is not None and shrink is not None:
raise click.BadParameter(
"Both shrink and shrieked cannot be provided at the same time."
Expand All @@ -321,7 +297,7 @@ def get_shrank_argument_path(shrank_path_str: str) -> Path:

if shrink is not None:
set_fuzz_mode(1)
shrink_crash_path = get_shrink_argument_path(shrink)
shrink_crash_path = get_shrink_argument_path(shrink, "crashes")
print("shrink from crash log: ", shrink_crash_path)
crash_log_dict = extract_crash_log_dict(shrink_crash_path)
path = crash_log_dict["test_file"]
Expand All @@ -336,7 +312,7 @@ def get_shrank_argument_path(shrank_path_str: str) -> Path:

if shrank:
set_fuzz_mode(2)
shrank_data_path = get_shrank_argument_path(shrank)
shrank_data_path = get_shrink_argument_path(shrank, "shrank")
print("shrank from shrank data: ", shrank_data_path)
with open(shrank_data_path, "r") as f:
target_fuzz_path = json.load(f)["target_fuzz_path"]
Expand Down

0 comments on commit 0799d0d

Please sign in to comment.