Skip to content

Commit

Permalink
✏️ fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MeditationDuck committed Dec 17, 2024
1 parent 32f4264 commit 5963d93
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
10 changes: 10 additions & 0 deletions wake/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ def run_test(
PytestWakePluginMultiprocessServer,
)

if shrink is not None:
raise click.BadParameter(
"Shrink can not execute with multiprocess mode."
)

if shrank is not None:
raise click.BadParameter(
"Shrank reproduce can not execute with multiprocess mode."
)

sys.exit(
pytest.main(
pytest_args,
Expand Down
15 changes: 12 additions & 3 deletions wake/testing/fuzzing/fuzz_shrink.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ def shrink_collecting_phase(
return exception_content, time_spent

def shrink_test(test_class: type[FuzzTest], flows_count: int):
import json
import inspect

error_flow_num = get_error_flow_num() # argument
actual_error_flow_num = error_flow_num
print(
Expand Down Expand Up @@ -824,9 +827,9 @@ def shrink_test(test_class: type[FuzzTest], flows_count: int):
# write crash log file.
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
# Assuming `call.execinfo` contains the crash information
shrank_file = crash_logs_dir / f"{timestamp}.json"

import inspect



current_file_path = os.path.abspath(inspect.getfile(test_class))

Expand All @@ -842,8 +845,14 @@ def shrink_test(test_class: type[FuzzTest], flows_count: int):
required_flows=required_flows,
)

import json
# Write to a JSON file
shrank_file = crash_logs_dir / f"{timestamp}.json"
# I would like if file already exists, then create new indexed file
if shrank_file.exists():
i = 0
while shrank_file.with_suffix(f"_{i}.json").exists():
i += 1
shrank_file = shrank_file.with_suffix(f"_{i}.json")
with open(shrank_file, "w") as f:
json.dump(store_data.to_dict(), f, indent=2)
print(f"Shrunken data file written to {shrank_file}")
Expand Down
11 changes: 7 additions & 4 deletions wake/testing/pytest_plugin_single.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import partial
import os
from typing import Iterable, List, Optional
from typing import Iterable, List, Optional, Tuple

from pytest import Session

Expand All @@ -23,14 +23,13 @@
export_merged_ide_coverage,
write_coverage,
)
import pickle

class PytestWakePluginSingle:
_config: WakeConfig
_cov_proc_count: Optional[int]
_random_seeds: List[bytes]
_debug: bool

_crash_log_meta_data: List[Tuple[str, str]]
def __init__(
self,
config: WakeConfig,
Expand All @@ -42,6 +41,7 @@ def __init__(
self._debug = debug
self._cov_proc_count = cov_proc_count
self._random_seeds = list(random_seeds)
self._crash_log_meta_data = []

def pytest_runtest_setup(self, item):
reset_exception_handled()
Expand Down Expand Up @@ -104,7 +104,7 @@ def pytest_exception_interact(self, node, call, report):
with crash_log_file.open('w') as f:
json.dump(crash_data, f, indent=2)

console.print(f"Crash log written to {crash_log_file}")
self._crash_log_meta_data.append((str(test_file_path), os.path.relpath(crash_log_file, self._config.project_root_path)))

def pytest_runtestloop(self, session: Session):
if (
Expand Down Expand Up @@ -155,3 +155,6 @@ def pytest_terminal_summary(self, terminalreporter, exitstatus, config):
terminalreporter.section("Wake")
terminalreporter.write_line("Random seed: " + self._random_seeds[0].hex())
terminalreporter.write_line("Executed flow number: " + str(get_error_flow_num()))

for node, crash_log in self._crash_log_meta_data:
terminalreporter.write_line( f"{node} Crash log stored at {crash_log}")

0 comments on commit 5963d93

Please sign in to comment.