Skip to content

Commit

Permalink
✨ rough feature implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
MeditationDuck committed Sep 26, 2024
1 parent c5f224c commit 160ae7a
Show file tree
Hide file tree
Showing 4 changed files with 375 additions and 71 deletions.
51 changes: 51 additions & 0 deletions wake/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ def shell_complete(
count=True,
help="Increase verbosity. Can be specified multiple times.",
)
@click.option(
"--shrink",
type=click.Path(exists=True, dir_okay=False, readable=True), # Ensure it's an existing file
help="Path to the shrink log file.",
is_flag=False,
flag_value=-1,
default=None,
)

@click.argument("paths_or_pytest_args", nargs=-1, type=FileAndPassParamType())
@click.pass_context
Expand All @@ -255,6 +263,7 @@ def run_test(
attach_first: bool,
dist: str,
verbosity: int,
shrink: Optional[str],
paths_or_pytest_args: Tuple[str, ...],
) -> None:
"""Execute Wake tests using pytest."""
Expand Down Expand Up @@ -361,6 +370,48 @@ def run_test(
)
else:
from wake.testing.pytest_plugin_single import PytestWakePluginSingle
from wake.development.globals import set_fuzz_mode,set_sequence_initial_internal_state, set_error_flow_num

def extract_executed_flow_number(crash_log_file_path):
if crash_log_file_path is not None:
with open(crash_log_file_path, 'r') as file:
for line in file:
if "executed flow number" in line:
# Extract the number after the colon
parts = line.split(":")
if len(parts) == 2:
try:
executed_flow_number = int(parts[1].strip())
return executed_flow_number
except ValueError:
pass # Handle the case where the value after ":" is not an integer
return None

def extract_internal_state(crash_log_file_path):
if crash_log_file_path is not None:
with open(crash_log_file_path, 'r') as file:
for line in file:
if "Internal state of beginning of sequence" in line:
# Extract the part after the colon
parts = line.split(":")
if len(parts) == 2:
hex_string = parts[1].strip()
try:
# Convert the hex string to bytes
internal_state_bytes = bytes.fromhex(hex_string)
return internal_state_bytes
except ValueError:
pass # Handle the case where the value after ":" is not a valid hex string
return None

if shrink is not None:
number = extract_executed_flow_number(shrink)
assert number is not None, "Unexpected file format"
set_fuzz_mode(1)
set_error_flow_num(number)
beginning_random_state_bytes = extract_internal_state(shrink)
assert beginning_random_state_bytes is not None, "Unexpected file format"
set_sequence_initial_internal_state(beginning_random_state_bytes)

sys.exit(
pytest.main(
Expand Down
23 changes: 21 additions & 2 deletions wake/development/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
_config: Optional[WakeConfig] = None
_verbosity: int = 0

_fuzz_mode: int = 0

_error_flow_num: int = 0



def attach_debugger(
e_type: Optional[Type[BaseException]],
Expand Down Expand Up @@ -106,6 +111,20 @@ def attach_debugger(
p.reset()
p.interaction(None, tb)

def get_fuzz_mode() -> int:
return _fuzz_mode

def set_fuzz_mode(fuzz_mode: int):
global _fuzz_mode
_fuzz_mode = fuzz_mode

def get_error_flow_num() -> int:
return _error_flow_num

def set_error_flow_num(error_flow_num: int):
global _error_flow_num
_error_flow_num = error_flow_num


def get_exception_handler() -> Optional[
Callable[
Expand All @@ -132,11 +151,11 @@ def set_exception_handler(
):
global _exception_handler
_exception_handler = handler

def set_sequence_initial_internal_state(intenral_state: bytes):
global _initial_internal_state
_initial_internal_state = intenral_state

def get_sequence_initial_internal_state() -> bytes:
return _initial_internal_state

Expand Down
Loading

0 comments on commit 160ae7a

Please sign in to comment.