From 5963d930c356dbac69e6b9a79b04064f9f06bd5a Mon Sep 17 00:00:00 2001 From: MeditationDuck Date: Tue, 17 Dec 2024 13:59:42 +0100 Subject: [PATCH] :pencil2: fix --- wake/cli/test.py | 10 ++++++++++ wake/testing/fuzzing/fuzz_shrink.py | 15 ++++++++++++--- wake/testing/pytest_plugin_single.py | 11 +++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/wake/cli/test.py b/wake/cli/test.py index 105f338e..ec1b1adb 100644 --- a/wake/cli/test.py +++ b/wake/cli/test.py @@ -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, diff --git a/wake/testing/fuzzing/fuzz_shrink.py b/wake/testing/fuzzing/fuzz_shrink.py index a0866c6e..cbbf748d 100644 --- a/wake/testing/fuzzing/fuzz_shrink.py +++ b/wake/testing/fuzzing/fuzz_shrink.py @@ -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( @@ -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)) @@ -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}") diff --git a/wake/testing/pytest_plugin_single.py b/wake/testing/pytest_plugin_single.py index bd813e89..27498b7a 100644 --- a/wake/testing/pytest_plugin_single.py +++ b/wake/testing/pytest_plugin_single.py @@ -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 @@ -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, @@ -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() @@ -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 ( @@ -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}")